1 Reply Latest reply: Jul 21, 2015 8:43 AM by Julian Cates RSS

    Powershell: Remove a Volume that is in a VolumeCollection?

    Jeffrey Adams Wayfarer

      Hi All!

       

      I have a powershell script that is refreshing volumes, but has one flaw.

      I want to drop a volume (let's say for a test box) and then create a clone from a snapshot (let's say the latest Production Snapshot).

      To delete the volume I have to remove it from the volume collection first.  A pain...and it really isn't automated this way.

      So it would be great if I could remove the volume from the powershell script or force the delete on the volume.

       

      Has anybody done this?

      Any help would be appreciated.

       

      Thanks,

      Jeff

        • Re: Powershell: Remove a Volume that is in a VolumeCollection?
          Julian Cates Adventurer

          Hi Jeff,

           

          In NimbleOS 2.3, there are REST APIs available that you can use to do exactly this.  (I have a blog post coming soon that explains this in more detail.)  The following PowerShell code will call the API and do exactly what you need.  It first modifies the volume to take it offline and set its volcoll id to an empty string. This disassociates the volume from the volcoll.  Then it makes another API call to delete the volume once it's offline:

           

          param([string]$vol="")

          if ($vol -eq "") {

            write-host "`n`nUsage: delete-volume <VOLUME>`n`n";

            exit

          }

           

          ###########################

          # Enable HTTPS

          ###########################

           

          [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

           

          ###########################

          # Get Token

          ###########################

           

          $array = "<ARRAYNAME>"

          $username = "admin"

          $password = "<PASSWORD>"

           

          $data = @{

              username = $username

              password = $password

          }

           

          $body = convertto-json (@{ data = $data })

           

          $uri = "https://" + $array + ":5392/v1/tokens"

          $token = Invoke-RestMethod -Uri $uri -Method Post -Body $body

          $token = $token.data.session_token

           

          ###########################

          # Find a Volume by Name

          ###########################

           

          $header = @{ "X-Auth-Token" = $token }

          $uri = "https://" + $array + ":5392/v1/volumes"

          $volume_list = Invoke-RestMethod -Uri $uri -Method Get -Header $header

           

          foreach ($volume_id in $volume_list.data.id){

           

            $uri = "https://" + $array + ":5392/v1/volumes/" + $volume_id

            $volume = Invoke-RestMethod -Uri $uri -Method Get -Header $header

           

            if ($volume.data.name -eq $vol){

            $vol_id = $volume.data.id

            }

          }

           

          write-host "`n`nDeleting volume $vol with ID: $vol_id`n";

           

          #########################################

          # Offline a Volume and Disassociate from volcoll

          #########################################

           

          $data = @{

           

            online = "false"

            force = "true"

            volcoll_id = ""

          }

           

          $body = convertto-json (@{ data = $data })

          $header = @{ "X-Auth-Token" = $token }

          $uri = "https://" + $array + ":5392/v1/volumes/" + $vol_id

          $result = Invoke-RestMethod -Uri $uri -Method Put -Body $body -Header $header

           

          ###########################

          # Delete a Volume

          ###########################

           

          $header = @{ "X-Auth-Token" = $token }

          $uri = "https://" + $array + ":5392/v1/volumes/" + $vol_id

          $result = Invoke-RestMethod -Uri $uri -Method Delete -Header $header

           

          Cheers,

           

          Julian