From 0b23e927ac9a1229f75469c7cd765272557bb4f9 Mon Sep 17 00:00:00 2001 From: sakolish Date: Mon, 2 Jun 2008 13:02:38 +0000 Subject: [PATCH] Fix problem not writing "first" mac in writemac() with -w specified git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1542 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/PPCmac.pm | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/PPCmac.pm b/perl-xCAT-2.0/xCAT/PPCmac.pm index 5b256773d..393fd77dc 100644 --- a/perl-xCAT-2.0/xCAT/PPCmac.pm +++ b/perl-xCAT-2.0/xCAT/PPCmac.pm @@ -318,7 +318,7 @@ sub getmacs { $d, $opt ); } - my $Rc = shift(@$result); + $Rc = shift(@$result); ################################## # Form string from array results @@ -354,13 +354,13 @@ sub getmacs { # ent U9117.MMA.10F6F3D-V5-C3-T1 1e0e122a930d /vdevice/l-lan@30000003 # ##################################### - my $values; + my $data; foreach ( @$result ) { if ( /^#\s?Type/ ) { - $values.= "\n$_\n"; + $data.= "\n$_\n"; } elsif ( /^ent$delim/ ) { - $values.= "$_\n"; + $data.= "$_\n"; } } ##################################### @@ -369,7 +369,7 @@ sub getmacs { if ( exists( $opt->{w} )) { writemac( $name, $delim, $result ); } - return( [[$name,$values,$Rc]] ); + return( [[$name,$data,$Rc]] ); } @@ -381,37 +381,40 @@ sub writemac { my $name = shift; my $delim = shift; my $data = shift; - my $values; + my $value; ##################################### # Find first adapter ##################################### foreach ( @$data ) { if ( /^ent$delim/ ) { - $values = $_; + $value = $_; + last; } } ##################################### + # MAC not found in output + ##################################### + if ( !defined( $value )) { + return; + } + ##################################### # Get adapter mac ##################################### - my ($k,$u); - my @fields = split $delim, $values; + my @fields = split $delim, $value; my $mac = $fields[2]; ##################################### - # Write adapter mac to database + # Write adapter mac to database ##################################### - my $tab = xCAT::Table->new( "mac", -create=>1, -autocommit=>1 ); - if ( !$tab ) { + my $mactab = xCAT::Table->new( "mac", -create=>1, -autocommit=>1 ); + if ( !$mactab ) { return( [[$name,"Error opening 'mac'",RC_ERROR]] ); } - $k->{node} = $name; - $u->{mac} = $mac; - my $d = $tab->setAttribs( $k,$u ); - return undef; + $mactab->setNodeAttribs( $name,{mac=>$mac} ); + $mactab->close(); } - 1;