pages

Friday, March 9, 2012

vCO - how to find the vlanID of a dvPortGroup

Today I received an interesting question: "How to find out the VLAN ID of a distributed virtual port group?". At the first moment I think: "No problem, cause the vSphere client can also show the information.".

After several hours and searches in the vSphere API and Onyx I realized that there isn´t any direct method for that :(

So I test the illogical things and enhanced the defaultPortConfig attribute about the vlan attribute... and what should I say: There was an atribute!

After testing if the attribute is part of the VcVmwareDistributedVirtualSwitchVlanIdSpec I was able to check the vlan :)



for(i in dvSwitch.portgroup){
System.debug(dvSwitch.portgroup[i].config.defaultPortConfig.vlan);
if(dvSwitch.portgroup[i].config.defaultPortConfig.vlan instanceof VcVmwareDistributedVirtualSwitchVlanIdSpec){
System.debug(dvSwitch.portgroup[i].config.defaultPortConfig.vlan.vlanId);
}
}


This looks like the following screen in the end:












So I hope this helps! By the way, I never had so many failed runs in a row :)