Home > Storage > PowerFlex > White Papers > PowerFlex REST API Introduction > Add file system tree quota
This use case demonstrates the steps required to add a tree quota to a NAS file system.
We can obtain the file system id using the /rest/v1/file-systems endpoint. We need to include a select statement and select the file system id. This example assumes that there is a single file system and that quotas have already been enabled on the file system.
#Import modules
import json
import requests
import urllib3
from pfauth import authenticate
def getFsId(pfxm, accessToken):
#Get Sfile system id
url = f'https://{pfxm}/rest/v1/file-systems?select=id'
payload = {}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {accessToken}'
}
response = requests.get(url, headers=headers, data=payload, verify=False)
responseJson = response.json()
responseStr = json.dumps(responseJson, indent=2)
jsonObject = json.loads(responseStr)
fsid = (jsonObject[0]['id'])
return fsid
This function creates the file system tree quota. We need the following parameters as input to our function.
def createTreequota(pfxm, accessToken, fsid, path, userQuota, treeHardlimit, treeSoftlimit, gracePeriod):
url = f'https://{pfxm}/rest/v1/file-tree-quotas'
payload = json.dumps({
"file_system_id": f"{fsid}",
"path": f"{path}",
"is_user_quotas_enforced": userQuota,
"hard_limit": treeHardlimit ,
"soft_limit": treeSoftlimit,
"grace_period": gracePeriod
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {accessToken}'
}
response = requests.post(url, headers = headers, data = payload, verify = False)
return response
The main program sets the variables and calls each function.
pfxm = 'pfmp.powerflex.lab'
#PFxM user
username = 'admin'
password = 'P@ssword123'
#Pass variables to the authenticate() function.
accessToken = authenticate(username, password)
#Get the id of the file system
fsid = getFsId(pfxm, accessToken)
path = '/share1'
userQuota = False
treeHardlimit = 314572800
treeSoftlimit = 209715200
gracePeriod = 604800
treeQuota = createTreequota(pfxm, accessToken, fsid, path, userQuota, treeHardlimit, treeSoftlimit, gracePeriod)