pages

Showing posts with label DVS. Show all posts
Showing posts with label DVS. Show all posts

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 :)

Thursday, January 27, 2011

vCO - get all Distributed Virtual Switches

Yesterday i try to get all dvSwitches of a vCenter environment into an array. After several hours of searching and trying there is no easy way in my opinion. So i think this little workaround could help:

var dvPG = VcPlugin.getAllDistributedVirtualPortgroups();
var DVS = new Array(); 

for(i in dvPG){
   DVS.push(dvPG[i].config.distributedVirtualSwitch);
   DVS.sort();
   System.log("DVS vor Schleife: " + DVS);

   for ( i = 0; i < DVS.length; i++)
      {
      if(i != 0){
      while (DVS[i] == DVS[i-1])
      DVS.splice(i,1);
      }
   }
}

If you have other ways please feel free to publish them as a comment. Please note that you need at least one dvPortGroup!