From 0b2ae003e08e2c00e0e0a612db460c5e02c96027 Mon Sep 17 00:00:00 2001 From: nott Date: Tue, 1 Dec 2009 18:11:50 +0000 Subject: [PATCH] Add get_server_nodes routine. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4701 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/InstUtils.pm | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/perl-xCAT/xCAT/InstUtils.pm b/perl-xCAT/xCAT/InstUtils.pm index bea174219..fdbfcd88f 100644 --- a/perl-xCAT/xCAT/InstUtils.pm +++ b/perl-xCAT/xCAT/InstUtils.pm @@ -586,4 +586,71 @@ sub getOSnodes return ($rc, \@aixnodes, \@linuxnodes); } +#------------------------------------------------------------------------------- + +=head3 get_server_nodes + + Determines the server node names as known by a lists of nodes. + + Arguments: + A list of node names. + + Returns: + A hash ref of arrays, the key is the service node pointing to + an array of nodes that are serviced by that service node + + Example + my %servernodes = &get_server_nodes($callback, \@$AIXnodes); + + Comments: + - Code runs on MN or SNs + +=cut + +#------------------------------------------------------------------------------- +sub get_server_nodes +{ + my $class = shift; + my $callback = shift; + my $nodes = shift; + + my @nodelist; + if ($nodes) + { + @nodelist = @$nodes; + } + + # + # get the server name for each node - as known by node + # + my $noderestab = xCAT::Table->new('noderes'); + my $xcatmasters = $noderestab->getNodesAttribs(\@nodelist, ['node', 'xcatmaster']); + $noderestab->close; + + my %servernodes; + foreach my $node (@nodelist) + { + my $serv; + if ($xcatmasters->{$node}->[0]->{xcatmaster}) + { + # get ip of node xcatmaster attribute + my $xcatmaster = $xcatmasters->{$node}->[0]->{xcatmaster}; + $serv = inet_ntoa(inet_aton($xcatmaster)); + } + else + { + # get ip facing node + $serv = xCAT::Utils->getFacingIP($node); + } + chomp $serv; + + if (xCAT::Utils->validate_ip($serv)) { + push (@{$servernodes{$serv}}, $node); + } + } + + return \%servernodes; +} + + 1;