1 Reply Latest reply on May 20, 2013 7:49 AM by CSIEnvironments

    Deleting CIVM from a CIvApp

    CSIEnvironments Enthusiast

      Hi,

       

      I would like to remove a specific CIVM from a CIvApp. The CIvApp is stopped and powered off. The following bit of code works but performance is inconsistent. Sometimes it takes a few seconds, sometimes it takes extremely long to do 1 VM (1min 15 seconds). Even with the PowerCLI XmlSerializers installed. It's more than like it's because I'm using Get-CIVM.

       

      Works:

      $civapp = "Test"
      $civm = Get-CIVM -vApp $civapp -Name "VM1"
      $civm.ExtensionData.Delete()
      

       

       

      I've tried using Search-Cloud but it appears I can't do anything with the object once I found it:

      No ExtensionData property:

      $civm2 = Search-Cloud -QueryType AdminVM -Filter "ContainerName==Test;Name==VM2"
      

       

      I also thought about using Get-CIView and then using RecomposeVApp but I'm not sure what to pass that to delete a VM:

       

      $civapp = "Test"
      $ciview = "get-ciview -ID $civApp.Id"
      $ciview.RecomposeVApp("VM2" ,deleteItem) //Not sure what to do here.
      

       

       

      Or does anyone know of another method to delete CIVM's from a CIvApp via the SDK perhaps? Or maybe those mystical cloud views?


      Thanks!

        • 1. Re: Deleting CIVM from a CIvApp
          CSIEnvironments Enthusiast

          Thanks to some anonymous employee at VMWare I have a solution. It came from an "Internal Thread" so I don't exactly know who you are...Never the less, get that man a bells.

           

          Here is the code I received:

           

          You need to pass $null to all except the deleteItem parameter. Because the overload of RecomposeVApp that you use has too many parameters, I prefer the overload RecomposeVApp_Task(RecomposeVAppParams recomposeVAppParams). The deleteitem should be an array of Reference which has the Href pointing to the VM to be deleted. Here is a sample script:

          $ciVappName = "vApp_administrator_1"

          $vmsToDeleteNames = "vm2", "vm3"

          $civApp = Get-CIVApp $ciVappName

          $vmsToDelete = Get-CIVM -VApp $civApp | ? { $vmsToDeleteNames -contains $_.Name }

          $refsToVmsToDelete = $vmsToDelete | % {

             $ref = New-Object VMware.VimAutomation.Cloud.Views.Reference

             $ref.Href = $_.Href

             $ref

          }

          $recomposeParams = New-Object VMware.VimAutomation.Cloud.Views.RecomposeVAppParams

          $recomposeParams.DeleteItem = $refsToVmsToDelete

          $task = $civApp.ExtensionData.RecomposeVApp_Task($recomposeParams)

          # Note that if you need to edit multiple vapps, you can start the tasks for all vapps

          # and wait for the tasks at the end.

          $task.Wait()

           

           

          Thanks who ever you are