[pve-devel] [PATCH cluster 11/16] move ssh_info code to own file

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Nov 6 13:36:16 CET 2019


Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    requires versioned breaks on:
    - libpve-storage-perl
    - qemu-server
    - libpve-guest-common-perl

 data/PVE/Makefile   |  2 +-
 data/PVE/Cluster.pm | 58 --------------------------------------
 data/PVE/SSHInfo.pm | 68 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 59 deletions(-)
 create mode 100644 data/PVE/SSHInfo.pm

diff --git a/data/PVE/Makefile b/data/PVE/Makefile
index d965932..8ee4900 100644
--- a/data/PVE/Makefile
+++ b/data/PVE/Makefile
@@ -11,7 +11,7 @@ PVE_VENDORARCH=${DESTDIR}/${PERL_VENDORARCH}/auto/PVE/IPCC
 PERL_DOC_INC_DIRS:=..
 
 SUBDIRS=Cluster CLI API2
-SOURCES=IPCC.pm Cluster.pm Corosync.pm RRD.pm DataCenterConfig.pm
+SOURCES=IPCC.pm Cluster.pm Corosync.pm RRD.pm DataCenterConfig.pm SSHInfo.pm
 
 all:
 
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 2f2daf6..2057162 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -791,64 +791,6 @@ sub complete_migration_target {
     return $res;
 }
 
-sub get_ssh_info {
-    my ($node, $network_cidr) = @_;
-
-    my $ip;
-    if (defined($network_cidr)) {
-	# Use mtunnel via to get the remote node's ip inside $network_cidr.
-	# This goes over the regular network (iow. uses get_ssh_info() with
-	# $network_cidr undefined.
-	# FIXME: Use the REST API client for this after creating an API entry
-	# for get_migration_ip.
-	my $default_remote = get_ssh_info($node, undef);
-	my $default_ssh = ssh_info_to_command($default_remote);
-	my $cmd =[@$default_ssh, 'pvecm', 'mtunnel',
-	    '-migration_network', $network_cidr,
-	    '-get_migration_ip'
-	];
-	PVE::Tools::run_command($cmd, outfunc => sub {
-	    my ($line) = @_;
-	    chomp $line;
-	    die "internal error: unexpected output from mtunnel\n"
-		if defined($ip);
-	    if ($line =~ /^ip: '(.*)'$/) {
-		$ip = $1;
-	    } else {
-		die "internal error: bad output from mtunnel\n"
-		    if defined($ip);
-	    }
-	});
-	die "failed to get ip for node '$node' in network '$network_cidr'\n"
-	    if !defined($ip);
-    } else {
-	$ip = remote_node_ip($node);
-    }
- 
-    return {
-	ip => $ip,
-	name => $node,
-	network => $network_cidr,
-    };
-}
-
-sub ssh_info_to_command_base {
-    my ($info, @extra_options) = @_;
-    return [
-	'/usr/bin/ssh',
-	'-e', 'none',
-	'-o', 'BatchMode=yes',
-	'-o', 'HostKeyAlias='.$info->{name},
-	@extra_options
-    ];
-}
-
-sub ssh_info_to_command {
-    my ($info, @extra_options) = @_;
-    my $cmd = ssh_info_to_command_base($info, @extra_options);
-    push @$cmd, "root\@$info->{ip}";
-    return $cmd;
-}
 
 # NOTE: filesystem must be offline here, no DB changes allowed
 sub cfs_backup_database {
diff --git a/data/PVE/SSHInfo.pm b/data/PVE/SSHInfo.pm
new file mode 100644
index 0000000..fadd36c
--- /dev/null
+++ b/data/PVE/SSHInfo.pm
@@ -0,0 +1,68 @@
+package PVE::SSHInfo;
+
+use strict;
+use warnings;
+
+use PVE::Cluster;
+use PVE::Tools;
+
+sub get_ssh_info {
+    my ($node, $network_cidr) = @_;
+
+    my $ip;
+    if (defined($network_cidr)) {
+	# Use mtunnel via to get the remote node's ip inside $network_cidr.
+	# This goes over the regular network (iow. uses get_ssh_info() with
+	# $network_cidr undefined.
+	# FIXME: Use the REST API client for this after creating an API entry
+	# for get_migration_ip.
+	my $default_remote = get_ssh_info($node, undef);
+	my $default_ssh = ssh_info_to_command($default_remote);
+	my $cmd =[@$default_ssh, 'pvecm', 'mtunnel',
+	    '-migration_network', $network_cidr,
+	    '-get_migration_ip'
+	];
+	PVE::Tools::run_command($cmd, outfunc => sub {
+	    my ($line) = @_;
+	    chomp $line;
+	    die "internal error: unexpected output from mtunnel\n"
+		if defined($ip);
+	    if ($line =~ /^ip: '(.*)'$/) {
+		$ip = $1;
+	    } else {
+		die "internal error: bad output from mtunnel\n"
+		    if defined($ip);
+	    }
+	});
+	die "failed to get ip for node '$node' in network '$network_cidr'\n"
+	    if !defined($ip);
+    } else {
+	$ip = PVE::Cluster::remote_node_ip($node);
+    }
+ 
+    return {
+	ip => $ip,
+	name => $node,
+	network => $network_cidr,
+    };
+}
+
+sub ssh_info_to_command_base {
+    my ($info, @extra_options) = @_;
+    return [
+	'/usr/bin/ssh',
+	'-e', 'none',
+	'-o', 'BatchMode=yes',
+	'-o', 'HostKeyAlias='.$info->{name},
+	@extra_options
+    ];
+}
+
+sub ssh_info_to_command {
+    my ($info, @extra_options) = @_;
+    my $cmd = ssh_info_to_command_base($info, @extra_options);
+    push @$cmd, "root\@$info->{ip}";
+    return $cmd;
+}
+
+1;
-- 
2.20.1





More information about the pve-devel mailing list