Hi.
In vRA7 I used to update the VM hostname by creating an output of virtualMachineAddOrUpdateProperties in vRO and updating the property value as follows:
if (value != null && value.length > 0) {
System.debug("Update properties " + key + "=" + value);
props.put(key,value);
} else {
System.error("Error updating properties " + key + " +=empty value");
}
}
virtualMachineAddOrUpdateProperties = payload.virtualMachineAddOrUpdateProperties || new Properties();
updateprops(virtualMachineAddOrUpdateProperties, "Hostname", "newname");
updateprops(virtualMachineAddOrUpdateProperties, "VirtualMachine.Admin.Name", "newname");
I am trying to replicate this in vRA8 (cloud assembly) via vRO and hitting problems and was wondering if anyone had managed it yet??
resourceNames = inputProperties || new Properties();
delete resourceNames['resourceNames'][0]
resourceNames['resourceNames'].push("newMachineName")
This workflow triggers at the "Compute.allocation.pre" phase and completes successfully.
However, within cloud assembly I get the following error:
"Extensibility triggered task failure: Expected BEGIN_ARRAY but was STRING at line 1 column 279 path $.resourceNames"
Within the workflow I printed inputProperties at the start of the workflow and resourceNames at the end and I can see the resourceNames field has been updated as expected...
InputProperties
2020-01-22 15:35:08.000 +00:00infoBegin logging properties
2020-01-22 15:35:08.000 +00:00infoblueprintId :: string :: 6c549b32-e76f-4455-a894-809361178892
2020-01-22 15:35:08.000 +00:00infocomponentId :: string :: demo-machine
2020-01-22 15:35:08.000 +00:00infocomponentTypeId :: string :: Cloud.vSphere.Machine
2020-01-22 15:35:08.000 +00:00infocustomProperties :: Properties :: HashMap:384042417
2020-01-22 15:35:08.000 +00:00info- count :: string :: 1
2020-01-22 15:35:08.000 +00:00info- customizationSpec :: string :: Linux_Custom_Spec
2020-01-22 15:35:08.000 +00:00info- image :: string :: ubuntu
2020-01-22 15:35:08.000 +00:00info- resourceGroupName :: string :: VRM/DEV PROJECT
2020-01-22 15:35:08.000 +00:00info- sdlc :: string :: test
2020-01-22 15:35:08.000 +00:00infodeploymentId :: string :: 31ee7ea5-f690-4b9e-be24-b1531e7ac470
2020-01-22 15:35:08.000 +00:00infoendpointId :: string :: 91d7ed61ef9b327559c975bd9fa02
2020-01-22 15:35:08.000 +00:00infoexternalIds :: Array :: 0d4a9418-9acd-42b6-a39b-70fe7b7c6c51
2020-01-22 15:35:08.000 +00:00infohostSelectionIds :: Array :: 91d7ed61ef9b327559c975cfecaf0
2020-01-22 15:35:08.000 +00:00infoprojectId :: string :: 5c4b2ce9-7838-485b-b03d-8ae7002cdc15
2020-01-22 15:35:09.000 +00:00inforequestId :: string :: a27b2b03-72bf-4443-8230-da8b46a50eb8
2020-01-22 15:35:09.000 +00:00inforesourceIds :: Array :: f4cc3f33eaa2947559cbc43ce2f60
2020-01-22 15:35:09.000 +00:00inforesourceNames :: Array :: demo-machine-mcm626-128100897615
2020-01-22 15:35:09.000 +00:00infotags :: Properties :: HashMap:666784176
2020-01-22 15:35:09.000 +00:00info- Backup :: string :: Gold
2020-01-22 15:35:09.000 +00:00infoEnd Logging Properties
resourceNames
2020-01-22 15:35:09.000 +00:00infoblueprintId :: string :: 6c549b32-e76f-4455-a894-809361178892
2020-01-22 15:35:09.000 +00:00infocomponentId :: string :: demo-machine
2020-01-22 15:35:09.000 +00:00infocomponentTypeId :: string :: Cloud.vSphere.Machine
2020-01-22 15:35:09.000 +00:00infocustomProperties :: Properties :: HashMap:384042417
2020-01-22 15:35:09.000 +00:00info- count :: string :: 1
2020-01-22 15:35:09.000 +00:00info- customizationSpec :: string :: Linux_Custom_Spec
2020-01-22 15:35:09.000 +00:00info- image :: string :: ubuntu
2020-01-22 15:35:10.000 +00:00info- resourceGroupName :: string :: VRM/DEV PROJECT
2020-01-22 15:35:10.000 +00:00info- sdlc :: string :: test
2020-01-22 15:35:10.000 +00:00infodeploymentId :: string :: 31ee7ea5-f690-4b9e-be24-b1531e7ac470
2020-01-22 15:35:10.000 +00:00infoendpointId :: string :: 91d7ed61ef9b327559c975bd9fa02
2020-01-22 15:35:10.000 +00:00infoexternalIds :: Array :: 0d4a9418-9acd-42b6-a39b-70fe7b7c6c51
2020-01-22 15:35:10.000 +00:00infohostSelectionIds :: Array :: 91d7ed61ef9b327559c975cfecaf0
2020-01-22 15:35:10.000 +00:00infoprojectId :: string :: 5c4b2ce9-7838-485b-b03d-8ae7002cdc15
2020-01-22 15:35:10.000 +00:00inforequestId :: string :: a27b2b03-72bf-4443-8230-da8b46a50eb8
2020-01-22 15:35:10.000 +00:00inforesourceIds :: Array :: f4cc3f33eaa2947559cbc43ce2f60
2020-01-22 15:35:10.000 +00:00inforesourceNames :: Array :: newMachineName
2020-01-22 15:35:10.000 +00:00infotags :: Properties :: HashMap:666784176
2020-01-22 15:35:10.000 +00:00info- Backup :: string :: Gold
2020-01-22 15:35:10.000 +00:00info__item_stack:/item0
There's a good chance i'm doing something stupid but I can't see it!!!
Make sure your workflow has an output variable called resourceNames of type Array/string.
Then in your scriptable task:
var resourceNames = inputProperties.resourceNames;
resourceNames[0] = 'newName';
Obviously this is a super simplistic example, remembering that this workflow will run once per compute stack on the blueprint. So if your count setting for the stack is greater than 1 you'll need to generate X number of names.
You can also do it with ABX if you don't have a specific need to use vRO. Projects also offer a naming template function though it is more limited and specific to each instance of vRA and each project.
Make sure your workflow has an output variable called resourceNames of type Array/string.
Then in your scriptable task:
var resourceNames = inputProperties.resourceNames;
resourceNames[0] = 'newName';
Obviously this is a super simplistic example, remembering that this workflow will run once per compute stack on the blueprint. So if your count setting for the stack is greater than 1 you'll need to generate X number of names.
You can also do it with ABX if you don't have a specific need to use vRO. Projects also offer a naming template function though it is more limited and specific to each instance of vRA and each project.
Ahh I knew it would be something simple. I had resourceNames set as 'Properties' and not String/Array.
Changing the type worked perfectly.
Thanks for your help
Great question (I'm coming from vRA 7.6 too) and a great answer which has helped me progress.
I'm doing a few basic tests in vRA 8 and have a follow up question which I hope you can help with.
I'm able to change the resourceNames property with testVM using the method you provided. Tested by amending the workflow script and running again against a previously failed run where inputProperties payload already existed.
var newName = "test-vRA8-VM"
var resourceNames = inputProperties.resourceNames;
System.log("resourceNames 0 " + resourceNames[0])
resourceNames[0] = newName;
System.log("resourceNames Now " + resourceNames[0])
var machineName = inputProperties.get("resourceNames");
var machineID = inputProperties.get("resourceIds");
System.log("Machine Name: " + machineName)
2020-02-04 10:55:51.000 +00:00INFOresourceNames 0 Cloud_vSphere_Machine_1-mcm244-129206615225
2020-02-04 10:55:51.000 +00:00INFOresourceNames Now eugbd-wapp1999
2020-02-04 10:55:51.000 +00:00INFOMachine Name: test-vRA8-VM
2020-02-04 10:55:51.000 +00:00INFOMachine ID: 84a784cbea6250bf
2020-02-04 10:55:51.000 +00:00INFO__item_stack:/item0
Its the event subscription that I'm having trouble with. I've subscribed to the Computer Provision event topic.
The event triggers successfully and the correct resource name is captured but the VM in vCentre is still created with default naming;
Any help appreciated.
Change the subscription to the 'Compute Allocation' phase and the VM in vCenter will be created with the correct name
Thanks for the quick reply. Was full of hope after that but unfortunately I've had the same outcome;
Compute allocation subscription;
Successfully run with correct resourceNames value;
Default naming used for VM in vVcentre;
I believe blocking is required on the subscription to update property values
YES grumpyengineer, that was it, of course!
Thanks for your help!!
You can do this with an ABX ? If I have a naming convention for the whole organization and not per project, can I trigger this ABX for every compute allocation ? I have tried many times with an ABX but it seems to scope only by projects and not all the organization.
Another question about inputs/outputs in vRO. Why you must specify only the resourcesName and not the whole "inputProperties" as Property type ? If I want to change multiple variables ?
For example :
var customProperties = inputProperties;
customProperties.resourcesName[0] = "newName";
# set other properties here
# set customProperties as output
Hello,
How can I achieve Custom properties in vRA8.X . Nothing but replacement for virtualMachineAddOrUpdateProperties .
As of now I am using vRO(7.5) workflow to update properties of VM using payload. Code shared below.
virtualMachineAddOrUpdateProperties = new Properties ();
virtualMachineAddOrUpdateProperties.put('Name', hostname);
virtualMachineAddOrUpdateProperties.put('VirtualMachine.Network0.MacAddressType', 'static');
virtualMachineAddOrUpdateProperties.put('VirtualMachine.Network0.MacAddress', mac);
virtualMachineAddOrUpdateProperties.put('VirtualMachine.Network0.Name', "VLAN"+vlan);