lsdef enhancements to show nics attributes
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@15594 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -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; | ||||
|   | ||||
| @@ -1263,22 +1263,21 @@ nics => { | ||||
|             nicips => 'Comma-separated list of IP addresses per NIC. To specify one ip address per NIC: | ||||
|                     <nic1>!<ip1>,<nic2>!<ip2>,..., for example, eth0!10.0.0.100,ib0!11.0.0.100 | ||||
|                 To specify multiple ip addresses per NIC: | ||||
|                     <nic1>!<ip1>|<ip2>,<nic2>!<ip1>|<ip2>,..., for example, eth0!10.0.0.100|fd55::214:5eff:fe15:849b,ib0!11.0.0.100|2001::214:5eff:fe15:849a | ||||
|                     <nic1>!<ip1>|<ip2>,<nic2>!<ip1>|<ip2>,..., 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.<nicname> 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: | ||||
|                             <nic1>!<ext1>,<nic2>!<ext2>,..., for example, eth0!-eth0,ib0!-ib0 | ||||
|                         If multiple ip addresses are associcated with each NIC: | ||||
|                             <nic1>!<ext1>|<ext2>,<nic2>!<ext1>|<ext2>,..., for example,  eth0!-eth0|-eth0-ipv6,ib0!-ib0|-ib0-ipv6.', | ||||
|             nictypes => 'Comma-separated list of NIC types per NIC. <nic1>!<type1>,<nic2>!<type2>, e.g. eth0!Ethernet,ib0!Infiniband',  | ||||
|             niccustomscripts => 'Comma-separated list of custom scripts per NIC.  <nic1>!<script1>,<nic2>!<script2>, e.g. eth0!configeth eth0, ib0!configib ib0 | ||||
|                             <nic1>!<ext1>|<ext2>,<nic2>!<ext1>|<ext2>,..., for example,  eth0!-eth0|-eth0-ipv6,ib0!-ib0|-ib0-ipv6. The xCAT object definition commands support to use nichostnamesuffixes.<nicname> as the sub attributes.', | ||||
|             nictypes => 'Comma-separated list of NIC types per NIC. <nic1>!<type1>,<nic2>!<type2>, e.g. eth0!Ethernet,ib0!Infiniband. The xCAT object definition commands support to use nictypes.<nicname> as the sub attributes.',  | ||||
|             niccustomscripts => 'Comma-separated list of custom scripts per NIC.  <nic1>!<script1>,<nic2>!<script2>, e.g. eth0!configeth eth0, ib0!configib ib0. The xCAT object definition commands support to use niccustomscripts.<nicname> as the sub attribute | ||||
| .', | ||||
|             nicnetworks => 'Comma-separated list of networks connected to each NIC. | ||||
|                 If only one ip address is associated with each NIC: | ||||
|                     <nic1>!<network1>,<nic2>!<network2>, 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: | ||||
|                     <nic1>!<network1>|<network2>,<nic2>!<network1>|<network2>, 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 | ||||
| ', | ||||
|                     <nic1>!<network1>|<network2>,<nic2>!<network1>|<network2>, 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.<nicname> as the sub attributes.', | ||||
|             nicaliases => 'NOT YET IMPLEMENTED.  | ||||
| 			 | ||||
|             Comma-separated list of aliases for each NIC. | ||||
|   | ||||
| @@ -4,11 +4,12 @@ B<lsdef> - Use this command to list xCAT data object definitions. | ||||
|  | ||||
| =head1 SYNOPSIS | ||||
|  | ||||
| B<lsdef> [B<-h>|B<--help>] [B<-t> I<object-types>] | ||||
| B<lsdef> [B<-h>|B<--help>] [B<-t> I<object-types>] [B<-i> I<attr-list>] | ||||
|  | ||||
| B<lsdef> [B<-V>|B<--verbose>] [B<-l>|B<--long>] [B<-s>|B<--short>] [B<-a>|B<--all>] [B<-S>]  | ||||
| [B<-t> I<object-types>] [B<-o> I<object-names>] [B<-z>|B<--stanza>] [B<-i> I<attr-list>] | ||||
| [B<-c>|B<--compress>] [B<--osimage>][[B<-w> I<attr>==I<val>] [B<-w> I<attr>=~I<val>] ...] [I<noderange>] | ||||
| [B<-c>|B<--compress>] [B<--osimage>] [B<--nics>] [[B<-w> I<attr>==I<val>] | ||||
| [B<-w> I<attr>=~I<val>] ...] [I<noderange>] | ||||
|  | ||||
|  | ||||
| =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<object-types> | ||||
|  | ||||
| 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 | ||||
|   | ||||
| @@ -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.<nic> 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 = (); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user