Retrieve vCenter as an SdkConnection from vCloud Director in vRealize Orchestrator
| 2 minutes
VMware vCloud Director vRealize Orchestrator Javascript How-To vRealize Suite

I’ve been working on some more automation lately for vCloud Director using vRealize Orchestrator. One of my use cases was to retrieve the SDK Connection scripting object for the linked vCenter Server. My starting point was an Org vDC, and from there I wanted to get the backing vCenter Server.

Let’s start by getting the Provider vDC vCloud Reference object from the Org vDC scripting object (orgVDC):

var providerRef = orgVDC.toAdminObject().providerVdcReference;

The providerRef variable will now contain a VclReference that we can use query vCloud for the actual VclProviderVdc scripting object:

var providerVdc = orgVDC.getHost().getEntityByReference(VclFinderType.PROVIDER_VDC, providerRef);

Cool, now the providerVdc variable contains the VclProviderVdc scripting object.

Let’s now get the VclObject and enumerate it. You’ll also see the ‘[0]’ at the end of the enumerate() method which grabs the first entry in the enumerated array (this is called the array index). I only bother grabbing the first one as my environment only has one vCenter Server linked to vCloud.

var vCenterServer = providerVdc.toAdminExtensionObject().vimServer.enumerate()[0];

The returned object will be another VclReference that we need to again do a lookup for:

var obj = orgVDC.getHost().getEntityByReference(VclFinderType.VIM_SERVER, vCenterServer);

Nice, our obj var now holds the VclVimServer scripting object. But that’s not enough, we need the SdkConnection. Let’s grab the UUID of the vCenter Server from the VclVimServer object:

var vcUuid = obj.uuid;

Finally, let’s use VcPlugin to get the SdkConnection object from a UUID:

var vCenter = VcPlugin.findSdkConnectionForUUID(vcUuid);

Done! Our vCenter variable now contains the VC:SdkConnection scripting object.

Altogther for those that want the code in block:

var providerRef = orgVDC.toAdminObject().providerVdcReference;
var providerVdc = orgVDC.getHost().getEntityByReference(VclFinderType.PROVIDER_VDC, providerRef);
var vCenterServer = providerVdc.toAdminExtensionObject().vimServer.enumerate()[0];
var obj = orgVDC.getHost().getEntityByReference(VclFinderType.VIM_SERVER, vCenterServer);
var vcUuid = obj.uuid;
var vCenter = VcPlugin.findSdkConnectionForUUID(vcUuid);
About Stellios Williams
Senior Cloud Solutions Architect - Service Providers VMware
This is my personal tech related blog for anything private and public cloud - including homelabs! My postings are my own and don’t necessarily represent VMware’s positions, strategies or opinions. Any technical guidance or advice is given without warranty or consideration for your unique issues or circumstances.
Comments
comments powered by Disqus
Advertisement