VMware Cloud Community
wllp
Enthusiast
Enthusiast

vRA/vRO 7 - Get the custom properties values

I am trying to update the VM hostname and created a few property definition and added them into the property group.

Within the property group, I have created:

  • Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.BuildingMachine
  • Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Request

Both have the values __*,*

The property group is added to the blueprint and I have also created the new Event Subscriptions with the following setup:

  • Select "Machine Provisioning" topic
  • Added the following conditions
      • Data > Lifecycle state name EQUALS VMPSMasterWorkflow32.BuildingMachine
      • Data > Lifecycle state phase EQUALS PRE
      • Data > Machine > Machine Type EQUALS Virtual Machine

In the vRO workflow scripting, I am passing the "Payload" as Properties into the workflow

I am able to retrieve the machine ID

var machine = payload.get("machine");

machineId = machine.get("Id"); // Value is returned

var machineProperties = machine.get('properties'); // Getting NULL when retrieving the properties

The machineProperties is returning NULL and I am not able to proceed further to retrieve the property definition that I have specified.

Am I missing anything? Please help! Thanks.

5 Replies
vMarkusK1985
Expert
Expert

In vRO / vRA 6.2.x I do it this way.

Log all properties:

//Displaying vCAC VM properties

if (vCACVmProperties != null) {

  var log = "";

  log += "vCAC VM properties :\n";

  var array = new Array();

  for each (var key in vCACVmProperties.keys) {

  array.push(key + " : " + vCACVmProperties.get(key));

  }

  array.sort();

  for each (var line in array) {

  log += "\t" + line + "\n";

  }

  System.log(log);

}

Get something explicit:

var Network0_IP = vCACVmProperties.get("VirtualMachine.Network0.Address");

Kind Regards,

Markus

https://mycloudrevolution.com | https://twitter.com/vMarkus_K | https://github.com/vMarkusK
0 Kudos
rwk1982
Enthusiast
Enthusiast

In vRA 7.2/vRO 7.2 I use "vRA_VmProperties = payload.get("machine").get("properties")"

Drink coffee.. Do stupid things faster with more energy...
Windspirit
Hot Shot
Hot Shot

I created a little package that helps in this case.

See

http://langenhan.info/software/logallprops.html

0 Kudos
DanieleUlrich
Enthusiast
Enthusiast

At the first glance you're doing everthing correct according to the docs: https://docs.vmware.com/en/vRealize-Automation/7.3/vrealize-automation-73-extensibility.pdf  (p. 22)

What I would change is the way your accessing the payload. You could use 

var pl = JSON.parse(payload);

if (!!pl.machine.properties) {

  //do something with the props

   pl.machine.properties.get("propName").....


or properties['propName'] but the thing that you have to check first, if you really get properties. Just put a System.log(JSON.stringify(payload)); and check the contents.

If you don't get at least properties that start with '__' you have a problem on how you apply your property group in the blueprint.

0 Kudos
jonoped
Contributor
Contributor

wllp​   try using this in the scripting section..

var vmProperties = machine.get("properties");

for each (var key in vmProperties.keys) {

System.log("Key: "+key+" Value: "+vmProperties.get(key));

}

That should give you all of the variables. Then you can set things like this..

System.log(vmProperties.get("VirtualMachine.Network0.Address"));

This will give you Nic 0 IP for example...

I found the "vmProperties" scripting above on this website : https://thevirtualist.org/vra-event-broker-pass-basic-custom-properties-vro/

Hope this is of help to you or someone else

Jono