From 698cf752769968a3925e258daa9de4cc026e98c0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 2 Oct 2013 10:24:18 -0400 Subject: [PATCH 1/3] Refactor hostportgroup management code in esx plugin Have esxi support --addvlan parameter --- xCAT-server/lib/xcat/plugins/esx.pm | 112 ++++++++++++++++------------ xCAT-server/lib/xcat/plugins/svc.pm | 34 +++++++++ 2 files changed, 98 insertions(+), 48 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index b5af9ea99..3526260cc 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -2087,11 +2087,16 @@ sub chhypervisor { my $maintenance; my $online; my $stat; + my $vlanaddspec; + my $vlanremspec; require Getopt::Long; GetOptions( 'maintenance|m' => \$maintenance, 'online|o' => \$online, 'show|s' => \$stat, + 'show|s' => \$stat, + 'addvlan=s' => \$vlanaddspec, + 'removevlan=s' => \$vlanremspec, ); my $hyp = $args{hyp}; $hyphash{$hyp}->{hostview} = get_hostview(hypname=>$hyp,conn=>$hyphash{$hyp}->{conn}); #,properties=>['config','configManager']); @@ -2119,8 +2124,9 @@ sub chhypervisor { xCAT::SvrUtils::sendmsg("hypervisor online", $output_handler,$hyp); } } + } elsif ($vlanaddspec) { + fixup_hostportgroup($vlanaddspec, $hyp); } - return; } @@ -3736,6 +3742,62 @@ sub scan_cluster_networks { } } } + +sub fixup_hostportgroup { + my $vlanspec = shift; + my $hyp = shift; + my %args = @_; + my $hostview = $hyphash{$hyp}->{hostview}; + 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 + if ($vldata =~ /:/) { #The config specifies a particular path in some way + $vldata =~ s/(.*)://; + $switchname = get_switchname_for_portdesc($hyp,$1); + $pgname=$switchname."-".$vldata; + } else { #Use the default vswitch per table config to connect this through, use the same name we did before to maintain compatibility + $pgname=$vldata; + } + my $netsys; + $hyphash{$hyp}->{pgnames}->{$vlanspec}=$pgname; + my $policy = HostNetworkPolicy->new(); + unless ($hyphash{$hyp}->{nets}->{$pgname}) { + my $vlanid; + if ($vldata =~ /trunk/) { + $vlanid=4095; + } elsif ($vldata =~ /vl(an)?(\d+)$/) { + $vlanid=$2; + } else { + $vlanid = 0; + } + my $hostgroupdef = HostPortGroupSpec->new( + name =>$pgname, + vlanId=>$vlanid, + policy=>$policy, + vswitchName=>$switchname + ); + unless ($netsys) { + $netsys = $hyphash{$hyp}->{conn}->get_view(mo_ref=>$hostview->configManager->networkSystem); + } + $netsys->AddPortGroup(portgrp=>$hostgroupdef); + #$hyphash{$hyp}->{nets}->{$netname}=1; + while ((not defined $hyphash{$hyp}->{nets}->{$pgname}) and sleep 1) { #we will only sleep if we know something will be waiting for + $hostview->update_view_data(); #pull in changes induced by previous activity + if (defined $hostview->{network}) { #We load the new object references + foreach (@{$hostview->network}) { + my $nvw = $hypconn->get_view(mo_ref=>$_); + if (defined $nvw->name) { + $hyphash{$hyp}->{nets}->{$nvw->name}=$_; + } + } + } + } + } +} + sub validate_network_prereqs { my $nodes = shift; my $hyp = shift; @@ -3761,53 +3823,7 @@ sub validate_network_prereqs { foreach $node (@$nodes) { my @networks = split /,/,$tablecfg{vm}->{$node}->[0]->{nics}; foreach (@networks) { - my $switchname = get_default_switch_for_hypervisor($hyp); - my $tabval=$_; - my $pgname; - s/=.*//; #TODO specify nic model with =model - if (/:/) { #The config specifies a particular path in some way - s/(.*)://; - $switchname = get_switchname_for_portdesc($hyp,$1); - $pgname=$switchname."-".$_; - } else { #Use the default vswitch per table config to connect this through, use the same name we did before to maintain compatibility - $pgname=$_; - } - my $netname = $_; - my $netsys; - $hyphash{$hyp}->{pgnames}->{$tabval}=$pgname; - my $policy = HostNetworkPolicy->new(); - unless ($hyphash{$hyp}->{nets}->{$pgname}) { - my $vlanid; - if ($netname =~ /trunk/) { - $vlanid=4095; - } elsif ($netname =~ /vl(an)?(\d+)$/) { - $vlanid=$2; - } else { - $vlanid = 0; - } - my $hostgroupdef = HostPortGroupSpec->new( - name =>$pgname, - vlanId=>$vlanid, - policy=>$policy, - vswitchName=>$switchname - ); - unless ($netsys) { - $netsys = $hyphash{$hyp}->{conn}->get_view(mo_ref=>$hostview->configManager->networkSystem); - } - $netsys->AddPortGroup(portgrp=>$hostgroupdef); - #$hyphash{$hyp}->{nets}->{$netname}=1; - while ((not defined $hyphash{$hyp}->{nets}->{$pgname}) and sleep 1) { #we will only sleep if we know something will be waiting for - $hostview->update_view_data(); #pull in changes induced by previous activity - if (defined $hostview->{network}) { #We load the new object references - foreach (@{$hostview->network}) { - my $nvw = $hypconn->get_view(mo_ref=>$_); - if (defined $nvw->name) { - $hyphash{$hyp}->{nets}->{$nvw->name}=$_; - } - } - } - } #end while loop - } + fixup_hostportgroup($_, $hyp); } } return 1; diff --git a/xCAT-server/lib/xcat/plugins/svc.pm b/xCAT-server/lib/xcat/plugins/svc.pm index 4ef660f21..10b2b437b 100644 --- a/xCAT-server/lib/xcat/plugins/svc.pm +++ b/xCAT-server/lib/xcat/plugins/svc.pm @@ -21,6 +21,7 @@ sub handled_commands { return { mkstorage => "storage:type", rmstorage => "storage:type", + lspool => "storage:type", } } @@ -86,6 +87,25 @@ sub mkstorage { } } +sub hashifyoutput { + my @svcoutput = @_; + my $hdr = shift @svcoutput; + my @columns = split /:/, $hdr; + my @ret; + foreach my $line (@svcoutput) { + my $index = 0; + my %record = (); + my $keyname; + foreach my $datum (split /:/, $line) { + $keyname = $columns[$index]; + $record{$keyname} = $datum; + $index += 1; + } + push @ret,\%record; + } + pop @ret; # discard data from prompt + return @ret; +} sub bindhosts { my $nodes = shift; my $lun = shift; @@ -283,10 +303,24 @@ sub process_request { $dorequest = shift; if ($request->{command}->[0] eq 'mkstorage') { mkstorage($request); + } elsif ($request->{command}->[0] eq 'lspool') { + lsmdiskgrp($request); } foreach (values %controllersessions) { $_->close(); } } +sub lsmdiskgrp { + my $req = shift; + foreach my $node (@{$req->{node}}) { + my $session = establish_session(controller=>$node); + my @pools = hashifyoutput($session->cmd("lsmdiskgrp -delim :")); + foreach my $pool (@pools) { + sendmsg($pool->{name}. " available capacity: ".$pool->{free_capacity},$callback,$node); + sendmsg($pool->{name}. " total capacity: ".$pool->{capacity},$callback,$node); + } + } +} + 1; From 8b786b30c58be81d33e0a50620a227b96783d6a0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 2 Oct 2013 12:28:29 -0400 Subject: [PATCH 2/3] 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, From 422cf661ee0d5ef62b0b4c773bb43840d84e9c39 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 2 Oct 2013 13:46:15 -0400 Subject: [PATCH 3/3] Add removevlan support to chhypervisor for vmware --- xCAT-server/lib/xcat/plugins/esx.pm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index e03a1b8de..7de5f2fda 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -2127,6 +2127,8 @@ sub chhypervisor { } } elsif ($vlanaddspec) { fixup_hostportgroup($vlanaddspec, $hyp); + } elsif ($vlanremspec) { + fixup_hostportgroup($vlanremspec, $hyp, action=>'remove'); } return; } @@ -3748,6 +3750,8 @@ sub fixup_hostportgroup { my $vlanspec = shift; my $hyp = shift; my %args = @_; + my $action = 'add'; + if ($args{action}) { $action = $args{action} } my $hostview = $hyphash{$hyp}->{hostview}; my $switchsupport = 0; eval { @@ -3787,10 +3791,14 @@ sub fixup_hostportgroup { 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); + if ($action eq 'add') { + unless (grep {$_ eq $vlanid} @vlids) { + $swh->create_vlan($vlanid); + } + $swh->add_ports_to_vlan($vlanid, $swent->{'port'}); + } elsif ($action eq 'remove') { + $swh->remove_ports_from_vlan($vlanid, $swent->{'port'}); } - $swh->add_ports_to_vlan($vlanid, $swent->{'port'}); } } } @@ -3803,7 +3811,12 @@ sub fixup_hostportgroup { unless ($netsys) { $netsys = $hyphash{$hyp}->{conn}->get_view(mo_ref=>$hostview->configManager->networkSystem); } - $netsys->AddPortGroup(portgrp=>$hostgroupdef); + if ($action eq 'remove') { + $netsys->RemovePortGroup(pgName=>$pgname); + return; + } elsif ($action eq 'add') { + $netsys->AddPortGroup(portgrp=>$hostgroupdef); + } #$hyphash{$hyp}->{nets}->{$netname}=1; while ((not defined $hyphash{$hyp}->{nets}->{$pgname}) and sleep 1) { #we will only sleep if we know something will be waiting for $hostview->update_view_data(); #pull in changes induced by previous activity