HP OneView Manual del usuario

Página 282

Advertising
background image

<#
.DESCRIPTION
Attempts to send a web request to the appliance and obtain an 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

# use setup-request to issue the REST request to login and get the response
try
{
$loginResponse = setup-request -Uri $fullLoginUri -method "POST" -accept "application/json" -contentType
"application/json" -Body $body
if ($loginResponse -ne $null)
{
$loginResponse | convertFrom-Json
}
}
catch [System.Exception]
{
if ($global:interactiveMode -eq 1)
{
Write-Host $error[0].Exception.Message
}
else
{
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $error[0].Exception.Message

}
}
}

##### Executing backup ######
function backup-Appliance ([string]$authValue,[string]$hostname)
{
<#
.DESCRIPTION
Gives the appliance the command to start creating a backup

.PARAMETER authValue
The authorized sessionID given by login-appliance

.PARAMETER hostname
The location of the appliance to connect to (in https://{ipaddress} format)

.INPUTS
None, does not accept piping

.OUTPUTS
The task Resource returned by the appliance, converted to a hashtable object

.EXAMPLE
$taskResource = backup-Appliance $sessionID $hostname
#>

# append the REST Uri for backup to the IP address of the Appliance
$bkupUri = "/rest/backups/"
$fullBackupUri = $hostname + $bkupUri

# create a new webrequest and add the proper headers (new header, auth, is needed for authorization
# in all functions from this point on)
try
{
if ($global:scriptApiVersion -lt $taskResourceV2ApiVersion)

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

Advertising