HP OneView Manual del usuario

Página 294

Advertising
background image

}
else
{
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $error[0].Exception.Message

}
}
}

##### Send the login request to the appliance #####
function login-appliance ([string]$username,[string]$password,[string]$hostname)
{
<#
.DESCRIPTION
Attempts to send a web request to the appliance and obtain a authorized sessionID.

.PARAMETER username
The username to log into the remote appliance

.PARAMETER password
The correct password associated with username

.PARAMETER hostname
The appliance address to send the request to (in https://{ipaddress} format)

.INPUTS
None, does not accept piping

.OUTPUTS
Outputs the response body containing the needed session ID.

.EXAMPLE
$authtoken = login-appliance $username $password $hostname
#>

# the particular URI on the Appliance to request an "auth token"
$loginURI = "/rest/login-sessions"

# append the URI to the end of the IP address to obtain a full URI
$fullLoginURI = $hostname + $loginURI
# create the request body as a hash table, then convert it to json format
$body = @{ userName = $username; password = $password } | convertTo-json

try
{
# create a new webrequest object and give it the header values that will be accepted by the Appliance, get
response
$loginRequest = setup-request -Uri $fullLoginURI -method "POST" -accept "application/json" -contentType
"application/json" -Body $body
Write-Host "Login completed successfully."
}
catch [System.Exception]
{
Write-Host $_.Exception.message
Write-Host $error[0].Exception
return
}

#the output for the function, a hash table which contains a single value, "sessionID"
$loginRequest | convertFrom-Json
return
}

##### Upload the backup file to the appliance #####
function uploadTo-appliance ([string]$filepath,[string]$authinfo,[string]$hostname,[string]$backupFile)
{
<#
.DESCRIPTION
Attempts to upload a backup file to the appliance. Tries to use the curl command.
The curl command has significantly better performance especially for large backups.
If curl isn't installed, invokes uploadTo_appliance-without-curl to upload the file.

.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

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

Advertising