Task:
In vRO, we need the Deployment's Request ID and the Deployment to Retrieve the Deployments VMs.
In other words, from one of the VMs w/in a deployment, get all the VMs in Deployment.
Steps:
1. Get the vCACCAFECatalogResource for the current vCACVM:
Input: vCACHost (type: vCACCAFE:VCACHost)
Input: vCACVM (type: vCAC:VirtualMachine)
Output: vmResource (type: vCACCAFE:CatalogResource)
if (!vCACHost) {
System.warn('No vCACHost passed. Returning null.');
return null;
}
if (!vCACVM) {
System.warn('No vCACVM passed. Returning null.');
return null;
}
// get the resource
var catResource = null;
var query = vCACM.virtualMachineName;
var catResources = new Array();
catResources = vCACCAFEEntitiesFinder.findCatalogResources(vCACHost, query);
for each (var catResource in catResources) {
var crBindingId = catResource.getProviderBinding().getBindingId();
if (vCACVM.virtualMachineID === crBindingId) {
// match
return catResource;
} else {
// System.warn('No Catalog Resource found for VM, ' + query + ', returning null.');
return catResource;
}
}
2. With the VM's catalog resource object, get the parent deployment resource:
Input: vCACHost (type: vCACCAFE:VCACHost)
Input: vmResource (type: vCACCAFE:CatalogResource)
Output: depResource (type: vCACCAFE:CatalogResource)
if (!vmResource) {
System.warn('Missing required input VM resource. Returning null');
return null;
}
if (vmResource.resourceTypeRef.getId() === "composition.resource.type.deployment") {
System.warn('Submitted resource ' + vmResource.getName() + " not a VM, but a deployment Returning null.');
return null;
}
var curResource = vmResource;
var parentRef = curResource.parentResourceRef;
var deployment = null;
var catClientSvc = vCACHost.createCatalogClient().getCatalogConsumerResourceService();
while (parentRef && curResource.resourceTypeRef.getId() != "composition.resource.type.deployment") {
var parent = catClientSvc.getResource(parentRef.getId());
if (parent) {
if (parent.resourceTypeRef.getId() === "composition.resource.type.deployment") {
System.debug('Found deployment ' + parent.getName() + ', ID: ' + parent.getId() );
deployment = parent;
break;
} else {
// check next parent up the chain and loop
curResource = parent;
parentRef = curResource.parentResourceRef;
}
}
}
return deployment;
3. Using the deployment catalog resource object, get properties of the deployment:
Input: deploymentResource (type: vCACCAFE:CatalogResource)
Output: depReqObj (type: Object)
if (!deploymentResource ) {
System.warn('Missing required input deployment resource. Returning null');
return null;
}
if (!deploymentResource.resourceTypeRef.getLabel() === 'Deployment' ) {
System.warn('Resource option is not a deployment. Returning null');
return null;
}
var depReqObj = new Object;
depReqObj.requestId = deploymentResource.getRequestId();
depReqObj.depName = deploymentResource.getName();
depReqObj.description = deploymentResource.getDescription();
depReqObj.depName = deploymentResource.getName();
return depReqObj;
4. Get all the Child VMs of the Deployment (which will include the VM starting it all):
Input: vCACHost (type: vCACCAFE:VCACHost)
Input: depId (type:string, the deployment requestId, from part 3 above)
Output: vmResources (Array/vCACCAFE:CatalogResource)
if (!depId ) {
System.warn("No catalog resource ID passed. Returning null.");
return null;
}
// build query data request object
var vmResources = new Array();
var filter = new Array();
filter[0] = vCACCAFEFilterParam.equal("parentResource", vCACCAFEFilterParam.string(depId) );
var query = vCACCAFEOdataQuery.query().addFilter(filter);
var odataRequest = new vCACCAFEPageOdataRequest(1, 10000, query);
var catClientSvc = vCACHost.createCatalogClient().getCatalogConsumerResourceService();
var resources = catClientSvc.getResourcesList(odataRequest);
if (resources) {
for each (var resource in resources) {
System.debug("resourceTypeRef Label: " + resource.resourceTypeRef.getLabel());
System.debug("resourceTypeRef Id: " + resource.resourceTypeRef.getId());
if ( resource.resourceTypeRef.getLabel() === 'VirtualMachine' ) {
// add VM to list
vmResources.push(resource);
}
}
}
return resources;
previous page
|