Orchestrator Workflow Action to Create or Update a Custom Property

by Simon Sparks · 15 February 2016

To use this function add it to the class library file named vRealizeAutomation.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vRealizeAutomation.ts

Function CustomPropertyGetValue

Description: Orchestrator Workflow Function to Create or Update a Custom Property in vRealize Automation v7.x

publicCustomPropertyUpdateValue(objVcVirtualMachine:VcVirtualMachine,strPropertyName:string,strPropertyValue:string):void{

letobjVcVirtualMachineConfigInfo:VcVirtualMachineConfigInfo=objVcVirtualMachine.config;

letarrvCACVirtualMachine:vCACVirtualMachine[]=Server.findAllForType("vCAC:VirtualMachine","VMUniqueID eq '"+objVcVirtualMachineConfigInfo.instanceUuid+"'")asvCACVirtualMachine[];

letobjvCACVirtualMachine:vCACVirtualMachine=arrvCACVirtualMachine[0];

letobjVCACEntity:VCACEntity=objvCACVirtualMachine.getEntity();

letobjvCACHost:vCACHost=Server.findForType("vCAC:VCACHost",objVCACEntity.hostId)asvCACHost;

letblnFound:boolean=false;

letobjProperties:Properties=newProperties();
objProperties.put("PropertyName",strPropertyName);
objProperties.put("PropertyValue",strPropertyValue);
objProperties.put("IsHidden",false);
objProperties.put("IsRuntime",false);
objProperties.put("IsEncrypted",false);

letobjPropertiesLinks:Properties=newProperties();
objPropertiesLinks.put("VirtualMachine",objVCACEntity);

letobjPropertiesHeaders:Properties=newProperties();

letarrVCACEntityVirtualMachineProperties:VCACEntity[]=objVCACEntity.getLink(objvCACHost,"VirtualMachineProperties");

for (leti:number=0;i<arrVCACEntityVirtualMachineProperties.length;i++){
letobjVCACEntityVirtualMachineProperties:VCACEntity=arrVCACEntityVirtualMachineProperties[i];

letstrPropertyNameLoop:string=objVCACEntityVirtualMachineProperties.getProperty("PropertyName");

if (strPropertyNameLoop===strPropertyName){
blnFound=true;

letobjEntityKey:any=objVCACEntityVirtualMachineProperties.entityKey;

letstrEntityKeyId:string=objEntityKey.get("Id");

vCACEntityManager.updateModelEntityBySerializedKey(objvCACHost.id,"ManagementModelEntities.svc","VirtualMachineProperties",strEntityKeyId,objProperties,objPropertiesLinks,objPropertiesHeaders);

break;
}
}

if (blnFound===false){
vCACEntityManager.createModelEntity(objvCACHost.id,"ManagementModelEntities.svc","VirtualMachineProperties",objProperties,objPropertiesLinks,objPropertiesHeaders);
}
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like