For the life of me I cannot figure out how to set the virtual machine description from vro.
I'm passing in the VCAC:VirtualMachine and doing a getEntity() on the object to get the entity.
Then I output the properties and see: Notes=Provisioned by VMware vCAC
Then I pass the virtualmachine entity to "Create / update property on virtualMachine Entity" with property name "Notes".
The flow says that it's added a property Notes on the first run. On the second it says it has updated the property.
When lookign at the properties on entity.getProperties() Notes is still listed as the old value and there are no new properties.
What am I doing wrong here?
Thanks!
This probably does what you need... From your VC:virtualMachine.... get the associated vcacVm (let me know if you don't know how to do this)
var entity = vcacvm.getEntity();
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("Notes", description);
System.log("Setting description for " +vcacvm.virtualMachineName +" to '" +description +"'.");
System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId, modelName, entitySetName, entityIdString, updateProperties, links, headers);
After looking further it seems my method is updating Custom Properties.
How do I update properties on the entity itself?
-Justin
For VC:VirtualMachine, it can be done with the following scripting code (vm is VC:VirtualMachine object, desc is a string with the new description)
// this code sets the 'Description' custom attribute
vm.setCustomValue("Description", desc);
// and this code sets the 'Notes' property
var spec = new VcVirtualMachineConfigSpec();
spec.annotation = desc;
vm.reconfigVM_Task(spec);
I'm not familiar with vCAC plug-in, but if you have VCAC:VirtualMachine object, you should be able to read virtual machine ID from it, then fetch the corresponding VC:VirtualMachine object, and proceed with the code above, using something like:
var vms = VcPlugin.getManagedObjectsForIds("VirtualMachine", ["10.23.117.25/vm-6113"]); // '10.23.117.25' is VC address, 'vm-6113' is VM ID
if (vms == null || vms.length == 0) {
System.log("VM not found");
} else {
var vm = vms[0];
// ... proceed with code in the first snippet
}
Thanks. Do these sync back into VRA?
The annotation script works but doesn't sync when inventory is updated.
The other:
Throws an error:
[2015-08-19 14:55:07.750] [I] A specified parameter was not correct.
key (Workflow:setVCDescription / Set Attributes (item2)#1)
In this case desc is a string that contains the new description.
ideas?
This probably does what you need... From your VC:virtualMachine.... get the associated vcacVm (let me know if you don't know how to do this)
var entity = vcacvm.getEntity();
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("Notes", description);
System.log("Setting description for " +vcacvm.virtualMachineName +" to '" +description +"'.");
System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId, modelName, entitySetName, entityIdString, updateProperties, links, headers);
This works nicely. Thanks!!