Home > vSphere API > Moving Virtual Machine to Distributed Virtual Switch

Moving Virtual Machine to Distributed Virtual Switch

The distributed virtual switch introduced in vSphere 4 has many benefits over the traditional switch. For one thing, you no longer have possible glitches with live migrating virtual machines from one host to another using traditional switches, and all your port settings go with your virtual machines.

If you have virtual machines using traditional switches, you can easily move them to new distributed virtual switches. The rest of this article explains how to achieve this.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure


You can use the reconfigVM_Task method defined in vSphere API (in VI Java API, it’s defined on VirtualMachine class). The tricky part is always the parameter because there are tons of possibilities with the parameter type VirtualMachineConfigSpec.

To find out how to populate the parameter, you can try the Onyx. Here are the SOAP request I recorded while changing a VM to DVS. With this XML, you can be sure about two things by studing the content within the spec tag: what parameters and what values should be there. Note that the tag names in the XML map to the same property names in data objects of parameters. I should add that you don’t have to match 100% what vSphere Client sends to the vCenter, but it’s definitely a good starting point from where you can reduce some of the sub data objects or sub properties.

<soap:Envelope xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>
    <ReconfigVM_Task xmlns=”urn:internalvim25″>
      <_this xsi:type=”ManagedObjectReference” type=”VirtualMachine” serverGuid=”BA9CE658-75F7-4A99-ACE6-99EB1376B94A”>vm-134</_this>
          <device xsi:type=”VirtualE1000″>
              <label>Network adapter 1</label>
              <summary>VM Network</summary>
            <backing xsi:type=”VirtualEthernetCardDistributedVirtualPortBackingInfo”>
                <switchUuid>49 cd 3f 50 a8 dd ce 80-03 0d 01 06 6b 91 e4 34</switchUuid>

  1. pranav
    August 3rd, 2011 at 10:28 | #1

    I am not sure whether this is right place holder for this question :

    Actually I am facing one problem when I am modifying VirtualDeviceConfigSpec i.e. removing all the nics first and adding it back again and modifying dv port group then for that dv port group after power on device status shows as not connected somehow.

    I am doing following in add part of getNICDeviceConfigSpec() , but still not able to get it connected, do I need to do some more things

    VirtualDeviceConnectInfo vdci = new VirtualDeviceConnectInfo();

    System.out.println(“setting start connected as true “);
    System.out.println( nic.getMacAddress() );

  2. Stephen McKay
    April 25th, 2016 at 18:27 | #2

    Steve – your popup banner add for the ‘”Super vCenter” with True HTML5 Client’ is truly super annoying. There has to be a better way.

  1. June 29th, 2011 at 00:02 | #1