]> git.proxmox.com Git - pve-cluster.git/commitdiff
add get_local_migration_ip method
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 28 Oct 2016 09:53:25 +0000 (11:53 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Oct 2016 10:10:01 +0000 (12:10 +0200)
used to get the local IP from the datacenter migration->network
CIDR, if any.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
data/PVE/Cluster.pm

index fe741cfc037b22f752fc7d5c317e06aadcecb622..d9eced78a87a43d8344a3cf7ebc4ff01bd4380f6 100644 (file)
@@ -16,6 +16,7 @@ use PVE::INotify;
 use PVE::IPCC;
 use PVE::SafeSyslog;
 use PVE::JSONSchema;
+use PVE::Network;
 use JSON;
 use RRDs;
 use Encode;
@@ -1048,6 +1049,32 @@ sub remote_node_ip {
     return wantarray ? ($ip, $family) : $ip;
 }
 
+sub get_local_migration_ip {
+    my ($migration_network, $noerr) = @_;
+
+    my $cidr = $migration_network;
+
+    if (!defined($cidr)) {
+       my $dc_conf = cfs_read_file('datacenter.cfg');
+       $cidr = $dc_conf->{migration}->{network}
+         if defined($dc_conf->{migration}->{network});
+    }
+
+    if (defined($cidr)) {
+       my $ips = PVE::Network::get_local_ip_from_cidr($cidr);
+
+       die "no IP address configured on local node for network '$cidr'\n" 
+           if !$noerr && (scalar(@$ips) == 0);
+
+       die "multiple IP address configured for network '$cidr'\n" 
+           if !$noerr && (scalar(@$ips) > 1);
+
+       return @$ips[0];
+    }
+
+    return undef;
+};
+
 # ssh related utility functions
 
 sub ssh_merge_keys {