changes for multi vlan support

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13560 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2012-08-20 20:00:45 +00:00
parent 9bd7ba8625
commit bfd8e946be
2 changed files with 34 additions and 73 deletions

View File

@ -1,6 +1,13 @@
#!/usr/bin/perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::MacMap;
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use lib "$::XCATROOT/lib/perl";
require Exporter;
our @ISA=qw/Exporter/;
our @EXPORT_OK=qw/walkoid/;
@ -177,11 +184,19 @@ sub rvlan {
#first order of business is to identify the target switches
my $switchtab=xCAT::Table->new('switch',-create=>0);
unless ($switchtab) { return; }
my $switchents = $switchtab->getNodesAttribs($nodes,[qw/switch port/]);
my $switchents = $switchtab->getNodesAttribs($nodes,[qw/switch port interface/]);
my $node;
foreach $node (keys %$switchents) {
my $entry;
foreach $entry (@{$switchents->{$node}}) {
#skip the none primary interface.
# The vlaue of the primary interface could be empty, primary or primary:ethx
if (defined($entry->{interface})) {
if ($entry->{interface} !~ /primary/) {
next;
}
}
$self->{switches}->{$entry->{switch}}->{$entry->{port}} = $node;
}
}
@ -319,11 +334,17 @@ sub refresh_table {
}
}
my %checked_pairs;
my @entries = $self->{switchtab}->getAllNodeAttribs(['node','port','switch']);
my @entries = $self->{switchtab}->getAllNodeAttribs(['node','port','switch','interface']);
#Build hash of switch port names per switch
$self->{switches} = {};
foreach my $entry (@entries) {
if (defined($entry->{switch}) and $entry->{switch} ne "" and defined($entry->{port}) and $entry->{port} ne "") {
#skip the none primary interface.
# The vlaue of the primary interface could be empty, primary or primary:ethx
if (defined($entry->{interface})) {
if ($entry->{interface} !~ /primary/) { next;}
}
if ( !$self->{switches}->{$entry->{switch}}->{$entry->{port}})
{
$self->{switches}->{$entry->{switch}}->{$entry->{port}} = $entry->{node};

View File

@ -194,6 +194,7 @@ sub makescript
push @scriptd, "GROUP=$groups->{groups}\n";
push @scriptd, "export GROUP\n";
# read the sshbetweennodes attribute and process
my $enablessh=xCAT::TableUtils->enablessh($node);
if ($enablessh == 1) {
@ -368,78 +369,17 @@ sub makescript
}
#get vlan related items
my $vlan;
my $swtab = xCAT::Table->new("switch", -create => 0);
if ($swtab) {
my $tmp = $swtab->getNodeAttribs($node, ['vlan'],prefetchcache=>1);
if (defined($tmp) && ($tmp) && $tmp->{vlan})
{
$vlan = $tmp->{vlan};
push @scriptd, "VLANID='" . $vlan . "'\n";
push @scriptd, "export VLANID\n";
} else {
my $vmtab = xCAT::Table->new("vm", -create => 0);
if ($vmtab) {
my $tmp1 = $vmtab->getNodeAttribs($node, ['nics'],prefetchcache=>1);
if (defined($tmp1) && ($tmp1) && $tmp1->{nics})
{
push @scriptd, "VMNODE='YES'\n";
push @scriptd, "export VMNODE\n";
my @nics=split(',', $tmp1->{nics});
foreach my $nic (@nics) {
if ($nic =~ /^vl([\d]+)$/) {
$vlan = $1;
push @scriptd, "VLANID='" . $vlan . "'\n";
push @scriptd, "export VLANID\n";
last;
}
}
}
}
}
if ($vlan) {
my $nwtab=xCAT::Table->new("networks", -create =>0);
if ($nwtab) {
my $sent = $nwtab->getAttribs({vlanid=>"$vlan"},'net','mask');
my $subnet;
my $netmask;
if ($sent and ($sent->{net})) {
$subnet=$sent->{net};
$netmask=$sent->{mask};
}
if (($subnet) && ($netmask)) {
my $hoststab = xCAT::Table->new("hosts", -create => 0);
if ($hoststab) {
my $tmp = $hoststab->getNodeAttribs($node, ['otherinterfaces'],prefetchcache=>1);
if (defined($tmp) && ($tmp) && $tmp->{otherinterfaces})
{
my $otherinterfaces = $tmp->{otherinterfaces};
my @itf_pairs=split(/,/, $otherinterfaces);
foreach (@itf_pairs) {
my ($name,$ip)=split(/:/, $_);
if(xCAT::NetworkUtils->ishostinsubnet($ip, $netmask, $subnet)) {
if ($name =~ /^-/ ) {
$name = $node.$name;
}
push @scriptd, "VLANHOSTNAME='" . $name . "'\n";
push @scriptd, "export VLANHOSTNAME\n";
push @scriptd, "VLANIP='" . $ip . "'\n";
push @scriptd, "export VLANIP\n";
push @scriptd, "VLANSUBNET='" . $subnet . "'\n";
push @scriptd, "export VLANSUBNET\n";
push @scriptd, "VLANNETMASK='" . $netmask . "'\n";
push @scriptd, "export VLANNETMASK\n";
last;
}
}
}
}
}
}
}
my $module_name="xCAT_plugin::vlan";
my @tmp_scriptd=();
eval("use $module_name;");
if (!$@) {
no strict "refs";
if (defined(${$module_name."::"}{getNodeVlanConfData})) {
@tmp_scriptd=${$module_name."::"}{getNodeVlanConfData}->($node);
}
}
@scriptd=(@scriptd,@tmp_scriptd);
#print Dumper(@tmp_scriptd);
#get monitoring server and other configuration data for monitoring setup on nodes