You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by ar...@apache.org on 2018/04/26 20:16:14 UTC

vcl git commit: VCL-1093 Added code contributed by [~junaid.ali] check to make sure VM's power is off in VMware.pm::delete_vm before attempting to unregister.

Repository: vcl
Updated Branches:
  refs/heads/VCL-1093 [created] 38e25f232


VCL-1093
Added code contributed by [~junaid.ali] check to make sure VM's power is off in VMware.pm::delete_vm before attempting to unregister.

Made minor regex change in VIM_SSH.pm::vm_unregister to check for VM power state 'not off' rather than 'is on' to prevent possible problems if something like 'suspended' was returned.

Added code to vSphere_SDK.pm::vm_unregister to check VM power state before attempting to unregister it. This aligns it with VIM_SSH.pm.


Project: http://git-wip-us.apache.org/repos/asf/vcl/repo
Commit: http://git-wip-us.apache.org/repos/asf/vcl/commit/38e25f23
Tree: http://git-wip-us.apache.org/repos/asf/vcl/tree/38e25f23
Diff: http://git-wip-us.apache.org/repos/asf/vcl/diff/38e25f23

Branch: refs/heads/VCL-1093
Commit: 38e25f232a33d1bd32f77cfc2e9f4d5712d5cfad
Parents: 407c44e
Author: Andy Kurth <ar...@apache.org>
Authored: Thu Apr 26 16:15:28 2018 -0400
Committer: Andy Kurth <ar...@apache.org>
Committed: Thu Apr 26 16:15:28 2018 -0400

----------------------------------------------------------------------
 managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm | 4 ++--
 managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm  | 7 +++++++
 .../lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm        | 8 ++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vcl/blob/38e25f23/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
----------------------------------------------------------------------
diff --git a/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm b/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
index 6931318..c3a88d2 100644
--- a/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
+++ b/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
@@ -1548,7 +1548,7 @@ sub vm_register {
 
 =head2 vm_unregister
 
- Parameters  : $vm_identifier 
+ Parameters  : $vm_identifier
  Returns     : boolean
  Description : Unregisters the VM indicated by the argument which may either be
                the .vmx file path or VM ID.
@@ -1588,7 +1588,7 @@ sub vm_unregister {
 		
 		# Power of the VM if it is powered on or the unregister command will fail
 		my $vm_power_state = $self->get_vm_power_state($vmx_file_path);
-		if ($vm_power_state && $vm_power_state =~ /on/i) {
+		if ($vm_power_state && $vm_power_state !~ /off/i) {
 			if (!$self->vm_power_off($vmx_file_path)) {
 				notify($ERRORS{'WARNING'}, 0, "failed to unregister VM because it could not be powered off: $vmx_file_path");
 				return;

http://git-wip-us.apache.org/repos/asf/vcl/blob/38e25f23/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
----------------------------------------------------------------------
diff --git a/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm b/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
index aa465ff..4e89641 100644
--- a/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
+++ b/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
@@ -5839,6 +5839,13 @@ sub delete_vm {
 		# The VM needs to be registered for get_vm_virtual_disk_file_paths to work
 		@virtual_disks = $self->api->get_vm_virtual_disk_file_paths($vmx_file_path);
 		
+		# Make sure VM is powered off before trying to unregister it
+		if (!$self->api->vm_power_off($vmx_file_path)) {
+			notify($ERRORS{'WARNING'}, 0, "failed to power off VM: $vmx_file_path, VM not deleted");
+			return;
+		}
+		
+		# Unregister the VM
 		if (!$self->api->vm_unregister($vmx_file_path)) {
 			notify($ERRORS{'WARNING'}, 0, "failed to unregister VM: $vmx_file_path, VM not deleted");
 			return;

http://git-wip-us.apache.org/repos/asf/vcl/blob/38e25f23/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
----------------------------------------------------------------------
diff --git a/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm b/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
index 3657192..4878da4 100644
--- a/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
+++ b/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
@@ -363,6 +363,14 @@ sub vm_unregister {
 	
 	my $vmx_path = $vm_view->{summary}{config}{vmPathName};
 	
+	my $vm_power_state = $self->get_vm_power_state($vmx_path);
+	if ($vm_power_state && $vm_power_state !~ /off/i) {
+		if (!$self->vm_power_off($vmx_path)) {
+			notify($ERRORS{'WARNING'}, 0, "failed to unregister VM because it could not be powered off: $vmx_path");
+			return;
+		}
+	}
+	
 	# Override the die handler
 	local $SIG{__DIE__} = sub{};