VMware Cloud Community
Zeppa
Contributor
Contributor

How to obtain VDS Portrgroup MoRef from name?

Hi,
I'm working on a workflow that creates portgroups, then external networks, then org networks.
To create external networks I need the MoRef of the portrgroups previously created. I read that is possible to get Moref from PG using query service but I can't find the way to do it.
Any help would be great.
Thanks
Zeppa
1 Reply
Zeppa
Contributor
Contributor

Me again.

I figured it out, so I'm sharing.

vcdhost is a vcloud host, and nombre is the name of the portrgroup.

var queryService = vcdhost.getQueryService();
expression = new VclExpression(VclQueryPortgroupField.NAME, nombre, VclExpressionType.EQUALS);
filter = new VclFilter(expression);
params = new VclQueryParams();
params.setFilter(filter);
var resultSet = queryService.queryRecords(VclQueryRecordType.PORTGROUP, params);
while (resultSet != null) {
    var records = resultSet.getRecords(new VclQueryResultPortgroupRecord());
    System.log(records.length + " Encontré algo");   
    for each (var record in records) {
        if (record.name == nombre) {
            record2 = record.moref;
            }
   }
    resultSet = resultSet.getNextPage();
}
0 Kudos