Last active
January 3, 2019 19:08
-
-
Save safeaim/05c683364d100e6c8f84ecb390667f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vCAC_Machine = Server.findAllForType("vCAC:VirtualMachine","VMUniqueID eq '" + vm.config.instanceUuid + "'"); | |
var virtualMachineEntity = vCAC_Machine[0].getEntity(); //to get entity | |
var vmEntityProps = virtualMachineEntity.getProperties(); //to get Entity properties for the next step | |
vmEntityProps.remove('VMDNSName'); | |
vmEntityProps.put('VMDNSName', newName); | |
vmEntityProps.put("VirtualMachineName", newName); | |
var hostId = virtualMachineEntity.hostId; | |
var modelName = virtualMachineEntity.modelName; | |
var entitySetName = virtualMachineEntity.entitySetName; | |
var entityIdString = virtualMachineEntity.keyString; | |
//Magic! | |
var Entity_Update = System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId,modelName,entitySetName,entityIdString,vmEntityProps,null,null); | |
var VM_update_Hostname = System.getModule("com.vmware.library.vcac").addUpdatePropertyFromVirtualMachineEntity(vCAC_host,virtualMachineEntity,"Hostname",newName,false,false,false,false); | |
//bind variables | |
var workflowPath = 'Library/vCenter/Virtual Machine management/Basic'; | |
var workflowNameToInvoke = 'Rename virtual machine'; | |
//create execution properties | |
var executionProperties = new Properties(); | |
executionProperties.put('newName',newName); | |
executionProperties.put('vm',vm); | |
//find worfklow catagory and get all workflows | |
var workflows = Server.getWorkflowCategoryWithPath(workflowPath).allWorkflows; | |
//loop over each workflow and find the workflow based on name | |
for each(var workflowObject in workflows){ | |
if(workflowNameToInvoke == workflowObject.name){ | |
//execute workflow and get workflowToken | |
var currentToken = workflowObject.execute(executionProperties) | |
//wait for workflow completions | |
var complete = false; | |
while(complete == false){ | |
if(currentToken != null && (currentToken.state != "running" && currentToken.state != "waiting")){ | |
System.log("Workflow '"+currentToken.name+"' terminated with status '"+currentToken.state+"'"); | |
complete = true; | |
} | |
} | |
//get output from the workflow token | |
var outputPropertiesToken = currentToken.getOutputParameters() | |
System.log('outputPropertiesToken.keys: ' + outputPropertiesToken.keys) | |
System.log("outputPropertiesToken.get('stringOutput'): " + outputPropertiesToken.get('stringOutput')) | |
break; | |
} | |
} | |
for each(var workflowObject in workflows){ | |
if(workflowNameToInvoke == workflowObject.name){ | |
//execute workflow and get workflowToken | |
var currentToken = workflowObject.execute(executionProperties) | |
//wait for workflow completions | |
var complete = false; | |
while(complete == false){ | |
if(currentToken != null && (currentToken.state != "running" && currentToken.state != "waiting")){ | |
System.log("Workflow '"+currentToken.name+"' terminated with status '"+currentToken.state+"'"); | |
complete = true; | |
} | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment