VMware Communities
jzaddach
Contributor
Contributor

VIX library returning wrong power state for suspended VMs

When querying the power status of a suspended VM through the VIX library, the API returns VIX_POWERSTATE_POWERED_OFF (2) instead of VIX_POWERSTATE_SUSPENDED (32). Is there another/better way to query via an API whether a VM is shut down or suspended?

Product: VMware Workstation 12 Pro

Version: 12.5.7 build-5813279

OS: Linux 4.8.0-54-generic x86_64 (Ubuntu 16.04)

Steps to reproduce the problem:

-          Create a new VM in VMware Workstation

-          - Power the VM on

-          - Suspend the VM

-          - Compile the attached test file (make)

-          - Run the generated executable with “./vix path_to_vmx_file”

-          - The program should output “Power state of VM is: 32” (but outputs: “Power state of VM is: 2”on my machine)

#include "vmware-vix/vix.h"

#include <stdlib.h>

#include <stdio.h>

int main(int argc, char * argv[])

{

   if (argc < 2) {

       printf("Usage: %s vm\n\tvm\tPath to .vmx file of the virtual machine\n", argv[0]);

       return 1;

   }

   VixHandle hostHandle = VIX_INVALID_HANDLE;

   VixHandle jobHandle = VIX_INVALID_HANDLE;

   VixError err;

   // Connect as current user on local host.

   jobHandle = VixHost_Connect(VIX_API_VERSION,

                               VIX_SERVICEPROVIDER_VMWARE_WORKSTATION,

                               NULL, // hostName

                               0, // hostPort

                               NULL, // userName

                               NULL, // password,

                               0, // options

                               VIX_INVALID_HANDLE, // propertyListHandle

                               NULL, // callbackProc

                               NULL); // clientData

                              

   err = VixJob_Wait(jobHandle,

                     VIX_PROPERTY_JOB_RESULT_HANDLE,

                     &hostHandle,

                     VIX_PROPERTY_NONE);

   if (VIX_OK != err) {

      // Handle the error...

      printf("Cannot connect to VIX host\n");

      goto abort;

   }

  

   Vix_ReleaseHandle(jobHandle);

   jobHandle = VIX_INVALID_HANDLE;

   // Open the virtual machine:

   VixHandle myVM = VIX_INVALID_HANDLE;

   jobHandle = VixVM_Open(hostHandle,

                       argv[1],

                       NULL, // callbackProc

                       NULL); // clientData

   err = VixJob_Wait(jobHandle,

                  VIX_PROPERTY_JOB_RESULT_HANDLE,

                  &myVM,

                  VIX_PROPERTY_NONE);

   if (VIX_OK != err) {

      // Handle the error...

      printf("Cannot open virtual machine\n");

      goto abort;

   }

   int vmPowerState;

   // ...Open the virtual machine and get a handle...

   err = Vix_GetProperties(myVM,

                           VIX_PROPERTY_VM_POWER_STATE,

                           &vmPowerState,

                           VIX_PROPERTY_NONE);

   if (VIX_OK != err) {

      // Handle the error...

      goto abort;

   }

   Vix_ReleaseHandle(myVM);

   printf("Power state of VM is: %d\n", vmPowerState);

   printf("\tSuspended power state is %d\n", VIX_POWERSTATE_SUSPENDED);

   printf("\tShutdown power state is %d\n", VIX_POWERSTATE_POWERED_OFF);

   return 0;

abort:

   VixHost_Disconnect(hostHandle);

   return 1;

}

}

fd

0 Kudos
0 Replies