Skip to content

Instantly share code, notes, and snippets.

@chelnak
Created February 7, 2017 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelnak/92d134920cdc394ec8eb5dbf29fef9e9 to your computer and use it in GitHub Desktop.
Save chelnak/92d134920cdc394ec8eb5dbf29fef9e9 to your computer and use it in GitHub Desktop.
Update IaaS Virtual Machine State
/*
- Update IaaS Virtual Machine State
- Input: virtualMachineName [String]
*/
var state = "Off";
var vCACVirtualMachine = Server.findAllForType("vCAC:VirtualMachine", "VirtualMachineName eq '" + virtualMachineName + "'");
if (vCACVirtualMachine.length == 0) {
throw "Could not find vCACVirtualMachine with name " + virtualMachineName;
}
var vCACEntity = vCACVirtualMachine[0].getEntity();
var hostId = vCACEntity.hostId;
var modelName = vCACEntity.modelName;
var entitySetName = vCACEntity.entitySetName;
var entityIdString = vCACEntity.keyString;
var properties = vCACEntity.getProperties();
properties.put("VirtualMachineState", state);
System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId,modelName,entitySetName,entityIdString,properties,null,null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment