VMware Cloud Community
dcoulter
Enthusiast
Enthusiast
Jump to solution

Get VIM Object by reference using vCloud plug-in

Hello, any suggestions on how to retrieve a VIM object by reference from a vCloud host?  I'm attempting to get the resource pool(s) backing provider vDCs.  Here's what I'm trying that's producing a null result:

for each (var vcdInstance in VclHostManager.getHostList()) {

     vcdInstance.login();

     for each (var pvdc in vcdInstance.toAdminObject().toAdminExtensionObject().getVMWProviderVdcs()) {

          for each (var rp in pvdc.getResourcePools()) {

               var rpVimObj = vcdInstance.getEntityByReference(VclFinderType.VIM_RESOURCE_POOL, rp.resourcePoolVimObjectRef);

               // rpVimObj is null

          }

     }

}


I've also tried a couple variations of finder types like VclVimObjectTypeEnum.RESOURCE_POOL as well as using rp.resourcePoolRef as parameters to getEntityByReference.  The vCloud host/plug-in version is 1.5, using vCO 5.1.

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
thomas_root1
Enthusiast
Enthusiast
Jump to solution

Hello,

there is a way! First, you have to get the MoRef of the providerVdc to identify the resourcepool in a VC. But be careful, in environments with many vCenter-servers the MoRef is maybe not unique ( look here and here).

I think this code will fit your requirements:

//A Moref is a VC-Identifier
var rpMorefs = new Array();

//do this for all vcdHosts
for each (var vcdInstance in VclHostManager.getHostList()) {

     vcdInstance.login();
     //get all Provider-vDCs from vcdHost
     for each ( var providerVdc in vcdInstance.toAdminObject().getProviderVdcs())
     {
        //Prepare query - getProviderVdc by name
        var expression = new VclExpression(VclQueryProviderVdcResourcePoolRelationField.NAME, providerVdc.name, VclExpressionType.EQUALS);
        var filter = new VclFilter(expression);
        var params = new VclQueryParams();
        params.setFilter(filter);
       
        while (resultSet != null)  {
            // retrieve ProviderVdcResourcePoolRelationRecord record
            var records = resultSet.getRecords(new VclQueryResultProviderVdcResourcePoolRelationRecord());
   
            for each (var record in records) {
                //get all resourcePoolMorefs
                rpMorefs.push(record.resourcePoolMoref);
            }
            resultSet = resultSet.getNextPage();
            }
     }
}

var resourcePools = VcPlugin.getAllResourcePools();

//get the vCenter-resourcePoolObject by Moref
for each (var moref in rpMorefs){
   
    for each (var resourcePool in resourcePools) {
        if ( moref == resourcePool.id) {
            System.log("Resourcepool of the providerVdc: " + resourcePool.name);
        }
    }
   
}

Another way to retrieve the MoRef is to extract it from the providerVdc-XML (providerVdc.toXml()).

Cheers,

Thomas

View solution in original post

Reply
0 Kudos
2 Replies
thomas_root1
Enthusiast
Enthusiast
Jump to solution

Hello,

there is a way! First, you have to get the MoRef of the providerVdc to identify the resourcepool in a VC. But be careful, in environments with many vCenter-servers the MoRef is maybe not unique ( look here and here).

I think this code will fit your requirements:

//A Moref is a VC-Identifier
var rpMorefs = new Array();

//do this for all vcdHosts
for each (var vcdInstance in VclHostManager.getHostList()) {

     vcdInstance.login();
     //get all Provider-vDCs from vcdHost
     for each ( var providerVdc in vcdInstance.toAdminObject().getProviderVdcs())
     {
        //Prepare query - getProviderVdc by name
        var expression = new VclExpression(VclQueryProviderVdcResourcePoolRelationField.NAME, providerVdc.name, VclExpressionType.EQUALS);
        var filter = new VclFilter(expression);
        var params = new VclQueryParams();
        params.setFilter(filter);
       
        while (resultSet != null)  {
            // retrieve ProviderVdcResourcePoolRelationRecord record
            var records = resultSet.getRecords(new VclQueryResultProviderVdcResourcePoolRelationRecord());
   
            for each (var record in records) {
                //get all resourcePoolMorefs
                rpMorefs.push(record.resourcePoolMoref);
            }
            resultSet = resultSet.getNextPage();
            }
     }
}

var resourcePools = VcPlugin.getAllResourcePools();

//get the vCenter-resourcePoolObject by Moref
for each (var moref in rpMorefs){
   
    for each (var resourcePool in resourcePools) {
        if ( moref == resourcePool.id) {
            System.log("Resourcepool of the providerVdc: " + resourcePool.name);
        }
    }
   
}

Another way to retrieve the MoRef is to extract it from the providerVdc-XML (providerVdc.toXml()).

Cheers,

Thomas

Reply
0 Kudos
dcoulter
Enthusiast
Enthusiast
Jump to solution

Thanks for the quick response and great write-up!  I was hoping vCO could internally resolve the object without doing a separate lookup to VcPlugin, looks like no such luck.

The resource pool moref can also be obtained with a slight modification to the original method posted:

...

for each (var rp in pvdc.getResourcePools()) {

     var rpMoRef = rp.resourcePoolVimObjectRef.moRef;  // resource pool moref

}

...

Good tip on multiple vCenters, that is the case here.

Thanks,

David

Reply
0 Kudos