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.

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

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/”>
  <soap:Header>
    <operationID>42A86E36-0000045C</operationID>
  </soap:Header>
  <soap:Body>
    <ReconfigVM_Task xmlns=”urn:internalvim25″>
      <_this xsi:type=”ManagedObjectReference” type=”VirtualMachine” serverGuid=”BA9CE658-75F7-4A99-ACE6-99EB1376B94A”>vm-134</_this>
      <spec>
        <changeVersion>2011-02-27T05:29:38.0135Z</changeVersion>
        <deviceChange>
          <operation>edit</operation>
          <device xsi:type=”VirtualE1000″>
            <key>4000</key>
            <deviceInfo>
              <label>Network adapter 1</label>
              <summary>VM Network</summary>
            </deviceInfo>
            <backing xsi:type=”VirtualEthernetCardDistributedVirtualPortBackingInfo”>
              <port>
                <switchUuid>49 cd 3f 50 a8 dd ce 80-03 0d 01 06 6b 91 e4 34</switchUuid>
                <portgroupKey>dvportgroup-328</portgroupKey>
              </port>
            </backing>
            <connectable>
              <startConnected>true</startConnected>
              <allowGuestControl>true</allowGuestControl>
              <connected>false</connected>
              <status>untried</status>
            </connectable>
            <controllerKey>100</controllerKey>
            <unitNumber>7</unitNumber>
            <addressType>assigned</addressType>
            <macAddress>00:50:56:ba:27:69</macAddress>
            <wakeOnLanEnabled>true</wakeOnLanEnabled>
          </device>
        </deviceChange>
      </spec>
    </ReconfigVM_Task>
  </soap:Body>
</soap:Envelope>

This entry was posted in vSphere API and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. pranav
    Posted August 3, 2011 at 10:28 am | Permalink

    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();
    vdci.setStartConnected(true);
    //vdci.setConnected(true);
    vdci.setAllowGuestControl(true);

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

  2. Stephen McKay
    Posted April 25, 2016 at 6:27 pm | Permalink

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

One Trackback

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  • NEED HELP?


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.