VMware Cloud Community
babarton
Contributor
Contributor
Jump to solution

Blocking Task on vApp delete: Getting VM information

I have a workflow that performs some cleanup on external systems when a vApp is deleted.  However in order to do this I need to get the VM's that are contained in that vApp.  I've noticed that when a vApp is blocked on delete (pending) that I am unable to get this information.  Anyone figured out a way around this?

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Sorry about that Brent, I thought that I had updated the Notifications package to include additional work and examples that we have completed for other blocking tasks such as this one...

Okay, if you are using the Workflow Runner as coded in the original notifications package, then you should be getting a limited vApp object (limited due to the object locking while the task is blocked.) WIth that vApp and a QueryService call we can get some info about the vms inside the vApp. In the current release of vCloud Director (1.5.1), the amount of info we can get is limited, but here is the code I have used:

The only input required to the following script is the "vCloud:vApp" object you receive from the blocking task. This script will simply try to System.log the values to your workflow execution Logs tab.

var queryService = vcdHost.getQueryService();
expression = new VclExpression(VclQueryVMField.CONTAINER, vApp.getReference().href, VclExpressionType.EQUALS);
filter = new VclFilter(expression);
params = new VclQueryParams();
params.setFilter(filter);
System.log("============== Display VM Info =============");
var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVM, params);
while (resultSet != null) {
    var records = resultSet.getRecords(new VclQueryResultAdminVMRecord());
    System.log(records.length + " VM records found");   
    for each (var record in records) {
      System.log("Processing VM: "+record.name);
      System.log("name",record.name);
      System.log("moref",record.moref);
      System.log("guestOs",record.guestOs);
      System.log("href",record.href);
      System.log("datastore",record.datastoreName);
      System.log("memoryMB",record.memoryMB);
      System.log("numberOfCpus",record.numberOfCpus);
      System.log("-----------------------------------\n\n");
   }
    resultSet = resultSet.getNextPage();
}

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

Reply
0 Kudos
4 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

Have you tried working with the notifications package we placed on the Documents tab of this community. If I remember correctly, one of the included workflows for approvals was for deletions -- and it includes the vm Name for each vm in the vApp that is to be deleted.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
babarton
Contributor
Contributor
Jump to solution

Burke,

Thank you for your response.  I downloaded and imported the notification package this AM.  I've gone through the workflow, but I am unable to locate any information pertaining to deletes.  It appears that this is focused primarily on approvals of vapp provisioning.  Here is a little additional information.  I am using "workflow runner" to get the information from the AMQP message.  If I execute the workflow and choose the vapp, it works without issue.  However if I use a blocking task on vapp deletion, then the array that I use to get the VM's from the vApp is empty.  It did get the information on one run, but I am chalking that up as a timing issue.

Any additional insight would be appreciated....

Thanks,

Brent

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Sorry about that Brent, I thought that I had updated the Notifications package to include additional work and examples that we have completed for other blocking tasks such as this one...

Okay, if you are using the Workflow Runner as coded in the original notifications package, then you should be getting a limited vApp object (limited due to the object locking while the task is blocked.) WIth that vApp and a QueryService call we can get some info about the vms inside the vApp. In the current release of vCloud Director (1.5.1), the amount of info we can get is limited, but here is the code I have used:

The only input required to the following script is the "vCloud:vApp" object you receive from the blocking task. This script will simply try to System.log the values to your workflow execution Logs tab.

var queryService = vcdHost.getQueryService();
expression = new VclExpression(VclQueryVMField.CONTAINER, vApp.getReference().href, VclExpressionType.EQUALS);
filter = new VclFilter(expression);
params = new VclQueryParams();
params.setFilter(filter);
System.log("============== Display VM Info =============");
var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVM, params);
while (resultSet != null) {
    var records = resultSet.getRecords(new VclQueryResultAdminVMRecord());
    System.log(records.length + " VM records found");   
    for each (var record in records) {
      System.log("Processing VM: "+record.name);
      System.log("name",record.name);
      System.log("moref",record.moref);
      System.log("guestOs",record.guestOs);
      System.log("href",record.href);
      System.log("datastore",record.datastoreName);
      System.log("memoryMB",record.memoryMB);
      System.log("numberOfCpus",record.numberOfCpus);
      System.log("-----------------------------------\n\n");
   }
    resultSet = resultSet.getNextPage();
}

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
babarton
Contributor
Contributor
Jump to solution

Thanks Burke, your script did the trick, and my workflow is functioning properly on the blocking task!

Brent

Reply
0 Kudos