beautypg.com

HP OneView User Manual

Page 310

background image

}
if ($statusResponse.status -eq "FAILED")
{
Write-Host "`r`nRestore failed! System should now undergo a reset to factory defaults."
}
Start-Sleep 10
} while ($statusResponse.status -eq "IN_PROGRESS")

return
}

##### Recovers Uri to the restore resource if connection lost #####
function recover-restoreID ([string]$hostname)
{
<#
.DESCRIPTION
Uses GET requests to check the status of the restore process.

.PARAMETER hostname
The appliance to end the request to.

.INPUTS
None, does not accept piping

.OUTPUTS
The Uri of the restore task in string form.

.EXAMPLE
$reacquiredUri = recover-restoredID $hostname
#>

$idUri = "/rest/restores/"
$fullIdUri = $hostname + $idUri
try
{
$rawIdResp = setup-request -uri $fullIdUri -method "GET" -contentType "application/json" -accept
"application/json" -authValue "foo"
$idResponse = $rawIdResp | convertFrom-Json
}
catch [Net.WebException]
{
$_.Exception.message
return
}
return $idResponse.members[0].uri
}

function setup-request ([string]$uri,[string]$method,[string]$accept,[string]$contentType =
"",[string]$authValue="0", [object]$body = $null)
{
<#
.DESCRIPTION
A function to handle the more generic web requests to avoid repeated code in every function.

.PARAMETER uri
The full address to send the request to (required)

.PARAMETER method
The type of request, namely POST and GET (required)

.PARAMETER accept
The type of response the request accepts (required)

.PARAMETER contentType
The type of the request body

.PARAMETER authValue
The session ID used to authenticate the request

.PARAMETER body
The message to put in the request body

.INPUTS
None

.OUTPUTS
The response from the appliance, typically in Json form.

.EXAMPLE
$responseBody = setup-request -uri https://10.10.10.10/rest/doThis -method "GET" -accept "application/json"

#>
try
{
[net.httpsWebRequest]$request = [net.webRequest]::create($uri)
$request.method = $method
$request.accept = $accept

$request.Headers.Add("Accept-Language: en-US")
if ($contentType -ne "")
{
$request.ContentType = $contentType
}

310

Backup and restore script examples