VMware Cloud Community
shay009
Contributor
Contributor

how to get VLAN Id of Organization network

Hi

could you please help me to find out the VLAN Id of the organization networks ( external and internal VLAN based) through VCO  apis ( vcenter or vcloud director)

Thanks for your cooperation.

shay

0 Kudos
3 Replies
tschoergez
Leadership
Leadership

Hi!

Not directly related to the vCO Plugin  for vCD, but it might guide you in the proper direction:

http://communities.vmware.com/thread/416430?tstart=0

Cheers,

Joerg

0 Kudos
shay009
Contributor
Contributor

Thanks Joerg, but i need to get Network information(VLAN ID) via Orchestrator workflows ( VCO) via vCenter Server plugin or vCloud Director plugins.

could any body help me to get this done?

Thanks for your kind cooperation.

0 Kudos
tschoergez
Leadership
Leadership

Using the link I posted and some other examples here in the forums I put the solution together (see script below, I also attached the complete workflow).

Be aware that it is a draft, use at your own risk.

For the discussion: I didn't find another way to "translate" the vCD OrgNetwork Objects in vCenter dvPortgroups than searching for the name. That works only unique if you have only one vCenter.

Better would be to get the vCenter and the moref from vCenter, but I don't know if that is possible via the vCloud-API and the Plugin.

Cheers,

Joerg

var queryService = vCDHost.toAdminObject().toAdminExtensionObject().getExtensionQueryService();
var expression = new VclExpression(VclQueryNetworkField.NAME, "*", VclExpressionType.EQUALS);
var filter = new VclFilter(expression);
var params = new VclQueryParams();
params.setFilter(filter);
var resultSet = queryService.queryAllOrgNetworkRecords(params);
var vlanOverview = "\n";
while (resultSet != null) {
    var records = resultSet.getRecords();
// only if you look for exactly one specific orgNetwork...
//if (records.length != 1) throw "Not exactly one OrgNetwork found!";
    //record = records[0];
for each (var record in records) { // loop through all ORG?NETWORKS
        var networkRef = new VclReference();
        networkRef.href = record.href;
        networkRef.name = record.name;
        networkRef.type = record.type;
        var network = (vCDHost.getEntityByReference(VclFinderType.ORG_NETWORK, networkRef));
if (network == null ) throw " Network not found";
//System.debug(network.toXml());
System.debug("==== processing " + network + "====");
//Get dvPortgroup in vCEnter
var orgNetworkName = network.getReference().name;
var id = network.getReference().id.split(":")[3];
System.debug("id: " + id);
var xpath = "name[ends-with(.,'" + id + "')]";
System.debug("searching for DVPortgroup with xpath: " + xpath);
var portgroups = VcPlugin.getAllDistributedVirtualPortgroups(null , xpath);
//xpath doesn't seem to work here , so we have to loop through resulting array and find the exact portgroup
System.debug("portgroups: " + portgroups);
var thePortgroups = new Array();
for each (var portgroup in portgroups) {
System.debug("portgroup.name: " + portgroup.name);
//remove all NOT matching portgroups
var pgname = portgroup.name;
if (portgroup.name.lastIndexOf(id) > -1) thePortgroups.push(portgroup);
}
System.debug("thePortgroups:  " + thePortgroups);
if (thePortgroups.length > 1) throw "No unique Portgroup for " + id + " found!";
if (thePortgroups.length == 1) {
//get VLAN id for this portgroup
var thePortgroup = thePortgroups[0];
var vlanId = thePortgroup.config.defaultPortConfig.vlan.vlanId;
vlanOverview += "OrgNetwork: " + orgNetworkName + "\t\t vlanId: " + vlanId + "\n";
}
}
resultSet = resultSet.getNextPage();
}
System.log(vlanOverview);
0 Kudos