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
This commit is contained in:
ligc 2013-03-14 07:41:51 +00:00
parent 0062a95fed
commit f07a2af37c
3 changed files with 182 additions and 11 deletions

View File

@ -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;

View File

@ -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

View File

@ -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 = ();