VMware {code} Community
justinha
Contributor
Contributor
Jump to solution

preventing multiple clients controlling a vm

I am using the VIX API to do a simple set of operations

I open a vm, revert to a snaphsot, then power on the vm and run some commands on it. Finally I close it. I have one difficulty in that the vm can be accessed by multiple VIX API clients - performing the same sequence. The clients are independent of each other. The single shared resource is the vm. I was wondering if it is possible somehow to prevent the multiple clients accessing the vm at the same time. I want the whole operation from reverting the snapshot to powering off the vm to be atomic. I see that I can detect the power state and act accordingly, but this leaves a gap while I am doing the revert to snapshot. Is it maybe possible to use the WriteVariable and ReadVariable functions to act as flags?

Thanks for your help in anticipation!

Reply
0 Kudos
1 Solution

Accepted Solutions
lemke
VMware Employee
VMware Employee
Jump to solution

Vix deosn't have any way to lock a VM.  RaedVaraible and WriteVariable (of type VIX_VM_CONFIG_RUNTIME_ONLY) might allow you to put your own hints in place (still plenty of room for races though).  Note that since those values are presisted in the .vmx file, choose your variable names closely (you don't want to affect the VM by setting something important) and error recovery may also get tricky if your app exits uncleanly and doesn't clear the flag.

View solution in original post

Reply
0 Kudos
2 Replies
lemke
VMware Employee
VMware Employee
Jump to solution

Vix deosn't have any way to lock a VM.  RaedVaraible and WriteVariable (of type VIX_VM_CONFIG_RUNTIME_ONLY) might allow you to put your own hints in place (still plenty of room for races though).  Note that since those values are presisted in the .vmx file, choose your variable names closely (you don't want to affect the VM by setting something important) and error recovery may also get tricky if your app exits uncleanly and doesn't clear the flag.

Reply
0 Kudos
justinha
Contributor
Contributor
Jump to solution

Thanks for your helpful answer lemke. I think I will look at creating an external locking mechanism. I did think I could use the VIX_VM_GUEST_VARIABLE flag to have the variables created with WriteVariable not persistent. I wasn't sure though if the variables would become immediately available to other sessions managing this VM. The documentation (http://www.vmware.com/support/developer/vix-api/vix17_reference/) gave me to believe the values would be volatile if I use the VIX_VM_GUEST_VARIABLE flag.

"variableType
The type of variable to read. The currently supported values are:
  • VIX_VM_GUEST_VARIABLE - A "Guest Variable". This is a runtime-only value; it is never stored persistently. This is the same guest variable that is exposed through the VMControl APIs, and is a simple way to pass runtime values in and out of the guest.
  • VIX_VM_CONFIG_RUNTIME_ONLY - The configuration state of the virtual machine. This is the .vmx file that is stored on the host. You can read this and it will return the persistent data. If you write to this, it will only be a runtime change, so changes will be lost when the VM powers off. Not supported on ESX hosts.
  • VIX_GUEST_ENVIRONMENT_VARIABLE - An environment variable in the guest of the VM. On a Windows NT series guest, writing these values is saved persistently so they are immediately visible to every process. On a Linux or Windows 9X guest, writing these values is not persistent so they are only visible to the VMware tools process. Requires root or Administrator privilege."
Reply
0 Kudos