Compare commits

...

3 Commits

Author SHA1 Message Date
cb2d15cf29 update work on mkvlan 2014-05-04 18:26:29 +01:00
397e964364 add lsvlan, a few initial changes 2014-05-04 16:09:33 +01:00
e6315798fc start work on mkvlan support 2014-05-04 15:30:04 +01:00
2 changed files with 257 additions and 0 deletions

View File

@ -0,0 +1,74 @@
=head1 Name
B<mkvlan> - Create vlan on switches
=head1 B<Synopsis>
B<mkvlan> [B<-h>|B<--help>|B<?>|B<-v>|B<--version>]
B<mkvlan> {Ivlanid} -n I<noderange> {B-i <interface>|B-m <netmask> |B-t <subnet>}
=head1 B<Description>
B<mkvlan> creates tagged vlan on the switches corresponding to the attributes defined in the B<switch> table
=head1 B<Options>
=over 7
=item B<vlanid>
The vlan to tag on the switch.
=item B<interface>
List all buses for each I/O slot.
=item B<netmask>
Retrieves number of processors, speed, total memory, and DIMM
locations.
=item B<subnet>
Retrieves model number.
=item B<-h>|B<--help>|B<?>
Print help.
=item B<-v>|B<--version>
Print version.
=back
=back
=head1 B<Examples>
=over 4
=item *
To make a private vlan for stand-alone nodes for the management network, enter:
mkvlan -n node1,node2,node3
=item *
You can specify vlan id, subnet and netmask etc, enter:
mkvlan 3 -n node1,node2,node3 -t 10.3.2.0 -m 255.255.255.0
=item *
To create a tagged vlan on an interface, enter:
mkvlan -n node1,node2,node3 -i eth1
=back
=head1 SEE ALSO
L<noderange(3)|noderange.3>, L<lsvlan(1)|lsvlan.1>

View File

@ -0,0 +1,183 @@
#!/usr/bin/perl
package xCAT_plugin::vlan;
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use lib "$::XCATROOT/lib/perl";
use strict;
use warnings "all";
use xCAT::GlobalDef;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::SvrUtils;
use xCAT::Usage;
use xCAT::NodeRange;
sub handled_commands {
return {
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;
#local to module
my $callback;
my $timeout;
my $port;
my $debug;
my $ndebug = 0;
my $sock;
my $noclose;
my %sessiondata; #hold per session variables, in preparation for single-process strategy
my %pendingtransactions; #list of peers with callbacks, callback arguments, and timer expiry data
my $enable_cache="yes";
my $cache_dir = "/var/cache/xcat";
my $vlanid;
sub process_request
{
my $req = shift;
my $callback = shift;
my $reqcmd = shift;
if ($command eq 'mkvlan')
{
return mkvlan($req, $callback, $reqcmd);
}
elsif ($command eq 'chvlan')
{
return chvlan($req, $callback, $reqcmd);
}
elsif ($command eq 'lsvlan')
{
return lsvlan($req, $callback, $reqcmd);
}
elsif ($command eq 'rmvlan')
{
return rmvlan($req, $callback, $reqcmd);
}
}
sub mkvlan
{
my $request = shift;
my $callback = shift;
my $reqcmd = shift;
# 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,
'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;}
# 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();
$rsp{data}->[0] = "$version";
$cb->(\%rsp);
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;}
}
}
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;