From e9f1d08be267bdeaaaacb7a6b65cae5c721fa452 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 9 Mar 2011 15:20:00 +0000 Subject: [PATCH] Add force argument to rmhypervisor git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9019 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/esx.pm | 40 +++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index 24a05a0a5..46b931660 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -45,6 +45,7 @@ my $requester; my $viavcenter; my $viavcenterbyhyp; my $vcenterautojoin=1; +my $vcenterforceremove=0; #used in rmhypervisor my $reconfigreset=1; my $vmwaresdkdetect = eval { require VMware::VIRuntime; @@ -383,6 +384,9 @@ sub process_request { if ($command eq 'rmigrate' or $command eq 'rmhypervisor') { #Only use vcenter when required, fewer prereqs $viavcenter = 1; } + if ($command eq 'rmhypervisor' and grep /-f/, @exargs) { #force remove of hypervisor + $vcenterforceremove=1; + } my $keytab = xCAT::Table->new('prodkey'); if ($keytab) { my @hypes = keys %hyphash; @@ -1012,6 +1016,28 @@ sub connecthost_callback { } } +sub delhost_callback { #only called in rmhypervisor -f case during validate vcenter phase + my $task = shift; + my $args = shift; + my $hv = $args->{hostview}; + my $state = $task->info->state->val; + if ($state eq "success") { + xCAT::SvrUtils::sendmsg("removed", $output_handler,$args->{hypname}); + $hypready{$args->{hypname}} = -1; #Impossible for this hypervisor to ever be ready + $vcenterhash{$args->{vcenter}}->{badhyps}->{$args->{hypname}} = 1; + } elsif ($state eq 'error') { + my $error = $task->info->error->localizedMessage; + if (defined ($task->info->error->fault->faultMessage)) { #Only in 4.0, support of 3.5 must be careful? + foreach(@{$task->info->error->fault->faultMessage}) { + $error.=$_->message; + } + } + xCAT::SvrUtils::sendmsg([1,$error], $output_handler); #,$node); + $hypready{$args->{hypname}} = -1; #Impossible for this hypervisor to ever be ready + $vcenterhash{$args->{vcenter}}->{badhyps}->{$args->{hypname}} = 1; + } +} + sub get_clusterview { my %args = @_; my $clustname = $args{clustname}; @@ -1768,9 +1794,9 @@ sub rmhypervisor_disconnected { my $state = $task->info->state->val; if ($state eq 'success') { my $task = $hyphash{$hyp}->{hostview}->Destroy_Task(); - $running_tasks{$task}->{data} = { node => $node, successtext => 'removed' }; - $running_tasks{$task}->{task} = $task; - $running_tasks{$task}->{callback} = \&generic_task_callback; + $running_tasks{$task}->{data} = { node => $node, successtext => 'removed' }; + $running_tasks{$task}->{task} = $task; + $running_tasks{$task}->{callback} = \&generic_task_callback; $running_tasks{$task}->{hyp} =$hyp; } elsif ($state eq 'error') { relay_vmware_err($task,"",$node); @@ -2861,7 +2887,7 @@ sub validate_vcenter_prereqs { #Communicate with vCenter and ensure this host is return 1; - } elsif ($vcenterautojoin) { #if allowed autojoin and the current view seems corrupt, throw it away and rejoin + } elsif ($vcenterautojoin or $vcenterforceremove) { #if allowed autojoin and the current view seems corrupt, throw it away and rejoin my $ref_to_delete; if ($hview->parent->type eq 'ClusterComputeResource') { #We are allowed to specifically kill a host in a cluster $ref_to_delete = $hview->{mo_ref}; @@ -2870,7 +2896,11 @@ sub validate_vcenter_prereqs { #Communicate with vCenter and ensure this host is } my $task = $hyphash{$hyp}->{vcenter}->{conn}->get_view(mo_ref=>$ref_to_delete)->Destroy_Task(); $running_tasks{$task}->{task} = $task; - $running_tasks{$task}->{callback} = \&addhosttovcenter; + if ($vcenterautojoin) { + $running_tasks{$task}->{callback} = \&addhosttovcenter; + } elsif ($vcenterforceremove) { + $running_tasks{$task}->{callback} = \&delhost_callback; + } $running_tasks{$task}->{conn} = $hyphash{$hyp}->{vcenter}->{conn}; $running_tasks{$task}->{data} = { depfun => $depfun, depargs => $depargs, conn=> $hyphash{$hyp}->{vcenter}->{conn}, connspec=>$connspec,hostview=>$hview,hypname=>$hyp,vcenter=>$vcenter }; return undef;