From f07a2af37c9249a5c3a61ab420cd7ad96804e9b6 Mon Sep 17 00:00:00 2001 From: ligc Date: Thu, 14 Mar 2013 07:41:51 +0000 Subject: [PATCH] lsdef enhancements to support nics, display and set nics info more easily git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.8@15507 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/DBobjUtils.pm | 84 +++++++++++++++++ xCAT-client/pods/man1/lsdef.1.pod | 15 +++- xCAT-server/lib/xcat/plugins/DBobjectdefs.pm | 94 ++++++++++++++++++-- 3 files changed, 182 insertions(+), 11 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index 656cceabe..2ad64d399 100644 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -2592,4 +2592,88 @@ sub judge_node return $flag; } + + +#------------------------------------------------------------------------------- + +=head3 expandnicsattr + Expand the nics related attributes into the readable format, + for example, the nicsips=eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 + expanded format: + nicsips.eth0=1.1.1.1|2.1.1.1 + nicsips.eth1=3.1.1.1|4.1.1.1 + + Arguments: + nicsattr value, like niccsips=eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 + nicnames: only return the value for specific nics, like "eth0,eth1" + Returns: + expanded format, like: + nicsips.eth0=1.1.1.1|2.1.1.1 + nicsips.eth1=3.1.1.1|4.1.1.1 + Error: + none + + Example: + my $nicsstr = xCAT::DBobjUtils->expandnicsattr($attrval); + + Comments: + none +=cut + +#------------------------------------------------------------------------------- +sub expandnicsattr() +{ + my $nicstr = shift; + if (($nicstr) && ($nicstr =~ /xCAT::/)) + { + $nicstr = shift; + } + my $nicnames = shift; + + my $ret; + + $nicstr =~ /^(.*?)=(.*?)$/; + + #Attribute: nicips, nichostnamesuffix, etc. + my $nicattr = $1; + + # Value: eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 + my $nicval=$2; + + # $nicarr[0]: eth0!1.1.1.1|2.1.1.1 + # $nicarr[1]: eth1!3.1.1.1|4.1.1.1 + my @nicarr = split(/,/, $nicval); + + foreach my $nicentry (@nicarr) + { + #nicentry: eth0!1.1.1.1|2.1.1.1 + # $nicv[0]: eth0 + # $nicv[1]: 1.1.1.1|2.1.1.1 + my @nicv = split(/!/, $nicentry); + + # only return nic* attr for these specific nics + if ($nicnames) + { + my @nics = split(/,/, $nicnames); + if ($nicv[0]) + { + # Do not need to return the nic attr for this nic + if (!grep(/^$nicv[0]$/, @nics)) + { + next; + } + } + } + + # ignore the line that does not have nicname or value + if ($nicv[0] && $nicv[1]) + { + $ret .= " $nicattr.$nicv[0]=$nicv[1]\n"; + } + } + + chomp($ret); + return $ret; + +} 1; diff --git a/xCAT-client/pods/man1/lsdef.1.pod b/xCAT-client/pods/man1/lsdef.1.pod index 0e14b0bbe..39093757a 100644 --- a/xCAT-client/pods/man1/lsdef.1.pod +++ b/xCAT-client/pods/man1/lsdef.1.pod @@ -4,11 +4,12 @@ B - Use this command to list xCAT data object definitions. =head1 SYNOPSIS -B [B<-h>|B<--help>] [B<-t> I] +B [B<-h>|B<--help>] [B<-t> I] [B<-i> I] B [B<-V>|B<--verbose>] [B<-l>|B<--long>] [B<-s>|B<--short>] [B<-a>|B<--all>] [B<-S>] [B<-t> I] [B<-o> I] [B<-z>|B<--stanza>] [B<-i> I] -[B<-c>|B<--compress>] [B<--osimage>][[B<-w> I==I] [B<-w> I=~I] ...] [I] +[B<-c>|B<--compress>] [B<--osimage>] [B<--nics>] [[B<-w> I==I] +[B<-w> I=~I] ...] [I] =head1 DESCRIPTION @@ -66,6 +67,10 @@ A set of comma delimited object names. Show all the osimage information for the node. +=item B<--nics> + +Show the nics configuration information for the node. + =item B<-t> I A set of comma delimited object types. Use the help option to get a list of valid objects. @@ -211,6 +216,12 @@ when defining an xCAT node. lsdef -t node -h -i profile,pprofile +=item 17. + +To display the nics configuration information for node cn1. + + lsdef cn1 --nics + =back =head1 FILES diff --git a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm index fa1d6fd1b..ce2e4660c 100644 --- a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm +++ b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm @@ -40,6 +40,8 @@ $Getopt::Long::ignorecase = 0; %::WhereHash; # hash of attr=val from "-w" option @::AttrList; # list of attrs from "-i" option +%::NicsAttrHash; # hash of nics attributes specified with "-i" option + # e.g. $::NicsAttrHash{'nicips'} = ("eth0","eth1"); # object type lists @::clobjtypes; # list of object types derived from the command line. @@ -266,6 +268,7 @@ sub processArgs 'nocache' => \$::opt_nc, 'S' => \$::opt_S, 'osimage' => \$::opt_osimg, + 'nics' => \$::opt_nics, ) ) { @@ -331,6 +334,19 @@ sub processArgs return 2; } + # -i and --nics cannot be used together + if ($::opt_nics && $::opt_i) { + my $rsp; + $rsp->{data}->[0] = "The flags \'-i'\ and \'--nics'\ cannot be used together."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + return 2; + } + + # --nics is the equivalent of -i nicips,nichostnamesuffixes... + if ($::opt_nics) { + $::opt_i="nicips,nichostnamesuffixes,nictypes,niccustomscripts,nicnetworks,nicaliases"; + } + # -i and -s cannot be used together if ($::opt_i && $::opt_s) { my $rsp; @@ -619,6 +635,11 @@ sub processArgs @dispattrs = split(/,/, $::opt_i); foreach my $dattr (@dispattrs) { + # lsdef -t node -h -i nicips.eth0 + if($dattr =~ /^(nic\w+)\.\w+$/) + { + $dattr = $1; + } $dispattrhash{$dattr} = 1; } } @@ -909,6 +930,16 @@ sub processArgs if ($::opt_i) { @::AttrList = split(',', $::opt_i); + # nicips. should be changed to nicips + my $i = 0; + for ($i=0; $i < (scalar @::AttrList) ; $i++ ) + { + if($::AttrList[$i] =~ /^(nic\w+)\.(\w+)$/) + { + $::AttrList[$i] = $1; + push @{$::NicsAttrHash{$::AttrList[$i]}}, $2; + } + } } return 0; @@ -3123,18 +3154,49 @@ sub defls } else { - - # since they asked for this attr - # show it even if not set - if (!$::opt_c) + # nics attributes, like nicips, nichostnamesuffix. + if ($showattr =~ /^nic/) { - push (@{$rsp_info->{data}}, " $showattr=$attrval"); - } + my $nicval = "$showattr=$attrval"; + my $nicnames; + if (defined($::NicsAttrHash{$showattr})) + { + $nicnames = join(',', @{$::NicsAttrHash{$showattr}}); + } + my $nicsstr; + if ($nicnames) + { + $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval, $nicnames); + } + else + { + $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval); + } + # Compress mode, format the output + if ($::opt_c) + { + $nicsstr =~ s/^\s+/$obj: /; + $nicsstr =~ s/\n\s+/\n$obj: /g; + } + if ($nicsstr) + { + push (@{$rsp_info->{data}}, "$nicsstr"); + } + } else { - push (@{$rsp_info->{data}}, "$obj: $showattr=$attrval"); + # since they asked for this attr + # show it even if not set + if (!$::opt_c) + { + push (@{$rsp_info->{data}}, " $showattr=$attrval"); + } + else + { + push (@{$rsp_info->{data}}, "$obj: $showattr=$attrval"); - } + } + } } } } @@ -3156,7 +3218,20 @@ sub defls # don't print unless set if ( (defined($attrval)) && ($attrval ne '') ) { - push (@{$rsp_info->{data}}, " $showattr=$attrval"); + # nics attributes, like nicips, nichostnamesuffix. + if ($showattr =~ /^nic/) + { + my $nicval = "$showattr=$attrval"; + my $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval); + if ($nicsstr) + { + push (@{$rsp_info->{data}}, "$nicsstr"); + } + } + else + { + push (@{$rsp_info->{data}}, " $showattr=$attrval"); + } } } } @@ -3801,6 +3876,7 @@ sub initialize_variables %::objfilehash = (); %::WhereHash = (); @::AttrList = (); + %::NicsAttrHash = (); @::clobjtypes = (); @::fileobjtypes = (); @::clobjnames = ();