vCO – Configure vMotion with Virtual Distributed Virtual Switch

Here is some code how to configure the vMotion address with a distributed virtual switch. Input parameter are my host and dvSwitch. I go through all portgroups and compare if it is called vmotion. If so I set IP and subnet. Hard coded so it is easier to understand, you probably want this also as input parameter or use some algorithm. For instance user last octet from MGT IP to have same last octet.

//myhost is input parameter of type VcHostSystem
//dvSwitch is input parameter of type...
 
var networkSystem = myhost.configManager.networkSystem;
var vMotionSystem = myhost.configManager.vmotionSystem;
var pgs = dvSwitch.portgroup;

for each (var pg in pgs)
{
	if (pg.name.toLowerCase() == "vmotion")
	{
		System.log("vMotion PG name: " + pg.name);
		var nic = new VcHostVirtualNicSpec();
		nic.ip = new VcHostIpConfig();
		nic.ip.dhcp = false;
		nic.ip.ipAddress = "192.168.1.10"; 
		nic.ip.subnetMask = "255.255.255.0";
		nic.distributedVirtualPort = new VcDistributedVirtualSwitchPortConnection();
		nic.distributedVirtualPort.switchUuid = dvSwitch.uuid;
		nic.distributedVirtualPort.portgroupKey = pg.key;

		networkSystem.addVirtualNic("", nic);  // HostNetworkSystem
		vMotionSystem.selectVnic("vmk1");  //enable vMotion
	}
	
}

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 )

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: