joeheyming
Contributor
Contributor

Create vlan for esx host

Hi,

I'm trying to learn how to use orchestrator and I thought a good project would be to create a workflow that allows you to create a vlan for an esx host.

What I would like to do further with this is to create a vlan on a bunch of hosts at a time, like say: for this folder of esx hosts, create the vlan id on it if it doesn't exist.

Any tips on how to add a vlan to an esx host?

-


Sorry, I meant, can I use the vmware api to create a portgroup with a specific vlan ID for the main vswitch of an esx host. Smiley Happy

0 Kudos
3 Replies
krowczynski
Virtuoso
Virtuoso

Create an VLAN on your physical switch.

After that assign an new Portgroup an an vswitch with the new created VLAN.

MCP, VCP3 , VCP4
0 Kudos
joeheyming
Contributor
Contributor

Hi. I solved it by creating an action element. Decided I'd share the main part for others.

System.log("----creating portGroupSpec--


");

var vlanName = "VLAN"+vlanID; // vlanID is a number input to the action

var myPortGroupSpec = new VcHostPortGroupSpec();

myPortGroupSpec.name = vlanName;

myPortGroupSpec.vlanId = vlanID;

myPortGroupSpec.vswitchName = defaultSwitch; // default switch is calculated above

var myVcHostNetworkPolicy = new VcHostNetworkPolicy() ;

myPortGroupSpec.policy = myVcHostNetworkPolicy;

System.log("------ getting ManagedObjectReference --> HostNetworkSystem -


");

var vimHost = VcPlugin.allVimHosts[0];

var netSys = VcPlugin.convertToVimManagedObject(vimHost, host.configManager.networkSystem);

System.log("------run add port group: " + vlanName + " -


");

try{

netSys.addPortGroup(myPortGroupSpec);

System.log("Successfully created portgroup!");

}

catch(exception){

System.log("Portgroup already exists!");

}

-


Its just javascript!! Its not that hard. Luckily I had my trusty api documentation.

0 Kudos
admin
Immortal
Immortal

Thanks for sharing!

You beat me to the punch. I thought you wanted a new vswitch instead of a new port group and had started working on that.

Cheers,

Sia

0 Kudos