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/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index af555a33c..f4f7222c8 100644 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -1263,22 +1263,21 @@ nics => { nicips => 'Comma-separated list of IP addresses per NIC. To specify one ip address per NIC: !,!,..., for example, eth0!10.0.0.100,ib0!11.0.0.100 To specify multiple ip addresses per NIC: - !|,!|,..., for example, eth0!10.0.0.100|fd55::214:5eff:fe15:849b,ib0!11.0.0.100|2001::214:5eff:fe15:849a + !|,!|,..., for example, eth0!10.0.0.100|fd55::214:5eff:fe15:849b,ib0!11.0.0.100|2001::214:5eff:fe15:849a. The xCAT object definition commands support to use nicips. as the sub attributes. Note: The primary IP address must also be stored in the hosts.ip attribute. The nichostnamesuffixes should specify one hostname suffix for each ip address.', nichostnamesuffixes => 'Comma-separated list of hostname suffixes per NIC. If only one ip address is associated with each NIC: !,!,..., for example, eth0!-eth0,ib0!-ib0 If multiple ip addresses are associcated with each NIC: - !|,!|,..., for example, eth0!-eth0|-eth0-ipv6,ib0!-ib0|-ib0-ipv6.', - nictypes => 'Comma-separated list of NIC types per NIC. !,!, e.g. eth0!Ethernet,ib0!Infiniband', - niccustomscripts => 'Comma-separated list of custom scripts per NIC. !,!, e.g. eth0!configeth eth0, ib0!configib ib0 + !|,!|,..., for example, eth0!-eth0|-eth0-ipv6,ib0!-ib0|-ib0-ipv6. The xCAT object definition commands support to use nichostnamesuffixes. as the sub attributes.', + nictypes => 'Comma-separated list of NIC types per NIC. !,!, e.g. eth0!Ethernet,ib0!Infiniband. The xCAT object definition commands support to use nictypes. as the sub attributes.', + niccustomscripts => 'Comma-separated list of custom scripts per NIC. !,!, e.g. eth0!configeth eth0, ib0!configib ib0. The xCAT object definition commands support to use niccustomscripts. as the sub attribute .', nicnetworks => 'Comma-separated list of networks connected to each NIC. If only one ip address is associated with each NIC: !,!, for example, eth0!10_0_0_0-255_255_0_0, ib0!11_0_0_0-255_255_0_0 If multiple ip addresses are associated with each NIC: - !|,!|, for example, eth0!10_0_0_0-255_255_0_0|fd55:faaf:e1ab:336::/64,ib0!11_0_0_0-255_255_0_0|2001:db8:1:0::/64 -', + !|,!|, for example, eth0!10_0_0_0-255_255_0_0|fd55:faaf:e1ab:336::/64,ib0!11_0_0_0-255_255_0_0|2001:db8:1:0::/64. The xCAT object definition commands support to use nicnetworks. as the sub attributes.', nicaliases => 'NOT YET IMPLEMENTED. Comma-separated list of aliases for each NIC. 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 = ();