1 Reply Latest reply on Sep 11, 2019 2:17 AM by shill81

    Execute SOAP request to Add Virtual Machine to DRS Group

    antonnoble_2014 Lurker

      Hi, I've been working with SOAP messages and the vSphere vimService lately. I've ran into a snag. I want to add a virtual machine to an existing DRS group by send a soap call to the API. Here's what I'm trying:

       

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

        </soap:Header>

        <soap:Body>

          <ReconfigureComputeResource_Task xmlns="urn:internalvim25">

            <_this xsi:type="ManagedObjectReference" type="ClusterComputeResource">domain-c22</_this>

            <spec xsi:type="ClusterConfigSpecEx">

              <groupSpec>

                <operation>edit</operation>

                <info xsi:type="ClusterVmGroup">

                  <name>migrateVMs</name>

                  <vm type="VirtualMachine" >vm-2261</vm>

                </info>

              </groupSpec>

            </spec>

            <modify>true</modify>

          </ReconfigureComputeResource_Task>

        </soap:Body>

      </soap:Envelope>

       

      Error Message:

       

      Unable to find specified dynamic type &quot;ClusterVmGroup&quot;

      Specified dynamic type ClusterVmGroup is not a DataObject type.

       

      If I watch this call happen in Project Onyx using both the VI Client and PowerCLI the exact same call is pretty much being made, without failure. Can anyone provide an explanation on how format my SOAP to make this work? I use onyx for similar operations making SOAP calls and never have problems. I've reviewed the reference API docs, and it looks right...

       

      Kind Regards

        • 1. Re: Execute SOAP request to Add Virtual Machine to DRS Group
          shill81 Lurker

          I spent almost a day figuring this out: You need to set the API version in the HTTP header:

           

          SOAPAction: "urn:vim25/6.5"

           

          If you don't do that you end up with an older API version, which does not support the neccesary datatypes.

           

          POST https://<hostname>/sdk/vimService HTTP/1.1

          Accept-Encoding: gzip,deflate

          Content-Type: text/xml;charset=UTF-8

          SOAPAction: "urn:vim25/6.5"

          Cookie:

          Content-Length: 681

          Host: <host>

          Connection: Keep-Alive

          User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

          Cookie: vmware_soap_session="<sessionkey>"

          Cookie2: $Version=1

           

          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

             <soapenv:Header/>

             <soapenv:Body>

                <urn:ReconfigureComputeResource_Task>

                   <urn:_this type="ClusterComputeResource">domain-c28</urn:_this>

                   <urn:spec xsi:type="ClusterConfigSpecEx">

                  <groupSpec>

                      <operation>add</operation>

                      <info xsi:type="ClusterVmGroup">

                          <name>TestGroup</name>

                          <vm>vm-123</vm>    

                      </info>

                  </groupSpec>

                   </urn:spec>

                   <urn:modify>true</urn:modify>

                </urn:ReconfigureComputeResource_Task>

             </soapenv:Body>

          </soapenv:Envelope>