vCO Workflow Script to Create a Distributed Virtual Switch – Part 4

The following is a multi-part series of vCO Workflow Scripts to Create a Distributed Virtual Switch – Part 4

 

 

System.log("====================================================================================================");

System.log("===== Building dvSwitch Port Group Boolean Policy");

var objVcBoolPolicyFALSE;
	objVcBoolPolicyFALSE = new VcBoolPolicy();
	objVcBoolPolicyFALSE.inherited = false;
	objVcBoolPolicyFALSE.value = false;

System.log("===== Building dvSwitch Port Group Boolean Policy");

var objVcBoolPolicyTRUE;
	objVcBoolPolicyTRUE = new VcBoolPolicy();
	objVcBoolPolicyTRUE.inherited = false;
	objVcBoolPolicyTRUE.value = true;

System.log("===== Building dvSwitch Port Group Long Policy");

var objVcLongPolicy;
	objVcLongPolicy = new VcLongPolicy();
	objVcLongPolicy.inherited = true;	

System.log("===== Building dvSwitch Port Group Boolean Policy Inherited");

var objVcBoolPolicyInherited;
	objVcBoolPolicyInherited = new VcBoolPolicy();
	objVcBoolPolicyInherited.inherited = true;
					
System.log("===== Building an Array of dvSwitch Port Group Config Specification");

var arrVcDVPortgroupConfigSpec;
	arrVcDVPortgroupConfigSpec = new Array();

System.log("===== Looping Through an Array of dvSwitch Port Groups");

