This use case shows the process of expanding a volume. PowerFlex volumes can only be expanded, and the size must be in increments of 8 GB. Expanding a volume consists of the following steps:
The following code is used to authenticate with PowerFlex Manager and initialize variables.
#PFMP ingress
$PFMPhost = 'pfxm.powerflex.lab'
#Volume name
$Volume = 'vol001'
#Authentication
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Content-Type", "application/json")
$Headers.Add("Accept", "application/json")
$CredJson = "{`"username`": `"admin`", `"password`": `"Password`"}"
$Response = Invoke-RestMethod "https://$PFMPhost/rest/auth/login" -Method POST -Headers $Headers -Body $CredJson
$accessToken = $Response.access_token
#Create authentication header for use in API calls
$AuthHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$AuthHeader.Add("Content-Type", "application/json")
$AuthHeader.Add("Accept", "application/json")
$AuthHeader.Add("Authorization", "Bearer $accessToken")
Use the following endpoints to retrieve the id and current size of the volume to be expanded.
#Query volume id from name
$VolBody = "{`"name`": `"$Volume`"}"
$VolumeID = (Invoke-RestMethod -Uri "https://$PFMPhost/api/types/Volume/instances/action/queryIdByKey" -Method POST -Body $VolBody -Headers $AuthHeader)
#Get current volume size
$Volumeobject = (Invoke-RestMethod -Uri "https://$PFMPhost/api/instances/Volume::$VolumeID" -Method GET -Headers $AuthHeader)
$CurrentsizeGB = $Volumeobject.sizeInKb/1048576
Write-Output "Current volume size is $CurrentsizeGB GB"
The following code prompts the user for a new volume size, expands the volume, and displays the new size of the volume.
#Prompt user for expanded size of volume in GB
$Requestedsize = Read-Host 'Enter new volume size in multiples of 8 (GB)'
#Expand volume
$NewSize ="{`"sizeInGB`":`"$Requestedsize`"}"
Invoke-RestMethod -Uri "https://$PFMPhost/api/instances/Volume::$VolumeID/action/setVolumeSize" -Method POST -Body $NewSize -Headers $AuthHeader
#Get current volume size and display to user
$Newvolumeobject = (Invoke-RestMethod -Uri "https://$PFMPhost/api/instances/Volume::$VolumeID" -Method GET -Headers $AuthHeader)
$Newvolumesize = $Newvolumeobject.sizeInKb/1048576
Write-Output "New size of volume $Volume is $Newvolumesize GB"