VMware Cloud Community
dgberrid
Enthusiast
Enthusiast

Get Virtual Machines From Deployment

In vRA 6.x I was able to find all of the child virtual machines in a multi machine blueprint by finding the parent virtual machine and looking at the parent's child virtual machines. Unfortunatley the link to the parent virtual machine for virtual machines that are components of a deployment appears to be null now in vRA 7.x. 

Is there any way for one virtual machine component in a deployment to find out what other virtual machines are in the deployment? I would expect there be some unifying entity (like a parent entity) tying the machines together. Also, if there is such an entity, when is it created? 

9 Replies
qc4vmware
Virtuoso
Virtuoso

Yeah you can do so pretty easily.  If your starting point is of type vCAC:VirtualMachine you'll need to get its catalog resource.  Once you have the catalog resource you just need to look up each parent reference until you get to the deployment.  Once you have the deployment you can get all of the resources that are a part of it.  I'll attach some actions that you'll likely need to tweak but you can probably piece together what you need.

QCgetvCACCAFECatalogResourceForvCACVm will get the catalog resource for a vCAC vm

QCgetvCACCAFECatalogResourceDeployment will retrieve the deployment.  It will loop through parent resources until it gets to the deployment

QCgetvCACCAFECatalogResourceById looks up a resource by its ID (previous action makes use of this)

QCgetvCACCAFECatalogResourceChildren Retrieves all the child resources for a given resource id.  If you pass in the deployment id it will return the children.

I like having things in smaller reusable chunks but you could easily do this all in one action or scriptable task.  Most of what you need is in the last action assuming you have the parent resource id already.

unhappyvra
Enthusiast
Enthusiast

Here is a code to get a list of VMs (actually, names of them, but you could easy convert it to results you need) associated with deployment. The key point - you need deployment ID as input:

var filter = new Array();

var vCACCAFEHost_host = vCACCAFEEntitiesFinder.getHost("vCAFE_HOST_ID_BLA_BLA");

var catalogClient = vCACCAFEHost_host.createCatalogClient();

var catalogConsumerResourceService = catalogClient.getCatalogConsumerResourceService();

filter[0] = vCACCAFEFilterParam.equal("parentResource", vCACCAFEFilterParam.string(Deployment_id)); //Came from Action Input

var query = vCACCAFEOdataQuery.query().addFilter(filter);

var resources = catalogConsumerResourceService.getResourcesList(new vCACCAFEPageOdataRequest(query));

var vm_list = new Array();

if (resources != null )

{

for (var i = 0; i < resources.length; i++ )

{

  vm_list[i] = resources[i].name + "\t" + resources[i].description;

}

return vm_list;

}

0 Kudos
dgberrid
Enthusiast
Enthusiast

Where does the deployment_id come from? I don't see it on any of the component VM properties. 

When I just run the query...

var query = vCACCAFEOdataQuery.query() // No filter applied!!

var resources = catalogConsumerResourceService.getResourcesList(new vCACCAFEPageOdataRequest(query));

I get a number of resources but not the one I'm looking for. Also, I should have prefaced with I'm using the old lifecycle state Machine Provisioned when I actually look for the deployment.

0 Kudos
unhappyvra
Enthusiast
Enthusiast

Well, this action is actually a part of my Day-2 action, so Deployment ID comes from vRA. If you open vRA Automation (vCAFE host) in vRO, you could see your deployment and it's ID (like 24ba1d5f-3c55-46f3-xxxx-ecd58258xxxx). Try to find your deployment ID first and make a query with it to see what you get.

And I forgot to notice, 7.x has a bug (feature??) - you need to update your vCAFE plugin to the latest version - VMware Knowledge Base

And the second thing - take a look here, vCAFE plugin limited by 100 objects in reply - vRA 7.2 - vRO 7.2 - loading all CAFE VMs with Server.findAllForType not working on bigger groups

0 Kudos
qc4vmware
Virtuoso
Virtuoso

Did you look at the 4 actions I posted... they will help you get everything you need.  The deployment is just a catalog resource with a type specific to a deployment and it will have children associated with it.  You pass its resourceId in as the filter.  If you use an action on the virtual machine pass that resources id into the action which will retrieve the deployment.

0 Kudos
unhappyvra
Enthusiast
Enthusiast

I took a look and found several better ways to handle Deployment/parents/childs situation, thank you so much! I can improve my code Smiley Happy

0 Kudos
dgberrid
Enthusiast
Enthusiast

I'm checking them out right now, unfortunately QCgetvCACCAFECatalogResourceForvCACVm is failing on the query...

items = vCACCAFEEntitiesFinder.findCatalogResources(cafeHost, query);  

It doesn't return anything for the vCACVm I am passing in as input (the one currently in the Machine Provisioned state). Oddly enough it does work if I pass in a VM that is already through the Machine Provisioned lifecycle state.

0 Kudos
qc4vmware
Virtuoso
Virtuoso

Sounds like you could have an inventory refresh issue or some other race condition.  I've found I sometimes need to loop or wait a minute or two then suddenly things will work.

0 Kudos
dgberrid
Enthusiast
Enthusiast

This post helped me get what I needed...

https://communities.vmware.com/thread/479357

0 Kudos