for ( var i = 0; i < arrPortGroups.length; i++ )
{
	var arrPortGroup;
		arrPortGroup = arrPortGroups[i];
		
	var strPortGroupName;
		strPortGroupName = arrPortGroup[0];
		
	var intPortGroupVLAN;
		intPortGroupVLAN = arrPortGroup[1];

	var arrPortGroupUplinks;
		arrPortGroupUplinks = arrPortGroup[2];
		
	var strPortGroupTeamingPolicy;
		strPortGroupTeamingPolicy = arrPortGroup[3];
		
	System.log("===== Building dvSwitch Port Group VLAN Specification");

	var objVcVmwareDistributedVirtualSwitchVlanIdSpec;
		objVcVmwareDistributedVirtualSwitchVlanIdSpec = new VcVmwareDistributedVirtualSwitchVlanIdSpec();
		objVcVmwareDistributedVirtualSwitchVlanIdSpec.inherited = false;
		objVcVmwareDistributedVirtualSwitchVlanIdSpec.vlanId = intPortGroupVLAN;

	System.log("===== Building dvSwitch Port Group Traffic Shaping Policy: In-Bound");

	var objVcDVSTrafficShapingPolicyIN;
		objVcDVSTrafficShapingPolicyIN = new VcDVSTrafficShapingPolicy();
		objVcDVSTrafficShapingPolicyIN.inherited = false;
		objVcDVSTrafficShapingPolicyIN.enabled = objVcBoolPolicyFALSE;
		objVcDVSTrafficShapingPolicyIN.averageBandwidth = objVcLongPolicy;	// (ingressShapingAvg * 1000); // default value = 100000000 (bits per sec - so this value/1000 is what is shown as Kbits/sec in vCenter UI)
		objVcDVSTrafficShapingPolicyIN.peakBandwidth = objVcLongPolicy;	// (ingressShapingPeak * 1000); // default value same as averageBandwidth.value
		objVcDVSTrafficShapingPolicyIN.burstSize = objVcLongPolicy;	// (ingressShapingBurst * 1024); // default value = 104857600 (102400 Kbytes as shown in vCenter UI)
	
	System.log("===== Building dvSwitch Port Group Traffic Shaping Policy: Out-Bound");

	var objVcDVSTrafficShapingPolicyOUT;
		objVcDVSTrafficShapingPolicyOUT = new VcDVSTrafficShapingPolicy();
		objVcDVSTrafficShapingPolicyOUT.inherited = false;
		objVcDVSTrafficShapingPolicyOUT.enabled = objVcBoolPolicyFALSE;
		objVcDVSTrafficShapingPolicyOUT.averageBandwidth = objVcLongPolicy;	// (egressShapingAvg * 1000); // default value = 100000000 (bits per sec - so this value/1000 is what is shown as Kbits/sec in vCenter UI)
		objVcDVSTrafficShapingPolicyOUT.peakBandwidth = objVcLongPolicy;	// (egressShapingPeak * 1000); // default value same as averageBandwidth.value
		objVcDVSTrafficShapingPolicyOUT.burstSize = objVcLongPolicy;	// (egressShapingBurst * 1024); // default value = 104857600 (102400 Kbytes as shown in vCenter UI)

	System.log("===== Building dvSwitch Port Group Failure Criteria");

	var objVcDVSFailureCriteria;
		objVcDVSFailureCriteria = new VcDVSFailureCriteria();
		objVcDVSFailureCriteria.inherited = true;
	
	System.log("===== Building dvSwitch Port Group Uplink Port Order Policy");

	var objVcVMwareUplinkPortOrderPolicy;
		objVcVMwareUplinkPortOrderPolicy = new VcVMwareUplinkPortOrderPolicy();
		objVcVMwareUplinkPortOrderPolicy.inherited = false;
		objVcVMwareUplinkPortOrderPolicy.activeUplinkPort = arrPortGroupUplinks;
		objVcVMwareUplinkPortOrderPolicy.standbyUplinkPort = new Array();

	System.log("===== Building dvSwitch Port Group Teaming Policy");

	var objVcVmwareUplinkPortTeamingPolicy;
		objVcVmwareUplinkPortTeamingPolicy = new VcVmwareUplinkPortTeamingPolicy();
		objVcVmwareUplinkPortTeamingPolicy.inherited = false;
		objVcVmwareUplinkPortTeamingPolicy.policy = new VcStringPolicy();
		objVcVmwareUplinkPortTeamingPolicy.policy.inherited = false;
		objVcVmwareUplinkPortTeamingPolicy.policy.value = "loadbalance_loadbased";
		objVcVmwareUplinkPortTeamingPolicy.notifySwitches = new VcBoolPolicy();
		objVcVmwareUplinkPortTeamingPolicy.notifySwitches.inherited = false;
		objVcVmwareUplinkPortTeamingPolicy.notifySwitches.value = true;
		objVcVmwareUplinkPortTeamingPolicy.rollingOrder = new VcBoolPolicy();
		objVcVmwareUplinkPortTeamingPolicy.rollingOrder.inherited = false;
		objVcVmwareUplinkPortTeamingPolicy.rollingOrder.value = !true;
		objVcVmwareUplinkPortTeamingPolicy.failureCriteria = objVcDVSFailureCriteria;
		objVcVmwareUplinkPortTeamingPolicy.uplinkPortOrder = objVcVMwareUplinkPortOrderPolicy;
	
	System.log("===== Building dvSwitch Port Group Policy");

	var objVcVMwareDVSPortgroupPolicy;
		objVcVMwareDVSPortgroupPolicy = new VcVMwareDVSPortgroupPolicy();
		objVcVMwareDVSPortgroupPolicy.portConfigResetAtDisconnect = true;
		objVcVMwareDVSPortgroupPolicy.blockOverrideAllowed = true;
		objVcVMwareDVSPortgroupPolicy.shapingOverrideAllowed = false;
		objVcVMwareDVSPortgroupPolicy.vendorConfigOverrideAllowed = false;
		objVcVMwareDVSPortgroupPolicy.livePortMovingAllowed = false;
		objVcVMwareDVSPortgroupPolicy.vlanOverrideAllowed = false;
		objVcVMwareDVSPortgroupPolicy.uplinkTeamingOverrideAllowed = false;
		objVcVMwareDVSPortgroupPolicy.securityPolicyOverrideAllowed = false;
		
	System.log("===== Building dvSwitch Port Group Uplink Lacp Policy");
	
	var objVcVMwareUplinkLacpPolicy;
		objVcVMwareUplinkLacpPolicy = new VcVMwareUplinkLacpPolicy();
		objVcVMwareUplinkLacpPolicyinherited = false;
		objVcVMwareUplinkLacpPolicy.enable = objVcBoolPolicyInherited;
		objVcVMwareUplinkLacpPolicy.mode = new VcStringPolicy();
		objVcVMwareUplinkLacpPolicy.mode.inherited = true;
		
	System.log("===== Building dvSwitch Port Group Security Policy");

	var objVcDVSSecurityPolicy;
		objVcDVSSecurityPolicy = new VcDVSSecurityPolicy();
		objVcDVSSecurityPolicy.inherited = true;
		objVcDVSSecurityPolicy.allowPromiscuous = objVcBoolPolicyInherited;
		objVcDVSSecurityPolicy.forgedTransmits = objVcBoolPolicyTRUE;
		objVcDVSSecurityPolicy.macChanges = objVcBoolPolicyTRUE;
		
	System.log("===== Building dvSwitch Port Group Port Setting");

	var objVcVMwareDVSPortSetting;
		objVcVMwareDVSPortSetting = new VcVMwareDVSPortSetting();
		objVcVMwareDVSPortSetting.vlan = objVcVmwareDistributedVirtualSwitchVlanIdSpec;
		objVcVMwareDVSPortSetting.blocked = objVcBoolPolicyFALSE;
		objVcVMwareDVSPortSetting.inShapingPolicy = objVcDVSTrafficShapingPolicyIN;
		objVcVMwareDVSPortSetting.outShapingPolicy = objVcDVSTrafficShapingPolicyOUT;
		objVcVMwareDVSPortSetting.ipfixEnabled = objVcBoolPolicyInherited;
		objVcVMwareDVSPortSetting.lacpPolicy = objVcVMwareUplinkLacpPolicy;
		objVcVMwareDVSPortSetting.networkResourcePoolKey = new VcStringPolicy();
		objVcVMwareDVSPortSetting.networkResourcePoolKey.inherited = false;
		objVcVMwareDVSPortSetting.networkResourcePoolKey.value = "-1";
		objVcVMwareDVSPortSetting.qosTag = new VcIntPolicy();
		objVcVMwareDVSPortSetting.qosTag.inherited = true;
		objVcVMwareDVSPortSetting.securityPolicy = objVcDVSSecurityPolicy;
		objVcVMwareDVSPortSetting.txUplink = objVcBoolPolicyInherited;
		objVcVMwareDVSPortSetting.uplinkTeamingPolicy = objVcVmwareUplinkPortTeamingPolicy;
		objVcVMwareDVSPortSetting.vmDirectPathGen2Allowed = objVcBoolPolicyInherited;
		
	System.log("===== Building dvSwitch Port Group Configuration Specification");

	var objVcDVPortgroupConfigSpec;
		objVcDVPortgroupConfigSpec = new VcDVPortgroupConfigSpec();
		objVcDVPortgroupConfigSpec.name = strPortGroupName;
		objVcDVPortgroupConfigSpec.description = strPortGroupName;
		objVcDVPortgroupConfigSpec.numPorts = 16;
		objVcDVPortgroupConfigSpec.type = "earlyBinding";
		objVcDVPortgroupConfigSpec.autoExpand = true;
		objVcDVPortgroupConfigSpec.configVersion = "5.1.0";
		objVcDVPortgroupConfigSpec.policy = objVcVMwareDVSPortgroupPolicy;
		objVcDVPortgroupConfigSpec.portNameFormat = null;
		objVcDVPortgroupConfigSpec.defaultPortConfig = objVcVMwareDVSPortSetting;
		
	System.log("===== Adding the New dvSwitch Port Group Configuration Specification to The Array");

	arrVcDVPortgroupConfigSpec.push(objVcDVPortgroupConfigSpec);
}

System.log("====================================================================================================");

System.log("===== There are " + arrVcDVPortgroupConfigSpec.length + " dvSwitch Port Group Configuration Specifications Ready to be Created")

System.log("===== Executing the dvSwitch Port Group Creation Task");

var objVcTask;
	objVcTask = objVcVMwareDistributedVirtualSwitch.addDVPortgroup_Task(arrVcDVPortgroupConfigSpec);

var objResult;
	objResult = objModule.WaitForVcTask(objVcTask);
			
System.log("====================================================================================================");

Leave a Reply