7 Replies Latest reply on Nov 11, 2010 12:58 AM by brugh2

    LabManager import VM with Powershell

    brugh2 Enthusiast

      Hi,

       

      I'm trying to import a VM into LM using powershell. i got everything working up to the point where i have to give some configuration for the imported VM.

       

      I used http://poshcode.org/2263 to get going but instead of the external i used the internal API. it all works fine because i can call methods and get respons from labmanager.

       

      but when i try to import a VM with TemplateImportFromSMB there's one thing i can't get right. As the 2nd to last parameter it wants a VMparameter[] type. but i don't know how to create that in powershell. i tried @{ HW_VERSION="7" } and all sorts of array variants but powershell keeps complaining that it can't convert from hashtable or object[] or whatever i try, to this VMparameter[] type.

       

      from http://server/LabManager/SOAP/LabManagerInternal.asmx?WSDL i can see that the type should. as far as i can tell it's a form of string=>string type array. does anybody know how to build the parameter array to add to the import function? when i give  $() it imports into labmanager but with HW_VERSION 0 so it can't use it.

       

      i think i'm very close but can't get this last step to work. any help greatly appreciated!

       

       

      some data:

       

      $credential = $(get-credential)

      $server = "https://lmserver/LabManager/SOAP/LabManagerInternal.asmx"

      $proxy = New-WebServiceProxy -Uri $server -Credential $credential

       

      $proxy.TemplateImportFromSMB("
      FS001\share\VM-dir", "dirUser", "dirPwd", "VMname", "VMDescr", "DSname", @{ HW_VERSION = "7" }, 0);

      Cannot convert argument "6", with value: "System.Collections.Hashtable", for "TemplateImportFromSMB" to type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3r_SOAP_LabManagerInternal_asmx.VMParameter[]": "Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3r_SOAP_LabManagerInternal_asmx.VMParameter[]".

       

      and a bit WSDL:

       

            <s:complexType name="ArrayOfVMParameter">

              <s:sequence>

                <s:element minOccurs="0" maxOccurs="unbounded" name="VMParameter" nillable="true" type="tns:VMParameter" />

              </s:sequence>

            </s:complexType>

            <s:complexType name="VMParameter">

              <s:sequence>

                <s:element minOccurs="1" maxOccurs="1" name="parameter_name" type="tns:VMParameterType" />

                <s:element minOccurs="0" maxOccurs="1" name="parameter_value" type="s:string" />

              </s:sequence>

            </s:complexType>

            <s:simpleType name="VMParameterType">

              <s:restriction base="s:string">

                <s:enumeration value="NAME" />

                <s:enumeration value="DESCRIPTION" />

                <s:enumeration value="VCPUCOUNT" />

                <s:enumeration value="GUESTOS" />

                <s:enumeration value="MEMORY" />

                <s:enumeration value="ISVROUTER" />

                <s:enumeration value="VMXFILENAME" />

                <s:enumeration value="VMXDATASTOREPATH" />

                <s:enumeration value="DS_URL" />

                <s:enumeration value="HW_VERSION" />

                <s:enumeration value="FILE_ALLOCATION_TYPE" />

              </s:restriction>

            </s:simpleType>

            <s:element name="TemplateImportResponse">

              <s:complexType>

                <s:sequence>

                  <s:element minOccurs="1" maxOccurs="1" name="TemplateImportResult" type="s:int" />

                </s:sequence>

              </s:complexType>

            </s:element>

            <s:element name="TemplateImportFromSMB">

              <s:complexType>

                <s:sequence>

                  <s:element minOccurs="0" maxOccurs="1" name="UNCPath" type="s:string" />

                  <s:element minOccurs="0" maxOccurs="1" name="dirUsername" type="s:string" />

                  <s:element minOccurs="0" maxOccurs="1" name="dirPassword" type="s:string" />

                  <s:element minOccurs="0" maxOccurs="1" name="name" type="s:string" />

                  <s:element minOccurs="0" maxOccurs="1" name="description" type="s:string" />

                  <s:element minOccurs="0" maxOccurs="1" name="storageServerName" type="s:string" />

                  <s:element minOccurs="0" maxOccurs="1" name="parameterList" type="tns:ArrayOfVMParameter" />

                  <s:element minOccurs="1" maxOccurs="1" name="performGuestCustomization" type="s:boolean" />

                </s:sequence>

              </s:complexType>

            </s:element>

            <s:element name="TemplateImportFromSMBResponse">

              <s:complexType>

                <s:sequence>

                  <s:element minOccurs="1" maxOccurs="1" name="TemplateImportFromSMBResult" type="s:int" />

                </s:sequence>

              </s:complexType>

            </s:element>

        • 1. Re: LabManager import VM with Powershell
          antize Enthusiast

          Looks like you need a type: LabManager.Web.SOAP.VMParameter , which comes from VSLA.UI.dll. Check out http://communities.vmware.com/docs/DOC-10608 and https: //yourserver/LabManager/SOAP/LabManagerInternal.asmx?op=TemplateImportFromSMB .

           

          I found that DLL on my Lab Manager server here: C:\Program Files\VMware\VMware vCenter Lab Manager\WebSrvr\bin\VSLA.UI.dll.

           

          [http://  Reflection.Assembly  |http://  Reflection.Assembly  ]::LoadFrom("C:\Program Files\VMware\VMware vCenter Lab Manager\WebSrvr\bin\VSLA.UI.dll")
          

           

          $vmp = New-Object LabManager.Web.SOAP.VMParameter
          

           

          $vmp.parameter_name = "HW_VERSION"
          

           

          $vmp.parameter_value = 7
          

           

          [  LabManager.Web.SOAP.VMParameter  [  ]  ] $vmps += $vmp
          

           

          BY THE WAY! I HATE THIS DAMN FORUM FORMATTING ENGINE! HOW THE HELL DO I PUT SQUARE BRACKETS AND NOT HAVE THE TRANSFORM INTO URLS!!

          1 person found this helpful
          • 2. Re: LabManager import VM with Powershell
            brugh2 Enthusiast

            Aah, that's the missing link! I was kinda hoping it was a missing reference.

             

            one thing though, i don't run the powershell script on the labmanager server but on the server where my orchestrator runs. can i just copy the dll and reference it? or do i have to somehow register it first?

             

            never mind. i just tried it and it works like a charm i can now point to a VM in vCenter and have orchestrator validate the DB export at a DBA, clone the VM and fire the import script to make it available in Labmanager. Chain complete!

             

            Thanks for the assist

            • 3. Re: LabManager import VM with Powershell
              M0rph77 Novice

              hello, thanks for pointing me in the right direction

               

              one question;

              I've copied the dll locally on my orchestrator server..

              after:

               

              http://Reflection.Assembly::LoadFrom("C:\Program Files (x86)\VMware\VSLA.UI.dll")

              $vmp = New-Object LabManager.Web.SOAP.VMParameter

               

              I get the following error:

               

              New-Object : Cannot find type http://LabManager.Web.SOAP.VMParameter: make sure the assembly containing this type is loaded.

               

              Any suggestions where it's going wrong in my case?

              Thanks in advance!

              • 4. Re: LabManager import VM with Powershell
                brugh2 Enthusiast

                i had the same problem initially. i think when the assembly gets loaded, microsoft creates a new type for it. so instead of

                 

                  LabManager.Web.SOAP.VMParameter

                 

                i had to use this type (cut/paste from the errormessage i got):

                 

                  Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.VMParameter

                 

                go figure

                • 5. Re: LabManager import VM with Powershell
                  brugh2 Enthusiast

                  I do have another problem that perhaps antize or anybody else can shine a light on;

                   

                  when i build the VMparameters array, things seem to go well:

                   

                  $hw=new-object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.VMParameter

                  $hw.parameter_name = "HW_VERSION"

                  $hw.parameter_value = "7"

                   

                  $cpu=new-object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.VMParameter

                  $cpu.parameter_name = "VCPUCOUNT"

                  $cpu.parameter_value = "1"

                   

                  $gos=new-object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.VMParameter

                  $gos.parameter_name = "GUESTOS"

                  $gos.parameter_value = "RHEL4"

                   

                  [http://Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.VMparameter[|http://Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1r_SOAP_LabManagerInternal_asmx.VMparameter[]] $vmps += $cpu

                  $vmps += $hw

                  $vmps += $gos

                   

                  when i then show the content of the $vmps i get:

                   

                     parameter_name parameter_value

                     -


                  -


                         HW_VERSION 7

                            GUESTOS RHEL4

                          VCPUCOUNT 1

                   

                  so that's good. but when i run the TemplateImportFromSMB function, the call reports:

                      vCenter Lab Manager cannot find any suitable host connected to the datastore "VMFS_STORE" for this operation.

                   

                  i see a template appear in labmanager. but LM then reports an error saying:

                      Host "ESX1" does not support virtual machine hardware version "0"

                   

                  so somehow the '7' doesn't get through to the actual call.

                   

                  i see some perl scripts out there that show CPUCOUNT with value '1' (a string) but HW_VERSION as $7. i don't know what that means, if it means anything at all, but perhaps this helps somebody on what exactly to put in the VMparameters array? the WSDL shows it should be a string also but that doesn't seem to work.

                   

                  any ideas?

                  • 6. Re: LabManager import VM with Powershell
                    brugh2 Enthusiast

                    OK! this turns out not to be a powershell issue but a totally wrong errormessage from lab manager! as it turns out, the VM you want to import shouldn't be a some vmdk and vmx files in a directory but a directory with a configuration.xml file and a 'VM0' directory with the vmx and other files AND a 'vm.xml' file.

                     

                    I put everything in a blog post at http://virtuall.eu/blog/import-a-vm-in-lab-manager-using-orchestrator. it works like a charm. select a VM in Orchestrator, export it to a share (so you don't have to switch off the VM in production), import it into Lab Manager, and add it to a configuration.

                    • 7. Re: LabManager import VM with Powershell
                      brugh2 Enthusiast

                      The whole flow of things you need to do can be found at http://virtuall.eu/blog/import-a-vm-in-lab-manager-using-orchestrator