HP OneView User Manual
Page 289
$rawRestoreResponse = setup-request -uri $fullRestoreUri -method "POST" -accept "application/json" -contentType
"application/json" -authValue $authinfo -Body $body
$restoreResponse = $rawRestoreResponse | convertFrom-Json
return $restoreResponse
}
catch [Net.WebException]
{
Write-Host $_.Exception.message
}
}
##### Check for the status of ongoing restore #####
function restore-status ([string]$authinfo = "foo",[string]$hostname,[object]$restoreResponse,[string]$recoveredUri
= "")
{
<#
.DESCRIPTION
Uses GET requests to check the status of the restore process.
.PARAMETER authinfo
**to be removed once no longer a required header**
.PARAMETER hostname
The appliance to connect to
.PARAMETER restoreResponse
The response body from the restore initiation request.
.PARAMETER recoveredUri
In case of a interruption in the script or connection, the Uri for status is instead obtained through
this parameter.
.INPUTS
None, does not accept piping
.OUTPUTS
None, end of script upon completion or fail.
.EXAMPLE
restore-status *$authinfo* -hostname $hostname -restoreResponse $restoreResponse
or
restore-status -hostname $hostname -recoveredUri $recoveredUri
#>
# append the appropriate URI to the IP address of the Appliance
if ($recoveredUri -ne "")
{
$fullStatusUri = $hostname + $recoveredUri
write-host $fullStatusUri
}
else
{
$fullStatusUri = $hostname + $restoreResponse.uri
}
do
{
try
{
# create a new webrequest and add the proper headers (new header, auth is needed for authorization
$rawStatusResp = setup-request -uri $fullStatusUri -method "GET" -accept "application/json" -contentType
"application/json" -authValue $authinfo
$statusResponse = $rawStatusResp | convertFrom-Json
$trimmedPercent = ($statusResponse.percentComplete) / 5
$progressBar = "[" + "=" * $trimmedPercent + " " * (20 - $trimmedPercent) + "]"
Write-Host "`rRestore progress: $progressBar " $statusResponse.percentComplete "%" -NoNewline
}
catch [Net.WebException]
{
try
{
$errorResponse = $error[0].Exception.InnerException.Response.getResponseStream()
$sr = New-Object IO.StreamReader ($errorResponse)
$rawErrorStream = $sr.readtoend()
$error[0].Exception.InnerException.Response.close()
$errorObject = $rawErrorStream | convertFrom-Json
Write-Host $errorObject.message $errorObject.recommendedActions
}
catch [System.Exception]
{
Write-Host "`r`n" $error[1].Exception
}
return
}
if ($statusResponse.status -eq "SUCCEEDED")
{
Write-Host "`r`nRestore complete!"
return
C.2 Sample restore script 289