consolidate the three duplicate subroutines thishostisnot into xCAT::Utils

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4603 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
ligc 2009-11-18 08:54:34 +00:00
parent 6d10253f56
commit 4089683849

View File

@ -496,7 +496,7 @@ sub dispatch_request {
# }
# undef $SIG{CHLD};
# $dispatch_parentfd = $parfd;
if ($_->{'_xcatdest'} and thishostisnot($_->{'_xcatdest'})) {
if ($_->{'_xcatdest'} and xCAT::Utils->thishostisnot($_->{'_xcatdest'})) {
#----- added to Client.pm -----#
$dispatch_cb->({warning=>['XCATBYPASS is set, skipping hierarchy call to '.$_->{'_xcatdest'}.'']});
@ -522,58 +522,6 @@ sub dispatch_request {
}
###################################
# thishostisnot
# does the requested IP belong to this local host?
#
# NOTE: This is copied from xcatd (last merge 5/21/08).
# Will eventually move to using common source....
###################################
sub thishostisnot {
my $comparison = shift;
# use "ip addr" for linux, since ifconfig
# doesn't list "ip addr add" aliases for linux
#
my $cmd = ($^O !~ /^aix/i) ? "/sbin/ip addr" : "ifconfig -a";
my @ips = split /\n/,`$cmd`;
####
# TODO: AIX will hang on the inet_aton call if it gets passed an IPv6
# address, since we have not added INET6 support to AIX yet.
# The ifconfig -a output may contain an IPv6 address for localhost.
# This code should only get called if using hierarchy
####
my $comp=IO::Socket::inet_aton($comparison);
foreach (@ips) {
if (xCAT::Utils->isAIX()) {
# don't want "inet6" entry - causes error in inet_aton
if (/^\s*inet\s+/) {
my @ents = split(/\s+/);
my $ip=$ents[2];
$ip =~ s/\/.*//;
if (IO::Socket::inet_aton($ip) eq $comp) {
return 0;
}
}
} else {
if (/^\s*inet/) {
my @ents = split(/\s+/);
my $ip=$ents[2];
$ip =~ s/\/.*//;
if (IO::Socket::inet_aton($ip) eq $comp) {
return 0;
}
}
}
}
return 1;
}
###################################
# do_request
# called from a plugin to execute another xCAT plugin command internally