From 239aa73e9341e04b00c6ab030c97c02af847512c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 5 Sep 2017 14:59:31 +0200 Subject: [PATCH] rbd: refactor cmdline helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit these were line by line identical except for the binary path Signed-off-by: Fabian Grünbichler --- PVE/Storage/RBDPlugin.pm | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm index 4c2967c..2a176a7 100644 --- a/PVE/Storage/RBDPlugin.pm +++ b/PVE/Storage/RBDPlugin.pm @@ -37,8 +37,8 @@ my $hostlist = sub { } @monhostlist); }; -my $rbd_cmd = sub { - my ($scfg, $storeid, $op, @options) = @_; +my $build_cmd = sub { + my ($binary, $scfg, $storeid, $op, @options) = @_; my $monhost = &$hostlist($scfg->{monhost}, ','); @@ -46,7 +46,7 @@ my $rbd_cmd = sub { my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd'; my $username = $scfg->{username} ? $scfg->{username} : 'admin'; - my $cmd = ['/usr/bin/rbd', '-p', $pool, '-m', $monhost]; + my $cmd = [$binary, '-p', $pool, '-m', $monhost]; if (-e $keyring) { push @$cmd, '-n', "client.$username"; @@ -69,36 +69,16 @@ my $rbd_cmd = sub { return $cmd; }; +my $rbd_cmd = sub { + my ($scfg, $storeid, $op, @options) = @_; + + return $build_cmd->('/usr/bin/rbd', $scfg, $storeid, $op, @options); +}; + my $rados_cmd = sub { my ($scfg, $storeid, $op, @options) = @_; - my $monhost = &$hostlist($scfg->{monhost}, ','); - - my $keyring = "/etc/pve/priv/ceph/${storeid}.keyring"; - my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd'; - my $username = $scfg->{username} ? $scfg->{username} : 'admin'; - - my $cmd = ['/usr/bin/rados', '-p', $pool, '-m', $monhost]; - - if (-e $keyring) { - push @$cmd, '-n', "client.$username"; - push @$cmd, '--keyring', $keyring; - push @$cmd, '--auth_supported', 'cephx'; - } else { - push @$cmd, '--auth_supported', 'none'; - } - - my $cephconfig = "/etc/pve/priv/ceph/${storeid}.conf"; - - if (-e $cephconfig) { - push @$cmd, '-c', $cephconfig; - } - - push @$cmd, $op; - - push @$cmd, @options if scalar(@options); - - return $cmd; + return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options); }; # needed for volumes created using ceph jewel (or higher)