Friday, November 18, 2011

vCO - how to determine free dvSwitch ports

Last week one of my customers ask for a method to report the free ports of all dvSwitch port-groups. First step I try was to look in the API explorer for a "freePorts" parameter, but there wasn´t one. So I developed a litte workflow including some loops (Thanks to Christophe for the bookmarked vCOteam article: Creating workflow loops).

The loops are necessary because of the unknown count of port-groups on the dvSwitch. So the whole workflow looks like this:




















The IN parameters are: DVports(String or number) and DVswitch (VC:DistributedVirtualSwitch). The DVports define the minimum available ports for the port groups and the DVswitch is the Switch to test on.

The first element "getAllPortGroups" gets all port-groups and test if it is a uplink port-group which I don´t want to test. The result is an array filled with all port-groups.

var DVSgroups = new Array();
for(i in DVS.portgroup){
if(DVS.portgroup[i].config.name.match("Uplink")){
System.log("Port-group is uplink port-group.");
}
else{
DVSgroups.push(DVS.portgroup[i]);
}
}


The next element "LoopSetup" sets the number of port-groups for the looping (DVSnb = DVSgroups.length;) and the following decision tests if the DVSnb is greater than 0 which allows you to iterate over every port-group. If the decision is true the counter will be lowered in the next step (counter = counter-1;) and the actual port-group is set in the next task (DVportGroup = DVSgroups[DVSnb];).

Now we have one port-group to test on (screenshot, cause the code raises an error in blogspot):


















As you can see I decided to count the connectees (VM Nics) of the port-groups to ensure that double used ports are counted.

I hope this helps you to find some free ports :)

No comments:

Post a Comment