marsadm: add --ip=, fix IP detection

This commit is contained in:
Thomas Schoebel-Theuer 2014-02-05 10:02:43 +01:00
parent c6a3753c1d
commit 4c36e803f3

View File

@ -137,10 +137,10 @@ my $host = `uname -n` or ldie "cannot determine my network node name\n";
chomp $host;
my $force = 0;
my $timeout = -1;
my $ip = _get_ip() or ldie "cannot determine my IP address\n";
my $ip = "";
my $kernel_version = 0;
unless ($ARGV[0] =~ m/cluster|cat/) {
unless (defined($ARGV[0]) && $ARGV[0] =~ m/cluster|cat/) {
$kernel_version = get_link("$mars/tree-$host", 1);
if ($kernel_version && $user_version != $kernel_version) {
lwarn "kernel_version=$kernel_version user_version=$user_version\n";
@ -820,9 +820,21 @@ sub _writable {
}
sub _get_ip {
chomp (my @info = `/sbin/ip addr show dev eth0`);
foreach (@info) {
m#\sinet\s(\d+\.\d+\.\d+\.\d+)# && return $1;
my $ip_path = "$mars/ips/ip-$host";
if (my $from_link = get_link($ip_path, 2)) {
lprint_stderr "Using IP '$from_link' from '$ip_path'\n";
return $from_link;
}
chomp (my @info = `/sbin/ip addr show`);
my $interface = "";
foreach my $line (@info) {
$interface = $1 if $line =~ m#^[0-9]+:\s([a-zA-Z_0-9]+):#;
next if $interface eq "lo";
if ($line =~ m#\sinet\s(\d+\.\d+\.\d+\.\d+)#) {
my $from_if = $1;
lprint_stderr "Using IP '$from_if' from interface '$interface'\n";
return $from_if;
}
}
return undef;
}
@ -1929,6 +1941,10 @@ foreach my $arg (@ARGV) {
$host = $arg;
}
next;
} elsif ($arg =~ s/--ip\s*=\s*([0-9.:\[\]]+)/$1/) {
$ip = $arg;
lprint_stderr "Using IP '$ip' from command line.\n";
next;
}
if ($arg =~ s/^force-//) {
$force++;
@ -1938,6 +1954,10 @@ foreach my $arg (@ARGV) {
my $cmd = shift @args || helplist "command argument is missing\n";
if (!$ip) {
$ip = _get_ip() or ldie "cannot determine my IP address\n";
}
$notify = "(cmd: $cmd)" unless $cmd eq "version";
if ($cmd =~ m/^help$/ || $cmd =~ m/^h$/) {