While working with VCO and NSX I find that I frequently need the MoRef (Managed Object Reference) of the Datacenter object in vCenter. Depending on your design you may have multiple datacenters. This workflow will accept the name of the datacenter as the input and will output the moref. You will need the vCenter plugin installed for this to function.
Create a new workflow and edit it.
Add and input parameter called strDatacenter.
Create an output parameter called datacenterMoref.
Add a Scriptable task on the Schema tab.
Bind the input parameter.
Bind the output parameter.
Modify the code in the scripting object. This code will call the VC plugin and query for all datacenter objects. It will check for a match of the input parameter and grab the moref.
// Get all datacenter objects var datacenters = VcPlugin.getAllDatacenters(); // While loop setup, length and increment counter var length = datacenters.length; var i = 0; // Loop through the datacenter objects, find matching datacenter, extract moref while (i < length){ if (datacenters[i].name == strDatacenter) { datacenterMoref = datacenters[i].id } i++; } // Log the moref System.log(datacenterMoref);
Save the workflow and test.
If successful, you should see the moref id in the logs. You can now use this in other workflows.