VMware Cloud Community
TimDScott
Enthusiast
Enthusiast
Jump to solution

Filtering for AWS machines with getResourcesListWithData

This code is being used in an action to get Virtual Machines contained within a business group:

const resourceService = vcacCafeHost.createCatalogClient().getCatalogConsumerResourceService();

const conditions = [];

conditions.push(vCACCAFEFilterParam.equal("resourceType/id", vCACCAFEFilterParam.string("Infrastructure.Virtual")));

conditions.push(vCACCAFEFilterParam.equal("organization/subTenant/name", vCACCAFEFilterParam.string(subtenantName)));

const filters = [];

filters.push(vCACCAFEFilterParam.group([vCACCAFEFilterParam.and(conditions)]));

const query = vCACCAFEOdataQuery.query().addFilter(filters).addAscOrderBy(["name"]);

var oDataRequest = new vCACCAFEPageOdataRequest(1, PAGE_LIMIT, query).first();

var resources = [];

do {

     var resourcesList = resourceService.getResourcesListWithData(false, false, oDataRequest);

     resources = resources.concat(resourcesList);

     System.debug("Found Resources: " + resourcesList.length);

     oDataRequest = oDataRequest.next();

} while (resourcesList.length > 0);

I need another version that will get specifically AWS machines. I am aware that I can change the resourceType/id filter to "Infrastructure.Cloud", but that will give me Azure etc. as well. I'm guessing there may be another filter I can supply to do this, but can't find any documentation?

Reply
0 Kudos
1 Solution

Accepted Solutions
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Are Azure machines actually registered as Infrastructure.Cloud and not an XaaS type? I have never used the native Azure functionality of vRA 7 (a more integrated XaaS implementation), only custom objects.

Taking a quick look you could filter on iconId with a value of Infrastructure.CatalogItem.Machine.Cloud.AmazonEC2.

View solution in original post

Reply
0 Kudos
6 Replies
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Are Azure machines actually registered as Infrastructure.Cloud and not an XaaS type? I have never used the native Azure functionality of vRA 7 (a more integrated XaaS implementation), only custom objects.

Taking a quick look you could filter on iconId with a value of Infrastructure.CatalogItem.Machine.Cloud.AmazonEC2.

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

Thanks again Steve, will check that out. Please can you let me know how you found that out, is it documented somewhere?

Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot
Jump to solution

I just grabbed an EC2 machine and looked at its properties. It looked to be the easiest individual piece of information to distinguish EC2 from others.

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

stevedrummond​ right, I wasn't aware of what you can actually filter on, seems like pretty much anything!

One other question, now I have my list of vm "resources", in the case of VMware vms, am I able to derive a machines instanceId? I know I can do a lookup by name to get the actual VC:VirtualMachine object, but I'm worried about duplicate names over different vCenters. This also applies to AWS instances / volumes. Thanks!

Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Yes you can get the unique identifier.

On your vCACCAFE:CatalogResource object you can use the method getResourceData(). This is a LiteralMap that contains the key EXTERNAL_REFERENCE_ID; for a vSphere machine this is the MoRef (Managed Object Reference) and for EC2 it is the instance ID. If you need the VM UUID you can get it from the vCAC:Entity object.

For the attached disks you can try to look for VirtualMachine.Disk<X>.ExternalReferenceId; I know vSphere disks have this property but I'm not sure about AWS Volumes as we don't use the OOTB AWS Disks (not fit for purpose). If the data isn't there you can always use the AWS plugin to get the volumes attached to the instance.

If you're doing all of this with EBS during provisioning it's even easier as all the details are given to you in the payload.

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

Now understand the Literal Map, in the case of vmware vms there's a VirtualMachine.Admin.UUID key that contains the InstanceId.

Thanks again for the help Steve!

Reply
0 Kudos