[pmg-devel] [PATCH pmg-api 1/6] cluster: refactor rsync_command

Stoiko Ivanov s.ivanov at proxmox.com
Mon Mar 15 23:01:30 CET 2021


pull out the ssh part for later reusal

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Cluster.pm | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/PMG/Cluster.pm b/src/PMG/Cluster.pm
index 6bb940a..daaa439 100644
--- a/src/PMG/Cluster.pm
+++ b/src/PMG/Cluster.pm
@@ -280,13 +280,21 @@ my $cond_commit_synced_file = sub {
     return 1;
 };
 
+my $ssh_command = sub {
+    my ($host_key_alias, @args) = @_;
+
+    my $cmd = ['ssh', '-l', 'root', '-o', 'BatchMode=yes'];
+    push @$cmd, '-o', "HostKeyAlias=${host_key_alias}" if $host_key_alias;
+    push @$cmd, @args if @args;
+    return $cmd;
+};
+
 my $rsync_command = sub {
     my ($host_key_alias, @args) = @_;
 
-    my $ssh_cmd = '--rsh=ssh -l root -o BatchMode=yes';
-    $ssh_cmd .=  " -o HostKeyAlias=${host_key_alias}" if $host_key_alias;
+    my $ssh_cmd = join(' ', @{$ssh_command->($host_key_alias)});
 
-    my $cmd = ['rsync', $ssh_cmd,  '-q', @args];
+    my $cmd = ['rsync', "--rsh=$ssh_cmd",  '-q', @args];
 
     return $cmd;
 };
-- 
2.20.1





More information about the pmg-devel mailing list