From 8b786b30c58be81d33e0a50620a227b96783d6a0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 2 Oct 2013 12:28:29 -0400 Subject: [PATCH] If xCAT-vlan is installed, have chhypervisor change the switch and the hypervisor --- xCAT-server/lib/xcat/plugins/esx.pm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index 3526260cc..e03a1b8de 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -23,6 +23,7 @@ use File::Temp qw/tempdir/; use File::Copy; use Fcntl qw/:flock/; use IO::Socket; #Need name resolution +use Scalar::Util qw/looks_like_number/; #use Data::Dumper; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); @@ -3748,9 +3749,13 @@ sub fixup_hostportgroup { my $hyp = shift; my %args = @_; my $hostview = $hyphash{$hyp}->{hostview}; + my $switchsupport = 0; + eval { + require xCAT::SwitchHandler; + $switchsupport = 1; + }; my $hypconn = $hyphash{$hyp}->{conn}; #this function can't work in clustered mode anyway, so this is appropriote. my $vldata = $vlanspec; - my $switchname = get_default_switch_for_hypervisor($hyp); my $pgname; $vldata =~ s/=.*//; #TODO specify nic model with =model @@ -3766,13 +3771,29 @@ sub fixup_hostportgroup { my $policy = HostNetworkPolicy->new(); unless ($hyphash{$hyp}->{nets}->{$pgname}) { my $vlanid; - if ($vldata =~ /trunk/) { + if (looks_like_number($vldata)) { + $vlanid = $vldata; + } elsif ($vldata =~ /trunk/) { $vlanid=4095; } elsif ($vldata =~ /vl(an)?(\d+)$/) { $vlanid=$2; } else { $vlanid = 0; } + if ($vlanid > 0 and $vlanid < 4095 and $switchsupport) { + my $switchtab = xCAT::Table->new("switch", -create=>0); + if ($switchtab) { + my $swent = $switchtab->getNodeAttribs($hyp, [qw/switch port/]); + if ($swent and $swent->{'switch'}) { + my $swh = new xCAT::SwitchHandler->new($swent->{'switch'}); + my @vlids = $swh->get_vlan_ids(); + unless (grep {$_ eq $vlanid} @vlids) { + $swh->create_vlan($vlanid); + } + $swh->add_ports_to_vlan($vlanid, $swent->{'port'}); + } + } + } my $hostgroupdef = HostPortGroupSpec->new( name =>$pgname, vlanId=>$vlanid,