4 Replies Latest reply on Mar 7, 2017 3:43 PM by bgarner

    Do "Copy to Catalog" via powercli looking for clues...

    bgarner Hot Shot

      I'm automating a template distribution process and need some insight on how to call the "copy to catalog" command via powercli. None of the regular powercli modules seem to have this function. Based on this old blog post https://blogs.vmware.com/PowerCLI/2012/03/automating-creation-of-vcd-organizations-users-and-org-vdcs.html "The Get-CIView cmdlet and ExtensionData property exposes the entire vCloud Director API and allows us to make changes to the CI, this opens up multiple possibilities and moves us away from just retrieving data and allows us to create and alter our CI." This looks like a usable API to powercli bridge.

      Screen Shot 2017-03-06 at 10.44.02 AM.png


      This leaves me with more questions than answers...


      Here is the API reference for the copy operation that I found.



      How do I go about forming the get-ciview .ExtensionData command to do this?

      How do I figure out what inputs are needed and collect them for inclusion in the command?


      Right now I'm just trying to figure out how to identify the objects I need in the ExtensionData space. Any pointers or suggestions on doing this are welcome!




        • 1. Re: Do "Copy to Catalog" via powercli looking for clues...
          bgarner Hot Shot

          Some progress today..

          Setup grab some of the needed objects.

          $copyme = get-civmtemplate -catalog "Origin" -name centos7
          $targetCatalog = get-catalog -name "RELEASE"
          $targetCatalogId = $targetCatalog.id
          $targetCatalogCiview = get-ciview -id $targetCatalogId
          $catalogEd = $targetCatalog.ExtensionData

          Build out what I think is needed as a new object to pass to the copy function.

          $sourceVapp = New-Object VMware.VimAutomation.Cloud.Views.Task
          $sourceVapp.id = $copyme.id
          $sourceVapp.name = "centTest"
          $sourceVapp.description = "test clone"


          First stab at building the actual command to copy the template.



          Error returned..

          Exception calling "Copy_Task" with "1" argument(s): "Bad request  - Bad request  - Error on line 1 of document  : Premature end of file. Nested exception: Premature end of file."                                                                         
          At line:1 char:1                                                                                                                                                                                                                                           
          + $catalogEd.copy_task($sourceVapp)                                                                                                                                                                                                                        
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                        
              + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException                                                                                                                                                                              
              + FullyQualifiedErrorId : CloudException
          • 2. Re: Do "Copy to Catalog" via powercli looking for clues...
            bgarner Hot Shot

            What is the deal with methods that say "void" in front of them? Assuming not to use those ones?

            Copy                              Method     void Copy(VMware.VimAutomation.Cloud.Views.Reference source, string name, string description)                                                                                                                                                                                                                                                                                                   

            Ok looks like I'm not building the correct objects to pass.

            Here is the copy_task method I'm attempting to use.

            Copy_Task   Method     VMware.VimAutomation.Cloud.Views.Task Copy_Task(VMware.VimAutomation.Cloud.Views.Reference source, string name, string description), VMware.VimAutomation.Cloud.Views.Task Copy_Task(VMware.VimAutomation.Cloud.Views.CopyOrMoveCatalogItemParams copyOrMoveCatalogItemParams)                                                                                                                  


            What is the deal with multiple descriptions on this line?

            Which object needs to be passed to copy_task()?

            • 3. Re: Do "Copy to Catalog" via powercli looking for clues...
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              The void in front means these methods do not return anything.


              The multiple descriptions mean that you can call the method with different numbers/types of parameters.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Do "Copy to Catalog" via powercli looking for clues...
                bgarner Hot Shot

                Ok I got it sorted out finally..


                Tip one use search-cloud to find the specific object types you need. Also if you're not seeing some objects add "admin" in front of the query type. The other thing was this VMware.VimAutomation.Cloud.Views.CopyOrMoveCatalogItemParams object. Getting that built with the correct values is key. Here is what ended up working for me.


                $copyme = search-cloud -querytype admincatalogitem -name centos7 -Filter 'CatalogName==Origin'
                $targetCatalog = search-cloud -querytype admincatalog -name "RELEASE"
                $catalogEd = (get-catalog $targetCatalog).ExtensionData
                $copyParms = New-Object VMware.VimAutomation.Cloud.Views.CopyOrMoveCatalogItemParams
                $copyParms.source = $copyme.id
                $copyParms.name = "centos7"