VMware Cloud Community
ccowan8
Contributor
Contributor

VR:Site (and other objects) lookup by name (or MOID)

I'm a noobie to VRO, and am struggling with a few things.

I'm wondering what the easiest technique is to find a return a VR:Site instance given it's name?

In more general terms, I'm interested in techniques for REST API, so that if supplied a the object name or MOID, I would get a full blown object.    Example: give a VM name or id as a string, who to get back the VC:VirtualMachine objects.

Thanks in advance for any suggestions.

Reply
0 Kudos
7 Replies
ccowan8
Contributor
Contributor

So, I'm thinking a REST call to /vco/api/catalog is what I need to be looking at.    I realize there's an XML parser, but need to find some examples to emulate.  

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Hi,

Perhaps the easiest way to find a VR site given its name and using vRO scripting API is to iterate over the list of sites looking for a match. Something like the following should work:

var sites = VRPluginConfig.getSites();

for each (var site in sites) {

  if (site.name == "mysite") {

    // success; you've found the site you are looking for

    // ...

    System.log("Found my site: " + site);

  }

}

vRO offers REST API to search for any plug-in object by its type and ID - you need to perform a GET request at https://{vroserver}:8281/vco/api/catalog/{namespace}/{type}/{id}

where:

- {vroserver} is the hostname or IP address of vRO server

- {namespace} is the plug-in name

- {type} is the plug-in object type, eg. VRSite

- {id} is the plug-in object ID (note that this ID might not be exactly the same as the MOID)

There is no generic REST API to search for plug-in object by its name, but some plug-ins implement sort of a filter which, when some string is passed as a parameter to the generic REST API to return all objects of a given type (GET at https://{vroserver}:8281/vco/api/catalog/{namespace}/{type}) , will filter the result list and return only those objects matching the filter. But again, this depends on the plug-in implementation, and most plug-in do not implement this feature.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

To get all VR sites, try a GET request at https://{vroserver}:8281/vco/api/catalog/VR/Site

Which REST client do you plan to use to make REST API calls?

Reply
0 Kudos
ccowan8
Contributor
Contributor

Thanks Ilian, from your answer it sounds as if there is nothing with VRO, and that I will have to launch an external command?

What is your suggestion?   (I'm hoping the appliance has curl, but that may be overly optimistic.)

Reply
0 Kudos
ccowan8
Contributor
Contributor

Ok.   Reading posts about RestHost

But since you're implying there are options, what are the other choices?

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Yes, vRO appliance has curl.

Also, vRO has a HTTP-REST plug-in, which you can configure to call vRO REST API, in case you want to do something with the REST call response content; eg. you can write some vRO scripting code to parse the response and do something with it.

Reply
0 Kudos
ccowan8
Contributor
Contributor

Continuing my learning.  Is there a quick a dirty and way to determine my own Vcenter server name, so I can determine which of my VRSite objects is the local one? 

I've seen some suggestions about vm.sdkConnection.optionManager.queryOptions("VirtualCenter").shift().value;
I just want a simple introspection call that tells me what my home base is.  Does VR Plugin return a reference to the VM you are current running on?

Reply
0 Kudos