[pve-devel] [PATCH 1/2] PVE::Tools: add build_ssh_opt subroutine

Stefan Priebe s.priebe at profihost.ag
Tue Oct 30 15:44:28 CET 2012


From: Stefan Priebe <git at profihost.ag>


Signed-off-by: root <root at neuerserver.de-nserver.de.de-nserver.de>
---
 data/PVE/Tools.pm |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm
index 27b4361..b42a5f2 100644
--- a/data/PVE/Tools.pm
+++ b/data/PVE/Tools.pm
@@ -30,6 +30,7 @@ template_replace
 safe_print
 trim
 extract_param
+build_ssh_opt
 );
 
 my $pvelogdir = "/var/log/pve";
@@ -888,4 +889,31 @@ sub dir_glob_foreach {
     } 
 }
 
+sub build_ssh_opt {
+    my ( $opts ) = @_;
+    my @ssh_opts = ();
+
+    # we only accept options we know and we have defaults for
+    # you can also delete options by passing the key with value
+    # undef
+    my $defaults = {
+        cipher => { opt => '-c', default => 'blowfish' },
+        mode   => { opt => '-o', default => 'BatchMode=yes' },
+    };
+
+    foreach my $option ( sort keys %$defaults ) {
+        if ( $opts && ref($opts) eq "HASH" && exists $opts->{$option} ) {
+
+            # option was passed as undef so skip this one
+            next if ( !defined $opts->{$option} );
+            push( @ssh_opts, ( $defaults->{$option}{opt}, $opts->{$option} ) );
+        }
+        else {
+            push( @ssh_opts, ( $defaults->{$option}{opt}, $defaults->{$option}{default} ) );
+        }
+    }
+
+    return @ssh_opts;
+}
+
 1;
-- 
1.7.2.5




More information about the pve-devel mailing list