add lsvlan, a few initial changes

This commit is contained in:
Arif Ali 2014-05-04 16:09:33 +01:00
parent e6315798fc
commit 397e964364

View File

@ -1,5 +1,4 @@
#!/usr/bin/perl
# OCF(c) 2014 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT_plugin::vlan;
BEGIN
@ -10,32 +9,27 @@ use lib "$::XCATROOT/lib/perl";
use strict;
use warnings "all";
use xCAT::GlobalDef;
use xCAT::SPD qw/decode_spd/;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::SvrUtils;
use xCAT::Usage;
use Scalar::Util qw(looks_like_number);
sub handled_commands {
return {
mkvlan => 'switch:vlan,port,switch', #done
chvlan => 'switch:vlan,port,switch', #done
lsvlan => 'switch:vlan,port,switch', #done
rmvlan => 'switch:vlan,port,switch', #done
mkvlan => 'switch:vlan,port,switch', # in progress
chvlan => 'switch:vlan,port,switch', # in progress
lsvlan => 'switch:vlan,port,switch', # in progress
rmvlan => 'switch:vlan,port,switch', # in progress
}
}
use POSIX "WNOHANG";
use IO::Handle;
use IO::Socket;
use IO::Select;
use Class::Struct;
use Digest::MD5 qw(md5);
use POSIX qw(WNOHANG mkfifo strftime);
use Fcntl qw(:flock);
#local to module
my $callback;
@ -50,15 +44,13 @@ my %pendingtransactions; #list of peers with callbacks, callback arguments, and
my $enable_cache="yes";
my $cache_dir = "/var/cache/xcat";
my $vlanid;
sub process_request
{
my $req = shift;
my $callback = shift;
my $reqcmd = shift;
my $nodes = $req->{node};
my $command = $req->{command}->[0];
my $args = $req->{arg};
my @nodes = $req
if ($command eq 'mkvlan')
{
@ -78,25 +70,88 @@ sub process_request
}
}
sub mkvlan
{
my $request = shift;
my $callback = shift;
my $reqcmd = shift;
my $nodes = @{$req->{node}};
my @args = @{$req->{arg}} if(exists($req->{arg}));
my @nodes = @{$req->{node}};
# Variables for this function
my $vlanid;
# A quick function for usage information for the command
my $mkvlan_usage = sub {
my $exitcode = shift @_;
my %rsp;
push @{$rsp{data}}, "Usage: mkvlan [vlanid] -n noderange [-t subnet | -m netmask | -i interface]";
push @{$rsp{data}}, " mkvlan [-?|-h|--help]";
if ($exitcode) { $rsp{errorcode} = $exitcode; }
$callback->(\%rsp);
};
# 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,
'v=s' => \$vlan,
'n=s' => \$noderange,
'i=s' => \$interface,
'h|?|help' => \$help,
'v|version' => \$VERSION,
);
# Show usage info if help is defined
if ($help) { $mkvlan_usage->(0); return; }
if ($VERSION) {
my %rsp;
my $version = xCAT::Utils->Version();
$rsp{data}->[0] = "$version";
$cb->(\%rsp);
return;
}
}
sub lsvlan
{
my $request = shift;
my $callback = shift;
my $reqcmd = shift;
my @args = @{$req->{arg}} if(exists($req->{arg}));
# A quick function for usage information for the command
my $lsvlan_usage = sub {
my $exitcode = shift @_;
my %rsp;
push @{$rsp{data}}, "Usage: mkvlan vlanid";
push @{$rsp{data}}, " mkvlan [-?|-h|--help]";
if ($exitcode) { $rsp{errorcode} = $exitcode; }
$callback->(\%rsp);
};
# 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(
'h|?|help' => \$help,
);
# Show usage info if help is defined
if ($help) { $lsvlan_usage->(0); return; }
# Show usage if we have less then 2 arguments, or the vlan option is not defined
if (scalar(@ARGV)<1 || !defined($vlanid)) { $lsvlan_usage->(1); return; }
}
1;