From 5229862ac3f4b7f6388527110512605e492720bf Mon Sep 17 00:00:00 2001 From: nott Date: Wed, 18 Aug 2010 15:19:01 +0000 Subject: [PATCH] add get_nim_attrs subroutine git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7129 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/InstUtils.pm | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/perl-xCAT/xCAT/InstUtils.pm b/perl-xCAT/xCAT/InstUtils.pm index ed2148727..790913161 100644 --- a/perl-xCAT/xCAT/InstUtils.pm +++ b/perl-xCAT/xCAT/InstUtils.pm @@ -180,6 +180,7 @@ sub myxCATname #----------------------------------------------------------------------------- sub is_me + { my ($class, $name) = @_; @@ -219,6 +220,86 @@ sub is_me #---------------------------------------------------------------------------- +=head3 get_nim_attrs + + Use the lsnim command to get the NIM attributes and values of + a resource. + + Arguments: + Returns: + hash ref - OK + undef - error + Globals: + + Error: + + Example: + + $attrvals = xCAT::InstUtils-> + get_nim_attrs($res, $callback, $nimprime, $subreq); + + + Comments: +=cut + +#----------------------------------------------------------------------------- +sub get_nim_attrs +{ + my $class = shift; + my $resname = shift; + my $callback = shift; + my $target = shift; + my $sub_req = shift; + + my %attrvals = undef; + + if (!$target) + { + $target = xCAT::InstUtils->getnimprime(); + } + chomp $target; + + my $cmd = "/usr/sbin/lsnim -l $resname 2>/dev/null"; + + my @nout = xCAT::InstUtils->xcmd($callback, $sub_req, "xdsh", $target, $cmd, 1); + if ($::RUNCMD_RC != 0) + { + my $rsp; + push @{$rsp->{data}}, "Could not run lsnim command: \'$cmd\'.\n"; + xCAT::MsgUtils->message("E", $rsp, $callback); + return undef; + } + + foreach my $line (@nout) { + + chomp $line; + my $junk; + my $attrval; + if ($line =~ /.*$target:(.*)/) { + ($junk, $attrval) = split(/:/, $line); + } else { + $attrval = $line; + } + + if ($attrval =~ /=/) { + + my ($attr, $val) = $attrval =~ /^\s*(\S+?)\s*=\s*(\S*.*)$/; + + if ($attr && $val) { + $attrvals{$attr} = $val; + } + } + } + + if (%attrvals) { + return \%attrvals; + } else { + return undef; + } +} + +#---------------------------------------------------------------------------- + =head3 get_nim_attr_val Use the lsnim command to find the value of a resource attribute.