vCO – Create Distributed Virtual Switch (DVS)

Here is the code for creating a distributed virtual switch. Input is sdkConnection. The code assumes you have only the root network folder.

//sdkConnection is an input parameter of type VC:SdkConnection
var allNetFolder = sdkConnection.getAllNetworkFolders();

//Assuming you have no network folder but the root folder
var netFolder = allNetFolder[0];

var dvsCreateSpec = new VcDVSCreateSpec();
var uplinkNames = new Array();
uplinkNames.push("uplink1");
uplinkNames.push("uplink2");
dvsCreateSpec.productInfo = new VcDistributedVirtualSwitchProductSpec();
//The Version of the DVS
dvsCreateSpec.productInfo.version = "4.1.0";  
dvsCreateSpec.configSpec = new VcVMwareDVSConfigSpec();
//The name of the DVS
dvsCreateSpec.configSpec.name = "DVSwitch_Backup";
dvsCreateSpec.configSpec.uplinkPortPolicy = new VcDVSNameArrayUplinkPortPolicy;
dvsCreateSpec.configSpec.uplinkPortPolicy.uplinkPortName = uplinkNames;

//Optional
dvsCreateSpec.configSpec.maxMtu = 9000;
dvsCreateSpec.configSpec.maxPorts = 20000;

task = netFolder.createDVS_Task(dvsCreateSpec);

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:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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: