From cc76a05db45b11f38a2a6c8fb61e8cc628f4d332 Mon Sep 17 00:00:00 2001 From: nott Date: Thu, 23 Aug 2012 16:56:08 +0000 Subject: [PATCH] add getNodeDomains git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13589 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index a7cbc7865..ba85bd59a 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -39,6 +39,73 @@ This program module file, is a set of network utilities used by xCAT commands. #------------------------------------------------------------- +#------------------------------------------------------------------------------- + +=head3 getNodeDomains + + Gets the network domain for a list of nodes + + The domain value comes from the network definition + associated with the node ip address. + + If the network domain is not set then the default is to + use the site.domain value + + Arguments: + list of nodes + Returns: + error - undef + success - hash ref of domains for each node + Globals: + $::VERBOSE + Error: + Example: + my $nodedomains = xCAT::NetworkUtils->getNodeDomains(\@nodes, $callback); + Comments: + none +=cut + +#------------------------------------------------------------------------------- +sub getNodeDomains() +{ + my $class = shift; + my $nodes = shift; + my $callback = shift; + + my @nodelist = @$nodes; + my %nodedomains; + + # Get the network info for each node + my %nethash = xCAT::DBobjUtils->getNetwkInfo(\@nodelist, $callback); + if (!(%nethash) && $::VERBOSE) + { + my $rsp; + push @{$rsp->{data}}, "Could not get xCAT network definitions for one or more nodes.\n"; + xCAT::MsgUtils->message("W", $rsp, $callback); + } + + # get the site domain value + my @domains = xCAT::TableUtils->get_site_attribute("domain"); + my $sitedomain = $domains[0]; + if (!$sitedomain && $::VERBOSE) + { + my $rsp; + push @{$rsp->{data}}, "Cannot get a domain value from the cluster site definition.\n"; + xCAT::MsgUtils->message("W", $rsp, $callback); + } + + # for each node - set hash value to network domain or default + # to site domain + foreach my $node (@nodelist) { + if ($nethash{$node}{domain}) { + $nodedomains{$node} = $nethash{$node}{domain}; + } else { + $nodedomains{$node} = $sitedomain; + } + } + + return \%nodedomains; +} #-------------------------------------------------------------------------------