Author: arkurth
Date: Thu Aug 10 16:07:09 2017
New Revision: 1804684

URL: http://svn.apache.org/viewvc?rev=1804684&view=rev
Log:
VCL-1072
Updated VIM_SSH.pm::vm_power_on. Added argument to call to _run_vim_cmd so that 
it only makes 1 attempt of executing the command. Added code to vm_power_on to 
check the output of the command for 'failed'. If 'failed', it checks the power 
status of the VM. If already on, returns true. If not, vm_power_on now calls 
itself one more time. A $is_retry_attempt argument was added to prevent 
circularity.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm?rev=1804684&r1=1804683&r2=1804684&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm 
(original)
+++ vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm Thu 
Aug 10 16:07:09 2017
@@ -1207,7 +1207,7 @@ sub vm_power_on {
        }
        
        # Get the vmx file path argument
-       my $vmx_file_path = shift;
+       my ($vmx_file_path, $is_retry_attempt) = @_;
        if (!$vmx_file_path) {
                notify($ERRORS{'WARNING'}, 0, "vmx file path argument was not 
supplied");
                return;
@@ -1221,13 +1221,15 @@ sub vm_power_on {
        }
        
        my $vim_cmd_arguments = "vmsvc/power.on $vm_id";
-       my ($exit_status, $output) = $self->_run_vim_cmd($vim_cmd_arguments, 
360);
+       my ($exit_status, $output) = $self->_run_vim_cmd($vim_cmd_arguments, 
360, 1);
        return if !$output;
        
        # Expected output if the VM was not previously powered on:
        # Powering on VM:
        
        # Expected output if the VM was previously powered on:
+       
+       # Old versions of ESXi? (unsure about when the output changed)
        # Powering on VM:
        # (vim.fault.InvalidPowerState) {
        #   dynamicType = <unset>,
@@ -1237,6 +1239,10 @@ sub vm_power_on {
        #   msg = "The attempted operation cannot be performed in the current 
state (Powered On).",
        # }
        
+       # ESXi 6.0, 6.5:
+       # Powering on VM:
+       # Power on failed
+       
        if (grep(/existingState = "poweredOn"/i, @$output)) {
                notify($ERRORS{'OK'}, 0, "VM is already powered on: 
$vmx_file_path");
                return 1;
@@ -1245,6 +1251,19 @@ sub vm_power_on {
                notify($ERRORS{'WARNING'}, 0, "unexpected output returned while 
attempting to power on VM $vmx_file_path, VIM command arguments: 
'$vim_cmd_arguments', output:\n" . join("\n", @$output));
                return;
        }
+       elsif (grep(/failed/i, @$output)) {
+               # Power on failed but no indication that VM is already powered 
on from the output, check the power state
+               # Command will occasionally incorrectly report that it failed 
but the VM is actually powered on
+               my $power_state = $self->get_vm_power_state($vmx_file_path);
+               if ($power_state && $power_state =~ /on/i) {
+                       notify($ERRORS{'OK'}, 0, "power on failed because VM is 
already powered on: $vmx_file_path");
+                       return 1;
+               }
+               elsif (!$is_retry_attempt) {
+                       # Make one more attempt, pass it the $is_retry_attempt 
argument to avoid an endless loop
+                       return $self->vm_power_on($vmx_file_path, 1);
+               }
+       }
        
        # Get the task ID
        my @task_ids = $self->_get_task_ids($vmx_file_path, 'powerOn');
@@ -1319,6 +1338,10 @@ sub vm_power_off {
        #   msg = "The attempted operation cannot be performed in the current 
state (Powered Off).",
        # }
        
+       # ESXi 6.0, 6.5:
+       # Powering off VM:
+       # Power off failed
+       
        if (grep(/existingState = "poweredOff"/i, @$output)) {
                notify($ERRORS{'DEBUG'}, 0, "VM is already powered off: 
$vmx_file_path");
                return 1;


Reply via email to