Home > Storage > PowerFlex > White Papers > PowerFlex REST API Introduction > Expand storage pool
This example shows the process of adding a device to an SDS and the expansion of a storage pool.
The following function returns the storage pool id using the storage pool name and protection domain name.
import requests
import getpass
#Import our PFxM Authentication function
from pfauth import authenticate
import json
import urllib3
def getSPId(pfxm, accessToken, spname, pdname):
#Get Storage Pool id from Storage Pool name
url = 'https://{pfxm}/api/types/StoragePool/instances/action/queryIdByKey'
payload = json.dumps({
"protectionDomainName": f"{pdname}",
"name": f"{spname}"
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {accessToken}'
}
response = requests.post(url, headers=headers, data=payload, verify=False)
spid = response.text
spid = spid.replace('"','')
print(f'The id for storage pool {spname} is {spid}')
return spid
The following function returns the SDS id, using the name of the SDS as input.
def getSDSId(pfxm, accessToken, sdsname):
#Get SDS id from SDS name
url = f'https://{pfxm}/api/types/Sds/instances/action/queryIdByKey'
payload = json.dumps({
"name": f"{sdsname}"
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {accessToken}'
}
response = requests.post(url, headers=headers, data=payload, verify=False)
sdsid = response.text
sdsid = sdsid.replace('"','')
print(f'The id for SDS {sdsname} is {sdsid}')
return sdsid
The following function adds the device, using the device path to the designated SDS and storage pool.
def addDevice(pfxm, accessToken, devpath, sdsid, spid):
url = f'https://{pfxm}/api/types/Device/instances'
payload = json.dumps({
"deviceCurrentPathname": f"{devpath}",
"storagePoolId": f"{spid}",
"sdsId": f"{sdsid}"
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {accessToken}'
}
response = requests.post(url, headers=headers, data=payload, verify=False)
devicecode = response.text
return devicecode
The main program sets the variables and calls each function.
#PFxM host
pfxm = 'pfmp.powerflex.lab'
#Prompt user for PowerFlex Manager username and password.
username = input('Enter PowerFlex Manager username:')
password = getpass.getpass('Enter password:')
#Pass variables to the authenticate() function.
accessToken = authenticate(username, password)
#Variables
spname = 'sp1'
pdname = 'pd1'
sdsname = 'sds1'
devpath = '/dev/sdb'
#Call functions
accessToken = authenticate(username, password)
spid = getSPId(spname, pdname)
sdsid = getSDSId(sdsname)
devicecode = addDevice(devpath, sdsid, spid)
print(f'Device {devpath} successfully added to SDS {sdsname} and storage pool {spname}')