pages

Showing posts with label dvSwitch. Show all posts
Showing posts with label dvSwitch. Show all posts

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

Thursday, November 24, 2011

vCO - wavemaker, your cloud webservice (part II)

Based on the first article I will show you how to interact with the workflows and give them parameters and receive results. As you might assume this is more complex than only a short "getAllWorkflows", but with wavemaker and some instructions it is much easier than develop web-clients in higher programming languages.

First thing we will need is the workflowId which was displayed in the first tab. To copy the ID from the workflow "getFreeDvPorts" you have to change the options of the dojoGrid.














So the "selectionMode" has to be "extended" which allows you to copy the ID of the workflow. Next thing you have to do is to change the IN parameter of the "getFreeDvPorts" workflow into "dvSwitchName" as String and "NumPorts" as Number. I also added an "CriticalGroups" as Array/String OUT parameter. So the inputs are the name of the dvSwitch and the minimum of free ports the port-groups must have. The output shows all critical port-groups without enough ports.














In wavemaker, under the tab "getInventory" you can now add 4 textfields:
  • username
  • password
  • dvSwitchName
  • FreePorts
and a button called "Submit". I also add a TokenID field to control if the workflow is started. Next button is called "Result" and the "dataGrid" is used to show the OUT results of the workflow. I entered the username and password fixed which makes it a bit easier. The page should look like this:




















First step is to select the submit button and select a new "Service" for the OnClick event. This service I named "executeWf" and select the reference "vCOlab" and the "executeWorkflow" operation. Now the Submit button is linked with the "executeWorkflow" operation. 




As you can see the "executeWorkflow" operation needs different input parameters. The first two: username and password are easy, cause you only have to bind them to the text fields created in the beginning. The third one is the workflow ID of the "getFreeDvPorts" workflow you can copy from the first "getAllWorkflows" tab (extended editor).

The fourth parameter is very special and William Lam (http://www.virtuallyghetto.com/) and I had some sleepless nights to get the right method. The input parameters "workflowInputs" are set as an expression not as Array/List or something. So you have to insert the following in the expression field:
















As you can see the value is linked to the text .dataValue from "dvSwitchName" and "FreeDvPorts". So the name and the ports are defined with the text fields. For the control field you have to link the dataValue of the TokenID field to the return value "id" of the executeWf operation.














This will show the TokenID also when pressing "Submit" and this indicates that the workflow is executed in vCenter Orchestrator.

The next step is to create a new Service for the "Result" button. This is the "getWorkflowTokenResult" operation which also needs some input parameters: username, password and workflowTokenId. The first and second is bind to the appropriate text field. The third one is linked to the TokenId dataValue:












At last you have to bind the dataGrid to the return value of the "getResult" operation. As you can the the empty dataGrid is changed to a name, type and value separation.

If everything is right the execution should look like:
















So, I hope this more complex scenario helps you to speed up your personal cloud portal with wavemaker and vCO.

Have fun!


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

Monday, March 28, 2011

vCO - set Jumbo Frames (MTU) for VMkernel

Last week I spoke to some fellows here at VMware and think about a solution to automate the MTU size for a dvPort/PortGroup with vCO automation. In the past there was no automated way than the excellent solution by Scott Lowe. Based on these findings i try to build this in vCO, knowing that the vSphere Client does not support this directly.

At first i had to identify the Port which serves the vmkernel and a few input parameters:









At first I need the host (in my case as string because this is used for an external excitation via SOAP), the name of the dvSwitch, the new IP address of the vmkernel interface and the new subnet mask. So i set the host (VcPlugin.getAllHostSystems) and use the getAllDvSwitches workflow from one of my last publications.
















After that I set the dvSwitch based on the input parameter (dvSwitch) and searching for the right port. The main procedure to identify the right port is: if(Ports[h].connectee.type == "hostVmkVnic") cause this compares to the vmkernel NIC.















At this point I know everything to change the MTU of the vmkernel Port, but... the API shows an cruel description:












So as mentioned when reading the article there is no direct API based way to set the MTU of a dvPort. In my case I solve the problem with using direct ssh commands. The drawback with this is the username/password dependence.














So after identifying the right host, the vmkernel port, the new ip address and subnet mask the ssh commands can run. As you can see I used exact the same commands as the console guys use.

So, hope this helps.

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!