From 536ad3a75f1fd925d67fdfa5eb07de1687c52704 Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 5 Aug 2009 11:53:05 +0000 Subject: [PATCH] add getSNformattedhash to format the Servicenode/node list into unique service node hash keys for pools git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3945 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Utils.pm | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index cefba67e9..42d620d48 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -3150,6 +3150,89 @@ sub get_ServiceNode #----------------------------------------------------------------------------- +=head3 getSNformattedhash + + Will call get_ServiceNode to get the Service node ( name or ipaddress) + as known by the Management + Server or Node for the input nodename or ipadress of the node + It will then format the output into a single servicenode key with values + the list of nodes service by that service node. This routine will + break up pools of service nodes into individual node in the hash unlike + get_ServiceNode which leaves the pool as the key. + + input: Same as get_ServiceNode to call get_ServiceNode + list of nodenames and/or node ipaddresses (array ref) + service name + "MN" or "Node" determines if you want the Service node as known + by the Management Node or by the node. + + recognized service names: xcat,tftpserver, + nfsserver,conserver,monserver + + service "xcat" is used by command like xdsh that need to know the + service node that will process the command but are not tied to a + specific service like tftp + + + output: A hash ref of arrays, the key is a single service node + pointing to + a list of nodes that are serviced by that service node + 'rra000-m'=>['blade01', 'testnode'] + 'sn1'=>['blade01', 'testnode'] + 'sn2'=>['blade01'] + 'sn3'=>['testnode'] + + Globals: + $::ERROR_RC + Error: + $::ERROR_RC=0 no error $::ERROR_RC=1 error + + example: $sn =xCAT::Utils->getSNformattedhash(\@nodes,$service,"MN"); + $sn =xCAT::Utils->getSNformattedhash(\@nodes,$service,"Node"); + +=cut + +#----------------------------------------------------------------------------- +sub getSNformattedhash +{ + my ($class, $node, $service, $request) = @_; + my @node_list = @$node; + my $cmd; + my %newsnhash; + my $sn = xCAT::Utils->get_ServiceNode(\@node_list, $service, $request); + + # get the keys which are the service nodes and break apart any pool lists + # format into individual service node keys pointing to node lists + + if ($sn) + { + foreach my $snkey (keys %$sn) + { + # split the key if pool of service nodes + #push my @nodes, $sn->{$snkey}->[0]; + push my @tmpnodes, $sn->{$snkey}; + my @nodes; + for my $i (0 .. $#tmpnodes) { + for my $j ( 0 .. $#{$tmpnodes[$i]}) { + my $check=$tmpnodes[$i][$j]; + push @nodes,$check; + } + } + my @servicenodes = split /,/, $snkey; + # now build new hash of individual service nodes + foreach my $newsnkey (@servicenodes) { + push @{$newsnhash{$newsnkey}}, @nodes; + } + + } + } + + return \%newsnhash; + +} + +#----------------------------------------------------------------------------- + =head3 toIP IPv4 function to convert hostname to IP address