From ce8f2e5282e04ea78f7104af7b6301490e99bf70 Mon Sep 17 00:00:00 2001 From: daniceexi Date: Mon, 10 Sep 2012 13:13:25 +0000 Subject: [PATCH] use ch/rmhypervisor to replace the cfghost command. fix the network attaching and cfg host nic issues git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@13736 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/rhevm.pm | 167 +++++++++++++++++--------- 1 file changed, 107 insertions(+), 60 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/rhevm.pm b/xCAT-server/lib/xcat/plugins/rhevm.pm index 4869b27ec..ef7802c52 100644 --- a/xCAT-server/lib/xcat/plugins/rhevm.pm +++ b/xCAT-server/lib/xcat/plugins/rhevm.pm @@ -58,22 +58,19 @@ sub handled_commands{ copycd => 'rhevm', mkinstall => "nodetype:os=(rhevh.*)", rpower => 'nodehm:power,mgt', - rsetboot => 'nodehm:power,mgt', - rmigrate => 'nodehm:power,mgt', - addhost => 'hypervisor:type=(rhelh)', - cfghost => 'hypervisor:type=(rhevh)', + rsetboot => 'nodehm:mgt', + rmigrate => 'nodehm:mgt', cfgve => 'rhevm', lsve => 'rhevm', lsvm => ['hypervisor:type=(rhev.*)','nodehm:mgt'], mkvm => 'nodehm:mgt', rmvm => 'nodehm:mgt', clonevm => 'nodehm:mgt', - rmigrate => 'nodehm:mgt', #rinv => 'nodehm:mgt', chvm => 'nodehm:mgt', #rshutdown => "nodetype:os=(rhev.*)", - #rmhypervisor => ['hypervisor:type','nodetype:os=(rhev.*)'], - #chhypervisor => ['hypervisor:type','nodetype:os=(rhev.*)'], + rmhypervisor => ['hypervisor:type','nodetype:os=(rhev.*)'], + chhypervisor => ['hypervisor:type','nodetype:os=(rhev.*)'], rhevhupdateflag => "nodetype:os=(rhevh.*)", getrvidparms => 'nodehm:mgt', }; @@ -354,9 +351,12 @@ sub process_request { rsetboot($callback, \%rhevm_hash, $args); } elsif ($command eq "addhost") { addhost($callback, \%rhevm_hash); - } elsif ($command eq "cfghost") { + } elsif ($command eq "chhypervisor") { cfghost($callback, \%rhevm_hash, $nodes, $args); - } elsif ($command eq "cfgve") { + } elsif ($command eq "rmhypervisor") { + push @$args, "-r"; + cfghost($callback, \%rhevm_hash, $nodes, $args); + }elsif ($command eq "cfgve") { cfgve($callback, \%rhevm_hash,$args); } elsif ($command eq "lsve") { lsve($callback, \%rhevm_hash,$args); @@ -596,7 +596,7 @@ sub mkinstall { $kcmdline .= " adminpw=$rhevm_hash->{$rhevm}->{host}->{$node}->{adminpw} rootpw=$rhevm_hash->{$rhevm}->{host}->{$node}->{rootpw} ssh_pwauth=1"; # set the hostname and password of the management server for the node so that node could register to the rhevm automatically. - $kcmdline .= " management_server=$rhevm_hash->{$rhevm}->{name} rhevm_admin_password=$rhevm_hash->{$rhevm}->{host}->{$node}->{rootpw}"; + $kcmdline .= " management_server=$rhevm_hash->{$rhevm}->{name} rhevm_admin_password=$rhevm_hash->{$rhevm}->{host}->{$node}->{rootpw}"; # set the flag update trigger, after installing of rhev-h, this url will be 'wget', xCAT MN will handle this event to run the upfateflag for this rhev-h my $xcatmaster; @@ -852,6 +852,7 @@ my $display = { }, 'networks' => { 'description' => ["description"], + 'vlan' => ["vlan", "id"], 'stp' => ["stp"], 'state' => ["status/state"], }, @@ -1154,13 +1155,14 @@ sub cfgve { my $args = shift; my $nodes = shift; - my ($type, $objlist, $mgr, $datacenter, $create, $update, $remove, $activate, $deactivate, $attach, $detach, $force, $stype, $cputype); + my ($type, $objlist, $mgr, $datacenter, $cluster, $create, $update, $remove, $activate, $deactivate, $attach, $detach, $force, $stype, $cputype, $vlan); if ($args) { @ARGV=@{$args}; GetOptions('t=s' => \$type, 'o=s' => \$objlist, 'm=s' => \$mgr, 'd=s' => \$datacenter, + 'l=s' => \$cluster, 'c' => \$create, 'u' => \$update, 'g' => \$activate, @@ -1170,7 +1172,8 @@ sub cfgve { 'r' => \$remove, 'f' => \$force, 'k=s' => \$stype, - 'p=s' => \$cputype); + 'p=s' => \$cputype, + 'v=s' => \$vlan); } my $rhevm = (keys %{$rhevm_hash})[0]; @@ -1277,6 +1280,9 @@ sub cfgve { my $api = "/api/networks"; my $method = "POST"; my $content = "$obj"; + if ($vlan) { + $content = "$obj"; + } my $request = genreq($ref_rhevm, $method, $api, $content); my $response; ($rc, $response) = send_req($ref_rhevm, $request->as_string()); @@ -1300,6 +1306,48 @@ sub cfgve { next; } generalaction($callback, $ref_rhevm, "/api/networks/$nwid", "DELETE", 1); + } elsif ($attach || $detach) { + unless ($cluster) { + $cluster = "Default"; + } + my ($rc, $clid, $stat, $response) = search_src($ref_rhevm, "clusters", "$cluster"); + if ($rc) { + my $rsp; + push @{$rsp->{data}}, "$obj: cannot find the cluster:$cluster."; + xCAT::MsgUtils->message("E", $rsp, $callback); + next; + } + + my $nwid; + ($rc, $nwid, $stat) = search_src($ref_rhevm, "networks", "$obj"); + if ($rc) { + my $rsp; + push @{$rsp->{data}}, "$obj: cannot find the network."; + xCAT::MsgUtils->message("E", $rsp, $callback); + next; + } + + if ($attach) { + my $api = "/api/clusters/$clid/networks"; + my $method = "POST"; + my $content = "$obj"; + my $request = genreq($ref_rhevm, $method, $api, $content); + my $response; + ($rc, $response) = send_req($ref_rhevm, $request->as_string()); + if ($rc) { + my $rsp; + push @{$rsp->{data}}, "$obj: $response"; + xCAT::MsgUtils->message("E", $rsp, $callback); + next; + } else { + my $rsp; + push @{$rsp->{data}}, "$obj: succeeded"; + xCAT::MsgUtils->message("I", $rsp, $callback); + next; + } + } elsif($detach) { + generalaction($callback, $ref_rhevm, "/api/clusters/$clid/networks/$nwid", "DELETE", 1); + } } } elsif ($type eq "dc") { my ($rc, $dcid, $stat, $response) = search_src($ref_rhevm, "datacenters", "$obj"); @@ -1767,7 +1815,7 @@ sub mkvm { # Get the attributes for the node from the vm table my $vmtab = xCAT::Table->new('vm',-create=>0); - my $vment = $vmtab->getNodesAttribs($nodes,['template', 'host', 'cluster', 'virtflags', 'storage', 'storagemodel', 'memory', 'cpus', 'nics', 'nicmodel', 'bootorder', 'vidproto']); + my $vment = $vmtab->getNodesAttribs($nodes,['master', 'host', 'cluster', 'virtflags', 'storage', 'storagemodel', 'memory', 'cpus', 'nics', 'nicmodel', 'bootorder', 'vidproto']); # Generate the xml content for add the storage # Note: this is an independent action after the vm creating @@ -1906,8 +1954,8 @@ sub mkvm { # configure the template my $hastpl = 0; my $tplele; - if ($myvment->{template}) { - $tplele = ""; + if ($myvment->{master}) { + $tplele = ""; $hastpl = 1; } else { $tplele = ""; @@ -2291,7 +2339,7 @@ sub chvm { # Get the attributes for the nodes from the vm table my $vmtab = xCAT::Table->new('vm',-create=>0); - my $vment = $vmtab->getNodesAttribs($nodes,['template', 'host', 'cluster', 'virtflags', 'storage', 'storagemodel', 'memory', 'cpus', 'nics', 'nicmodel', 'bootorder', 'vidproto']); + my $vment = $vmtab->getNodesAttribs($nodes,['master', 'host', 'cluster', 'virtflags', 'storage', 'storagemodel', 'memory', 'cpus', 'nics', 'nicmodel', 'bootorder', 'vidproto']); foreach my $rhevm (keys %{$rhevm_hash}) { my %node_hyp; @@ -2353,8 +2401,8 @@ sub chvm { # generate the content my $tplele; - if ($myvment->{template}) { - $tplele = ""; + if ($myvment->{master}) { + $tplele = ""; } # configure memory @@ -3138,6 +3186,45 @@ sub cfghypnw { if ($attr = getAttr($doc, "network", "id")) { $netid = $attr; } + + # attach the nic to the network if needed + # search the network + my $curnetid; + ($rc, $curnetid, $stat) = search_src($ref_rhevm, "networks", $netname); + if ($rc) { + if ($rc == 11) { + my $rsp; + push @{$rsp->{data}}, "$host: network: $netname does not exist."; + xCAT::MsgUtils->message("E", $rsp, $callback); + } else { + my $rsp; + push @{$rsp->{data}}, "$host: failed to get the network: $netname."; + xCAT::MsgUtils->message("E", $rsp, $callback); + } + next; + } + + # detach the nic from current network if old != new + if ($netid && ($netid ne $curnetid)) { + #detach the interface to the network + if (attach($callback, $ref_rhevm, "/api/hosts/$hostid/nics/$nicid", "network", $curnetid, 1)) { + my $rsp; + push @{$rsp->{data}}, "$host: failed to detach $ifname from $netname."; + xCAT::MsgUtils->message("E", $rsp, $callback); + next; + } + } + + # attach the interface to the network + if (!$netid ||($netid ne $curnetid)) { + if (attach($callback, $ref_rhevm, "/api/hosts/$hostid/nics/$nicid", "network", $curnetid)) { + my $rsp; + push @{$rsp->{data}}, "$host: failed to attach $ifname to $netname."; + xCAT::MsgUtils->message("E", $rsp, $callback); + next; + } + generalaction($callback, $ref_rhevm, "/api/hosts/$hostid/commitnetconfig"); + } # check the bootprotocol and network parameters, and configure if needed if (defined ($bprotocol) && $bprotocol =~ /^(dhcp|static)$/) { @@ -3187,55 +3274,15 @@ sub cfghypnw { my $rsp; push @{$rsp->{data}}, "$host: $response"; xCAT::MsgUtils->message("E", $rsp, $callback); + next; } } } else { my $rsp; push @{$rsp->{data}}, "$host: the boot procotol was not set or invalid."; xCAT::MsgUtils->message("E", $rsp, $callback); - } - - # search the network - my $curnetid; - ($rc, $curnetid, $stat) = search_src($ref_rhevm, "networks", $netname); - if ($rc) { - if ($rc == 11) { - my $rsp; - push @{$rsp->{data}}, "$host: network: $netname does not exist."; - xCAT::MsgUtils->message("E", $rsp, $callback); - } else { - my $rsp; - push @{$rsp->{data}}, "$host: failed to get the network: $netname."; - xCAT::MsgUtils->message("E", $rsp, $callback); - } next; } - - if ($netid eq $curnetid) { - generalaction($callback, $ref_rhevm, "/api/hosts/$hostid/commitnetconfig"); - next; - } - if ($netid) { - if ($netid eq $curnetid) { - next; - } else { - #detach the interface to the network - if (attach($callback, $ref_rhevm, "/api/hosts/$hostid/nics/$nicid", "network", $curnetid, 1)) { - my $rsp; - push @{$rsp->{data}}, "$host: failed to detach $ifname from $netname."; - xCAT::MsgUtils->message("E", $rsp, $callback); - next; - } - } - } - - # attach the interface to the network - if (attach($callback, $ref_rhevm, "/api/hosts/$hostid/nics/$nicid", "network", $curnetid)) { - my $rsp; - push @{$rsp->{data}}, "$host: failed to attach $ifname to $netname."; - xCAT::MsgUtils->message("E", $rsp, $callback); - next; - } generalaction($callback, $ref_rhevm, "/api/hosts/$hostid/commitnetconfig"); } @@ -3489,7 +3536,7 @@ sub attach { if ($doc ) { my $attr; if ($type eq "storage_domain") { - if ("inactive" eq getAttr($doc, "/storage_domain/status/state")) { + if (getAttr($doc, "/storage_domain/status/state" =~ /(inactive|active)/)) { return 0; } else { return 1;