Search code examples
soapvmwarevsphere

Create Distributed Portgroup with VLAN id in VMware vSphere SOAP api


I'm trying to create a distributed port group with a vlan ID in a VDS in VMware vSphere using the SOAP api. I can get it to create the port group, but it never assigns the vlan id. Here is the request I am sending as the spec to the CreateDVPortGroup_Task method (in the Managed Object Browser):

<spec>
   <name>Test</name>
   <numPorts>10</numPorts>
   <defaultPortConfig type="VMwareDVSPortSetting">
     <vlan>
       <inherited>false</inherited>
       <vlanId>123</vlanId>
     </vlan>
   </defaultPortConfig>
   <type>earlyBinding</type>
   <autoExpand>false</autoExpand>
</spec>

This creates a portgroup, but does not set the vlanId.

I see that it expects a DVPortSetting for the defaultPortConfig, but vsphere retains it as a VMwareDVSPortSetting object.

I've seen a few examples around the web doing it through other means, but I just need the format of the SOAP message. Could someone provide me with a sample soap request that would create a distributed port group with a vlan id?

Any help would be much appreciated.


Solution

  • Finally figured It out by looking through the implementation of vijava. Instead of using the type attribute, you have to use 'xsi:type'. What I was looking for was:

    <spec xsi:type="DVPortgroupConfigSpec">
       <name>Test</name>
       <numPorts>10</numPorts>
       <defaultPortConfig xsi:type="VMwareDVSPortSetting">
         <vlan xsi:type="VmwareDistributedVirtualSwitchVlanIdSpec">
           <inherited>false</inherited>
           <vlanId>123</vlanId>
         </vlan>
       </defaultPortConfig>
       <type>earlyBinding</type>
       <autoExpand>false</autoExpand>
    </spec>
    

    Frustratingly simple!