update work on mkvlan

This commit is contained in:
Arif Ali 2014-05-04 18:26:29 +01:00
parent 397e964364
commit cb2d15cf29
2 changed files with 32 additions and 6 deletions

View File

@ -71,4 +71,4 @@ To create a tagged vlan on an interface, enter:
=head1 SEE ALSO
L<lsvlan(1)|lsvlan.1>
L<noderange(3)|noderange.3>, L<lsvlan(1)|lsvlan.1>

View File

@ -14,8 +14,7 @@ use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::SvrUtils;
use xCAT::Usage;
use Scalar::Util qw(looks_like_number);
use xCAT::NodeRange;
sub handled_commands {
return {
@ -91,10 +90,10 @@ sub mkvlan
# Go through the arguments, and get the relevant information
@ARGV = @{$req->{arg}};
#Detect if the first variable is a number or not, as it may be the vlanid
if ($ARGV[0] !~ /\D/) {$vlanid=$ARGV[0];}
GetOptions(
't=s' => \$subnet,
'm=s' => \$mask,
@ -105,8 +104,12 @@ sub mkvlan
);
# Show usage info if help is defined
if ($help) { $mkvlan_usage->(0); return; }
if ($help) { $mkvlan_usage->(0); return;}
# Node range must be defined
if (!defined($noderange)) { $mkvlan_usage->(1); return;}
# Display the version of the code
if ($VERSION) {
my %rsp;
my $version = xCAT::Utils->Version();
@ -115,6 +118,29 @@ sub mkvlan
return;
}
# put the nodes in an array
my @nodes = split(/,/,$noderange);
my $swtab = xCAT::Table->new('switch');
my $swhash = $swtab->getNodesAttribs(\@nodes,['switch','vlan','port','interface']);
foreach (@nodes)
{
my $node = $_;
foreach (@$swhash->{$node})
{
my $nswhash = $_;
my $switch = $nswhash->{'switch'};
my $vlan = $nswhash->{'vlan'};
my $port = $nswhash->{'port'};
my $swinterface = $nswhash->{'interface'};
if ($vlanid == "" || !defined($vlanid)) {$vlanid = $vlan;}
if ($interface == "" || !defined($interface)) { $interface = $swinterface;}
}
}