HP OneView Manual del usuario

Página 295

Advertising
background image

None, does not accept piping

.OUTPUTS
The response body to the upload post request.

.EXAMPLE
$uploadResponse = uploadTo-appliance $filePath $sessionID $hostname $fileName
#>

$uploadUri = "/rest/backups/archive"
$fullUploadUri = $hostname + $uploadUri
$curlUploadCommand = "curl -s -k -X POST " +
"-H 'content-type: multipart/form-data' " +
"-H 'accept: application/json' " +
"-H 'auth: " + $authinfo + "' " +
"-H 'X-API-Version: $global:scriptApiVersion' " +
"-F file=@" + $filepath + " " +
$fullUploadUri

Write-Host "Uploading backup file to appliance, this may take a few minutes..."
try
{
$testCurlSslOption = curl -V
if ($testCurlSslOption -match "SSL")
{
$rawUploadResponse = invoke-expression $curlUploadCommand
if ($rawUploadResponse -eq $null)
{
return
}
$uploadResponse = $rawUploadResponse | convertFrom-Json

if ($uploadResponse.status -eq "SUCCEEDED")
{
Write-Host "Upload complete."
return $uploadResponse
}
else
{
Write-Host $uploadResponse
return
}
}
else
{
Write-Host "Version of curl must support SSL to get improved upload performance."
return uploadTo-appliance-without-curl $filepath $authinfo $hostname $backupFile
}
}
catch [System.Management.Automation.CommandNotFoundException]
{
return uploadTo-appliance-without-curl $filepath $authinfo $hostname $backupFile
}
catch [System.Exception]
{
Write-Host "Not able to upload backup"
Write-Host $error[0].Exception
return
}
}

##### Upload the backup file to the appliance without using the curl command #####
function uploadTo-appliance-without-curl
([string]$filepath,[string]$authinfo,[string]$hostname,[string]$backupFile)
{
<#
.DESCRIPTION
Attempts to upload a backup to the appliance without using curl.

.PARAMETER filepath
The absolute filepath to the backup file.

.PARAMETER authinfo
The authorized session ID returned by the login request

.PARAMETER hostname
The appliance to connect to

.PARAMETER backupFile
The name of the file to upload. Only used to tell the server what file is contained in the post
request.

.INPUTS
None, does not accept piping

.OUTPUTS
The response body to the upload post request.

C.2 Secuencia de comandos de restauración de ejemplo 295

Advertising