VMware Cloud Community
NigelHarris
Contributor
Contributor
Jump to solution

How to obtain the vCenter moref for a VM

I am using orchestrator with the vCloud plugin.  I'd like to understand how I can access the moref identifier for a virtual machine (as vcenter sees it) that is contained within a vCloud vApp.

thanks,

Reply
0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Here is an action I wrote to do it. It is using the query service.

Note that to be able to do so you need your vCD plug-in to be connected to the system org and use admin credentials.

var vcdHost = vm.getHost();
var vApp = vm.parent;

var vms = new Array();
var queryService = vcdHost.getQueryService();

expression = new VclExpression(VclQueryAdminVMField.CONTAINER, vApp.getReference().href, VclExpressionType.EQUALS);
filter = new VclFilter(expression);
params = new VclQueryParams();
params.setFilter(filter);



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) {
        if (record.name == vm.name) {
            return record.moref;
            }

    }
    resultSet = resultSet.getNextPage();
}
return null;

Christophe.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

Reply
0 Kudos
2 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Here is an action I wrote to do it. It is using the query service.

Note that to be able to do so you need your vCD plug-in to be connected to the system org and use admin credentials.

var vcdHost = vm.getHost();
var vApp = vm.parent;

var vms = new Array();
var queryService = vcdHost.getQueryService();

expression = new VclExpression(VclQueryAdminVMField.CONTAINER, vApp.getReference().href, VclExpressionType.EQUALS);
filter = new VclFilter(expression);
params = new VclQueryParams();
params.setFilter(filter);



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) {
        if (record.name == vm.name) {
            return record.moref;
            }

    }
    resultSet = resultSet.getNextPage();
}
return null;

Christophe.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
NigelHarris
Contributor
Contributor
Jump to solution

Thanks Christophe !

Reply
0 Kudos