vCO – Create Distributed Virtual Port Group

Here is the code for creating a distributed virtual port group. Input is of type VC:VmwareDistributedVirtualSwitch

//New port group basics like name and port numbers
var dvPortgroupConfigSpec = new Array();
dvPortgroupConfigSpec[0] = new VcDVPortgroupConfigSpec();
dvPortgroupConfigSpec[0].name = "vMotion";
dvPortgroupConfigSpec[0].numPorts = 32;
//Supported in vSphere 4.1: earlyBinding, ephemeral, lateBinding
dvPortgroupConfigSpec[0].type = "earlyBinding";

//Create vlan id
dvPortgroupConfigSpec[0].defaultPortConfig = new VcVMwareDVSPortSetting();
dvPortgroupConfigSpec[0].defaultPortConfig.vlan = new VcVmwareDistributedVirtualSwitchVlanIdSpec();
dvPortgroupConfigSpec[0].defaultPortConfig.vlan.inherited = false;
dvPortgroupConfigSpec[0].defaultPortConfig.vlan.vlanId = 0;

//Create Load Balancing Policy
dvPortgroupConfigSpec[0].defaultPortConfig.uplinkTeamingPolicy = new VcVmwareUplinkPortTeamingPolicy();
dvPortgroupConfigSpec[0].defaultPortConfig.uplinkTeamingPolicy.policy = new VcStringPolicy();
//Supported in vSphere 4.1: loadbalance_ip, loadbalance_loadbased, loadbalanced_srcid, loadbalanced_srcmac
dvPortgroupConfigSpec[0].defaultPortConfig.uplinkTeamingPolicy.policy.value = "loadbalance_loadbased";

//Security Policy all to reject
var reject = new VcBoolPolicy();
reject.value = false;
dvPortgroupConfigSpec[0].defaultPortConfig.securityPolicy = new VcDVSSecurityPolicy();
dvPortgroupConfigSpec[0].defaultPortConfig.securityPolicy.allowPromiscuous = reject;
dvPortgroupConfigSpec[0].defaultPortConfig.securityPolicy.forgedTransmits = reject;
dvPortgroupConfigSpec[0].defaultPortConfig.securityPolicy.macChanges = reject;
dvPortgroupConfigSpec[0].defaultPortConfig.securityPolicy.inherited = false;

//myDVS is input parameter of type VC:VmwareDistributedVirtualSwitch
task = myDVS.addDVPortgroup_Task(dvPortgroupConfigSpec);

Published by txusa

VMware Certified Design Expert - VCDX 92. VMware Architect, automation enthusiast.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: