From cb2d15cf29bdeaeb290ed18f31491dacce3e42e9 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Sun, 4 May 2014 18:26:29 +0100 Subject: [PATCH] update work on mkvlan --- xCAT-client/pods/man1/mkvlan.1.pod | 2 +- xCAT-server/lib/xcat/plugins/vlan.pm | 36 ++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/xCAT-client/pods/man1/mkvlan.1.pod b/xCAT-client/pods/man1/mkvlan.1.pod index 54c42ed13..0cfe80393 100644 --- a/xCAT-client/pods/man1/mkvlan.1.pod +++ b/xCAT-client/pods/man1/mkvlan.1.pod @@ -71,4 +71,4 @@ To create a tagged vlan on an interface, enter: =head1 SEE ALSO -L +L, L diff --git a/xCAT-server/lib/xcat/plugins/vlan.pm b/xCAT-server/lib/xcat/plugins/vlan.pm index c790b25f4..e06ad1b25 100644 --- a/xCAT-server/lib/xcat/plugins/vlan.pm +++ b/xCAT-server/lib/xcat/plugins/vlan.pm @@ -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;} + + + } }