Array Performance and Data Protection
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get snapshots in REST api

 
SOLVED
Go to solution
dustinryan471711
Occasional Visitor

Unable to get snapshots in REST api

I have copied the powershell from the nimble examples. Everything is working, except snapshots. See error in the output at the bottom.




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

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

# Get Token

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

$array = "10.2.25.50"

$username = "admin"

$password = "admin"

$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

"Testing snapshot issue"

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

# Get snapshot List

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

">>snapshot"

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

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

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

foreach ($snapshot_id in $snapshot_list.data.id){

$uri = "https://" + $array + ":5392/v1/snapshots" + $snapshot_id

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

    ">snapshot"

$snapshot.data

}

Testing snapshot issue

>>snapshot

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

At C:\Nimble\nimble_api_collector.ps1:39 char:18

+ ... apshot_list = Invoke-RestMethod -Uri $uri -Method Get -Header $header

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

3 REPLIES
shill119
Occasional Visitor
Solution

Re: Unable to get snapshots in REST api

Got this to work.

It takes the volume and gets snapshots based on the volume, then loops through the results.

"Testing snapshot issue"

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

# Get snapshot List

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

">>snapshot"

$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/snapshots/detail?vol_id=" + $volume_id

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

    foreach ($snapshot_id in $snapshot_list.data.id){

     $uri = "https://" + $array + ":5392/v1/snapshots/" + $snapshot_id

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

        ">snapshot"

     $snapshot.data

    }

}

jcates98
Trusted Contributor

Re: Unable to get snapshots in REST api

It looks like Steve Hill beat me to the punch.

The snapshots API requires you to specify the volume for which you want to retrieve the snapshots.  You cannot retrieve a list of all snapshots on the array in one fell swoop.  As Steve's code shows, the way to pull all snapshots would be to iterate through each volume and retrieve that volume's snapshots.

To be fair, the examples were pulled together when the API was in beta and actually did allow for this.  It looks like perhaps they haven't been updated.  We'll get that fixed.

dustinryan471711
Occasional Visitor

Re: Unable to get snapshots in REST api

Thanks Julian

Sent from my iPhone