HP OneView Manual del usuario

Página 288

Advertising
background image

if ($authValue -ne "")
{
$request.Headers.Item("auth") = $authValue
}
$request.Headers.Item("X-API-Version") = $global:scriptApiVersion
if ($body -ne $null)
{
$requestBodyStream = New-Object IO.StreamWriter $request.getRequestStream()
$requestBodyStream.WriteLine($body)
$requestBodyStream.flush()
$requestBodyStream.close()
}

# attempt to connect to the Appliance and get a response
[net.httpsWebResponse]$response = $request.getResponse()

if ($returnLocation)
{
$taskUri = $response.getResponseHeader("Location")

$response.close()
return $taskUri
}
else
{
# response stored in a stream
$responseStream = $response.getResponseStream()
$sr = New-Object IO.StreamReader ($responseStream)

#the stream, which contains a json object, is read into the storage variable
$rawResponseContent = $sr.readtoend()
$response.close()
return $rawResponseContent
}
}
catch [Net.WebException]
{
$errorMessage = $error[0].Exception.message

#Try to get more information about the error
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
if (($errorObject.message.length -gt 0) -and
($errorObject.recommendedActions.length -gt 0))
{
$errorMessage = $errorObject.message + " " + $errorObject.recommendedActions
}
}
catch [System.Exception]
{
#Use exception message
}

if ($isSilent) {
throw $errorMessage
}
elseif ($global:interactiveMode -eq 1)
{
Write-Host $errorMessage
}
else
{
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $errorMessage
}

#No need to rethrow since already recorded error
return
}
}

##### Start of function calls #####

#gets the credentials from user, either manual entry or from file
$savedLoginJson = queryfor-credentials $args[0]
if ($savedLoginJson -eq $null)
{
#if an error occurs, it has already been logged in the queryfor-credentials function
return
}

#extracts needed information from the credential json

288 Ejemplos de secuencias de comandos de copia de seguridad y restauración

Advertising