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 } }