Hi all,
Im trying to get the VM Name (or vCAC:VM or VC:VM) from a Post Approval Event. However I'm not getting there.
What I did:
Whats Happening:
When you run the following code after the deployment you get the VCAC:VM as well as the Deployment, however during the PostApproval Phase the Deployment doesn't have a Child (e.g. the VM) and the code doesn't show the vCAC:VM at all as a Resource.
Additionally there is no difference in between the properties and context the different approvals provide. So even with the VM approval no name or reference to the VM.
The only way I have found so far is to loop all vCAC:VMs pull there Properties and search for the _rootRequestID. However that is a bit hard with some 1000+ VMs...so there must be a better way.
My approval workflow (attached)
LogAllProp packed here : logAllProps
Code:
requestID=payload.sourceInfo.externalInstanceId;
tenant=System.getContext().getParameter("__asd_tenantRef");
var vcacCafeHost = vCACCAFEHostManager.getDefaultHostForTenant(tenant , "true")
var client = vcacCafeHost.createCatalogClient();
var requestService = client.getCatalogConsumerRequestService();
var resources = requestService.getResourcesProvisionedByRequest(requestID, null).getContent();
for each (resource in resources){
System.log(resource.name)
}
All props and context the Approval provides:
(sourceInfo.externalInstanceId is the root Request ID)
[2018-11-15 11:28:07.562] [I] ## Context #####################################
[2018-11-15 11:28:07.564] [I] __asd_catalogRequestId (string): 3dddb191-c851-4b8e-ad76-cd8b1afd4af1
[2018-11-15 11:28:07.567] [I] __asd_correlationId (string): 15a11bd9-4986-4f30-890a-8ed19f004dfd
[2018-11-15 11:28:07.569] [I] __asd_requestInstanceId (string): 223e23b0-e8c1-11e8-4ab2-b56832208a21
[2018-11-15 11:28:07.571] [I] __asd_requestInstanceTimestamp (string): "2018-11-15T10:28:03.563Z"
[2018-11-15 11:28:07.574] [I] __asd_requestInstanceTypeId (string): approval-com.vmware.cafe.catalog.request.post
[2018-11-15 11:28:07.576] [I] __asd_requestTraceId (string): zBPpqOka
[2018-11-15 11:28:07.578] [I] __asd_requestedBy (string): approval-service
[2018-11-15 11:28:07.580] [I] __asd_requestedFor (string): approval-service
[2018-11-15 11:28:07.582] [I] __asd_targetResourceId (string): 2589ccfb-eecf-4ef9-86dc-16a5e651b47f
[2018-11-15 11:28:07.585] [I] __asd_targetResourceProviderId (string): 5f68559d-276b-4163-9844-cf8d0a27a1e6
[2018-11-15 11:28:07.587] [I] __asd_targetResourceProviderTypeId (string): com.vmware.csp.core.cafe.approvals
[2018-11-15 11:28:07.589] [I] __asd_targetResourceTypeId (string): ApprovalRequest
[2018-11-15 11:28:07.592] [I] __asd_tenantRef (string): acme
[2018-11-15 11:28:07.594] [I] ## Payload #####################################
[2018-11-15 11:28:07.597] [I] (properties) [3]
[2018-11-15 11:28:07.599] [I] /businessJustification (string): string
[2018-11-15 11:28:07.600] [I] /createDate (date): Thu Nov 15 2018 10:28:03 GMT-0000 (UTC)
[2018-11-15 11:28:07.602] [I] /fieldNames (properties) [1]
[2018-11-15 11:28:07.604] [I] /fieldNames/businessJustification (string): string
[2018-11-15 11:28:07.606] [I] /requestInfo (properties) [10]
[2018-11-15 11:28:07.608] [I] /requestInfo/approvalLevel (properties) [4]
[2018-11-15 11:28:07.610] [I] /requestInfo/approvalLevel/classId (string): ApprovalLevel
[2018-11-15 11:28:07.612] [I] /requestInfo/approvalLevel/id (string): 4a0a372e-ddfc-4cfc-9c07-10ccc86bfe81
[2018-11-15 11:28:07.614] [I] /requestInfo/approvalLevel/label (string): vraPostApproval
[2018-11-15 11:28:07.615] [I] /requestInfo/approvalLevel/type (string): entityReference
[2018-11-15 11:28:07.617] [I] /requestInfo/approvalLevelName (string): vraPostApproval
[2018-11-15 11:28:07.619] [I] /requestInfo/approvalRequestId (string): 2589ccfb-eecf-4ef9-86dc-16a5e651b47f
[2018-11-15 11:28:07.621] [I] /requestInfo/createDate (date): Thu Nov 15 2018 10:28:03 GMT-0000 (UTC)
[2018-11-15 11:28:07.623] [I] /requestInfo/itemDescription (string):
[2018-11-15 11:28:07.625] [I] /requestInfo/itemName (string): smallRHEL
[2018-11-15 11:28:07.626] [I] /requestInfo/requestRef (string): 47
[2018-11-15 11:28:07.628] [I] /requestInfo/requestedBy (string): acme_admin@vsphere.local
[2018-11-15 11:28:07.630] [I] /requestInfo/requestedFor (string): acme_admin@vsphere.local
[2018-11-15 11:28:07.632] [I] /requestInfo/subtenantId (string): 06890147-51f7-4857-98c7-e5b6ca2d9dcd
[2018-11-15 11:28:07.634] [I] /requestInfo/type (string): entityReference
[2018-11-15 11:28:07.636] [I] /serviceId (string): ea08b8e8-196f-4cd7-bff4-92c5f504aac8
[2018-11-15 11:28:07.637] [I] /sourceInfo (properties) [3]
[2018-11-15 11:28:07.639] [I] /sourceInfo/externalClassId (string): request
[2018-11-15 11:28:07.641] [I] /sourceInfo/externalInstanceId (string): 15a11bd9-4986-4f30-890a-8ed19f004dfd
[2018-11-15 11:28:07.643] [I] /sourceInfo/serviceId (string): ea08b8e8-196f-4cd7-bff4-92c5f504aac8
[2018-11-15 11:28:07.645] [I] #############################################
Cause I have been asked, here is the code to get a VCACVM from the rootRequestID using Post Approval Properties
Inputs:
Output:
var notFound=true;
rootRequestID=payload.sourceInfo.externalInstanceId;
vcacvms=Server.findAllForType("vCAC:VirtualMachine", "IsManaged eq true");
for each (vcacvm in vcacvms){
vmProps=System.getModule("de.vleet.vra.tools").getPropertiesFromVCACVM(vcacvm);
if (rootRequestID==vmProps.get("__Cafe.Root.Request.Id")){
notFound=false;
break;
}
}
if (notFound){
vcacvm=null;
}