You can cut, paste, and edit the JavaScript examples to write scripts for CRUD vRealize Automation tasks.
For more information about scripting in vRealize Orchestrator, see Developing with VMware vRealize Orchestrator.
Create a vRealize Automation Model Entity
This example script performs the following actions:
Defines the model name and the entity set name.
Defines the properties of the host prefix.
Saves the host prefix entity.
Defines the properties of the provisioning group.
Defines the provisioning group as a link.
Saves the provisioning group entity, by linking it with the host name prefix.
Variable |
Type |
---|---|
host |
vCAC:VcacHost |
var modelName = 'ManagementModelEntities.svc'; var entitySetName = 'HostNamePrefixes'; var links = null; var headers = null; //Create properties for prefix entity var prefixInputProperties = { MachinePrefix:'test-prefix', NextMachineNo:1, MachineNumberLength:3 }; //Save the prefix var prefixEntity = vCACEntityManager .createModelEntity(host.id, modelName, entitySetName, prefixInputProperties, links, headers); entitySetName = 'ProvisioningGroups'; //Create properties for the provisioning group entity inputProperties = { GroupName:'TestGroupName', GroupDescription:'This group was generated with a vCO workflow', AdministratorEmail:'test@test.com', AdContainer:'AD', IsTestGroup:false, Flags:2, GroupType:1}; //Add a reference to the newly created prefix entity links = { HostNamePrefix:prefixEntity }; //Save the provisioning group var entity = vCACEntityManager.createModelEntity(host.id, modelName, entitySetName, inputProperties, links, headers);
Update a vRealize Automation Model Entity
This example script performs the following actions:
Gets the host ID from the provided entity.
Gets the model name from the provided entity.
Gets the entity set name from the provided entity.
Gets the entity ID from the provided entity.
Defines a set of properties that will be updated.
Starts the action responsible for updating the entity.
Variable |
Type |
---|---|
entity |
vCAC:Entity |
updatedDescription |
String |
var hostId = entity.hostId; var modelName = entity.modelName; var entitySetName = entity.entitySetName; var entityIdString = entity.keyString; var links = null; var headers = null; var updateProperties = new Properties(); updateProperties.put("UserNameDescription", updatedDescription); //Update the user description System.getModule("com.vmware.library.vcac") .updateVCACEntity(hostId, modelName, entitySetName, entityIdString, updateProperties, links, headers);
Read a vRealize Automation Model Entity
This example script performs the following actions:
Defines the model name and the entity set name.
Defines the blueprint ID with a property object.
Reads the entity.
Variable |
Type |
---|---|
host |
vCAC:VcacHost |
blueprintID |
String |
var modelName = 'ManagementModelEntities.svc'; var entitySetName = 'VirtualMachineTemplates'; var links = null; var headers = null; //Create properties for the prefix entity var blueprintId = { VirtualMachineTemplateID:blueprintId, }; //Read the blueprint var entity = vCACEntityManager .readModelEntity(host.id, modelName, entitySetName, blueprintId, headers);
Delete a vRealize Automation Model Entity
This example script performs the following actions:
Gets the host ID from the provided entity.
Gets the model name from the provided entity.
Gets the entity set name from the provided entity.
Gets the entity ID from the provided entity.
Starts the action responsible for deleting the entity.
Variable |
Type |
---|---|
entity |
vCAC:Entity |
var hostId = entity.hostId; var modelName = entity.modelName; var entitySetName = entity.entitySetName; var entityKeyString = entity.keyString; var headers = null; //Delete the entity System.getModule("com.vmware.library.vcac") .deleteVCACEntity(hostId, modelName, entitySetName, entityKeyString, headers);
Read a vRealize Automation Entity by Custom Filter
This example script performs the following actions:
Defines the model name and the entity set name.
Defines the properties by which the entities are filtered.
Reads a list of entities.
Variable |
Type |
---|---|
host |
vCAC:VcacHost |
templateName |
String |
var modelName = 'ManagementModelEntities.svc'; var entitySetName = 'VirtualMachineTemplates'; var headers = null; //Create properties for prefix entity var properties = { VirtualMachineTemplateName:templateName, }; //Read a list of entities var entities = vCACEntityManager .readModelEntitiesByCustomFilter(host.id, modelName, entitySetName, properties, headers);
Read a vRealize Automation Entity by System Query
This example script performs the following actions:
Defines the model name and the entity set name.
Defines the system queries by which the entities are filtered and selects the top ten results of all virtual machines, filtered by the machine state and component flag.
Reads a list of entities.
Variable |
Type |
---|---|
host |
vCAC:VcacHost |
var modelName = 'ManagementModelEntities.svc'; var entitySetName = 'VirtualMachines'; var filter = "VirtualMachineState eq 'Off' and IsComponent eq true"; var orderBy = 'VirtualMachineName asc'; var top = 10; { var skip = 0;, var headers = null; var select = null; var entities = vCACEntityManager readModelEntitiesBySystemQuery(host.id, modelName, entitySetName, filter, orderBy, select, top, skip, headers);