There are situations when one need to add a new port group to the existing standard vSwitch in vCenter. This is easily configurable in the vCenter in the host configuration. This can be done manually on the small number of hosts, however on bigger number it can be really annoying. What offers vRO as basis. In the built in workflow list under the “Library->vCenter->Networking->Standard Virtual Switch“, one can find a workflow “Add port group in the standard virtual switch“. It’s good for the start, so let’s see what it needs
So it requires plenty of parameters, but only few of them are mandatory : host, name, connectionType, portGroupName. It’s also wise to set proper VLAN ID, otherwise it will be set to 0.
So this pretty nice workflow does the job of adding new port group on the one ESX host. My use case was a little bit different. I had predefined virtual switch and connection type. So as vendor recommends I did a copy of existing workflow and I started to modify it. I called it “Add new port group to the vSwitch1 – VM type“.
After the copy, my first step was to remove from input all data I don’t need to be entered, so I left only three input parameters :
- host – type : VC:Hostsystem
- vlanid – type : number
- portGroupName – portGroupName
and rest of input parameters were moved as attributes. I had to set values in two of the attributes, name=vSwitch1 and connectionType=Virtual Machine, because these were mandatory.
And that’s it. I just commented few lines in the “Scriptable task” and added on to display some information
//System.log("host: " + host);
//System.log("host.configManager: " + host.configManager);
//System.log("Config: " + config);
System.log("Adding port group : " + portGroupName + ", vlan ID : " + vlanId + " on host " + host.name)
var myVcHostNetworkConfigResult = host.configManager.networkSystem.updateNetworkConfig(config, "modify"); // HostNetworkSystem
//System.log("result: " + myVcHostNetworkConfigResult);
It’s not necessary, I just did it to make it more readable. So now I have workflow to add new portgroup to the host on my requirements, however the task was to add this port group to all hosts
within provided cluster. For that I will use workflow I created to enumerate all hosts within the ESX cluster – this workflow returns an array of VC:HostSystem systems. Then I will use “Foreach element” workflow to run previously created workflow on each host from the returned array.
So in this workflow I have 3 input parameters : esxCluster, vlanid and portGroupName
So esxCluster will be used by workflow getAllHostsofCluster and the return array of hosts and then this array and remaining input parameters will be used in the “foreach element” workflow to add port group on each host of the cluster.
Last thing I’ve not for my workflow, was to replace the input of ESX cluster with drop-down list automatically generated from vCenter.
To achieve this I created a simple vRO action “ListvCenterClusters) with following code, this action brings as result array of string
var clArray = new Array()
clArray = VcPlugin.getAllClusterComputeResources()
var returnArray = new Array()
for (var i in clArray)
and I bound it to the input parameter esxCluster
So finally I have it
And that’s it.