5 Replies Latest reply on Dec 22, 2008 10:24 AM by Steve Jin

    Creating the Virtual Machine through VI browser

    Ashwin89 Enthusiast

       

      Hello,

       

       

      I am able to access the ESX server inventory through browser.

       

       

      I want to create the virtual machine using createvm_task() method.

       

       

      for this it required following parameters,

       

       

      Virtualmachineconfigspec (required)

       

       

      resourcepool(required)

       

       

      hostsystem (optional)

       

       

      When I am clicking on the invoke method then nothing is happening and I am loosing the connecction.

       

       

      Can anyone let me know how to specify these paramaters?

       

       

       

       

       

      Thanks,

       

       

      -AsHwIN

       

       

       

       

       

        • 1. Re: Creating the Virtual Machine through VI browser
          Steve Jin Expert

          I assume you are using the managed object browser. If so, you have to provide the required parameters in XML format.

           

          For the Virtualmachineconfigspec data object, you can check the related API reference:

           

          http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.ConfigSpec.html

           

          At the bottom of the page, you can find a link saying "Show WSDL type definition". Just click on it and you will find the XML schema of the data object. Based on the schema, you can create a XML string which includes the desired configurations, and copy it to the field for the config parameter.

           

           

          Do the same for other required parameters. When ready, just click "Invoke Method".

           

           

          Seemingly easy to say, but pretty hard to get the XML parameter right in reality.

           

           

          I have a technote illustrating how to invoke registration method on the ExtensionManager for registering VI Client plug-in using MOB. It doesn't help directly, but gives an idea what it takes to invoke a complicated method with MOB.

           

           

          http://communities.vmware.com/docs/DOC-9203

           

           

          Steve JIN, VMware Engineering

          Creator of VI Java API: http://vijava.sf.net/

          • 2. Re: Creating the Virtual Machine through VI browser
            Ashwin89 Enthusiast

             

            You mean to say we have to copy following XML in the text option.

             

             

            Where we should specify the value for different type.

             

             

            It will be really helpful if you can sample string about how to create it?

             

             

             

             

             

            <complexType xmlns="http://www.w3.org/2001/XMLSchema" xmlns:vim25="urn:vim25" name="VirtualMachineConfigSpec">

                        <complexContent>

                           <extension base="vim25:DynamicData">

                              <sequence>

                                 <element name="changeVersion" type="xsd:string" minOccurs="0"/>

                                 <element name="name" type="xsd:string" minOccurs="0"/>

                                 <element name="version" type="xsd:string" minOccurs="0"/>

                                 <element name="uuid" type="xsd:string" minOccurs="0"/>

                                 <element name="npivNodeWorldWideName" type="xsd:long" minOccurs="0" maxOccurs="unbounded"/>

                                 <element name="npivPortWorldWideName" type="xsd:long" minOccurs="0" maxOccurs="unbounded"/>

                                 <element name="npivWorldWideNameType" type="xsd:string" minOccurs="0"/>

                                 <element name="npivWorldWideNameOp" type="xsd:string" minOccurs="0"/>

                                 <element name="locationId" type="xsd:string" minOccurs="0"/>

                                 <element name="guestId" type="xsd:string" minOccurs="0"/>

                                 <element name="alternateGuestName" type="xsd:string" minOccurs="0"/>

                                 <element name="annotation" type="xsd:string" minOccurs="0"/>

                                 <element name="files" type="vim25:VirtualMachineFileInfo" minOccurs="0"/>

                                 <element name="tools" type="vim25:ToolsConfigInfo" minOccurs="0"/>

                                 <element name="flags" type="vim25:VirtualMachineFlagInfo" minOccurs="0"/>

                                 <element name="consolePreferences" type="vim25:VirtualMachineConsolePreferences" minOccurs="0"/>

                                 <element name="powerOpInfo" type="vim25:VirtualMachineDefaultPowerOpInfo" minOccurs="0"/>

                                 <element name="numCPUs" type="xsd:int" minOccurs="0"/>

                                 <element name="memoryMB" type="xsd:long" minOccurs="0"/>

                                 <element name="deviceChange" type="vim25:VirtualDeviceConfigSpec" minOccurs="0" maxOccurs="unbounded"/>

                                 <element name="cpuAllocation" type="vim25:ResourceAllocationInfo" minOccurs="0"/>

                                 <element name="memoryAllocation" type="vim25:ResourceAllocationInfo" minOccurs="0"/>

                                 <element name="cpuAffinity" type="vim25:VirtualMachineAffinityInfo" minOccurs="0"/>

                                 <element name="memoryAffinity" type="vim25:VirtualMachineAffinityInfo" minOccurs="0"/>

                                 <element name="networkShaper" type="vim25:VirtualMachineNetworkShaperInfo" minOccurs="0"/>

                                 <element name="cpuFeatureMask" type="vim25:VirtualMachineCpuIdInfoSpec" minOccurs="0" maxOccurs="unbounded"/>

                                 <element name="extraConfig" type="vim25:OptionValue" minOccurs="0" maxOccurs="unbounded"/>

                                 <element name="swapPlacement" type="xsd:string" minOccurs="0"/>

                                 <element name="bootOptions" type="vim25:VirtualMachineBootOptions" minOccurs="0"/>

                              </sequence>

                           </extension>

                        </complexContent>

                     </complexType>

             

             

             

             

             

            Thanks,

             

             

            -AsHwIN

             

             

            • 3. Re: Creating the Virtual Machine through VI browser
              Steve Jin Expert

               

              What you copied here is not the full picture yet. If you take a closer look, you can find it include other sub types like VirtualMachineFileInfo whose definition is included in this schema.

               

               

              The XML schema is just meta data with which the XML data must comply. You have to read through the schema and compile the XML data by yourself. The technote I wrote has shown how to do it step by step for the ExtensionManager.registerExtension() method. You can follow the ideas there for your own XML.

               

               

              http://communities.vmware.com/docs/DOC-9203

               

               

              Overall it's quite time consuming, and error prone. I wouldn't recommend you to do this. Any specific reason for you to go this way?

               

               

              Steve JIN, VMware Engineering

              Creator of VI Java API: http://vijava.sf.net/

               

               

              • 4. Re: Creating the Virtual Machine through VI browser
                Ashwin89 Enthusiast

                 

                Thanks Steve for the reply.

                 

                 

                I want to create the VM using VI and want to write to disk using VDDK.

                 

                 

                There is no way in VDDK to create the VM or to create the .vmx file.

                 

                 

                I will create the .vmx file using createvm_task and write to disk using VDDK.

                 

                 

                Is there any other way you suggest?

                 

                 

                 

                 

                 

                Thanks,

                 

                 

                -AsHwIN

                 

                 

                • 5. Re: Creating the Virtual Machine through VI browser
                  Steve Jin Expert

                  You can use VI SDK to create a virtual machine.  If code in Java, you can use VI Java API which makes your code much shorter and readable. Check out http://vijava.sf.net/

                   

                  Steve JIN, VMware Engineering

                  Creator of VI Java API: http://vijava.sf.net/