ONTAP Rest API Discussions

How to pass policy.id as variable in GET request on /protocols/nfs/export-policies/{policy.id}/rules

Juluri
2,649 Views

I have an export-policy with policy.id as 8179334014 and would like to retrieve all the rules information under this export-policy and I can do this if I run below command

 

response = requests.get('https://cluster-lif/api/protocols/nfs/export-policies/{8179334014}/rules', auth = ('xxxx', 'xxxx'), headers = {'accept' : 'application/hal+json' }, verify = False)

 

However if I want to pass variable instead of value "8179334014" say like below.

 

policy_id =  8179334014

response = requests.get('https://cluster-lif/api/protocols/nfs/export-policies/{policy_id}/rules', auth = ('xxxx', 'xxxx'), headers = {'accept' : 'application/hal+json' }, verify = False)

 

It doesnt work as its treating policy_id  as value,  looking for help to find a solution for this.

 

 

 

 

 

1 ACCEPTED SOLUTION

Twesha
2,616 Views

You can use an f-string if you're using python 3.6 or above. So, you would do something like:

response = requests.get(url=f"https://{clus_lif}/api/protocols/nfs/export-policies/{policy_id}/rules", auth = ("***", "****"), headers={"accept":"application/hal+json"}, verify=False), where clus_lif and policy_id are variables in my script. I gave this a shot and it worked for me.

 

Also, in case you're not aware, I wanted to share that we have a netapp_ontap python module that you can use if you're writing scripts that access the ONTAP REST API. It'll definitely make your life a lot easier and is more object oriented. See info here: https://pypi.org/project/netapp-ontap/.

View solution in original post

2 REPLIES 2

Twesha
2,617 Views

You can use an f-string if you're using python 3.6 or above. So, you would do something like:

response = requests.get(url=f"https://{clus_lif}/api/protocols/nfs/export-policies/{policy_id}/rules", auth = ("***", "****"), headers={"accept":"application/hal+json"}, verify=False), where clus_lif and policy_id are variables in my script. I gave this a shot and it worked for me.

 

Also, in case you're not aware, I wanted to share that we have a netapp_ontap python module that you can use if you're writing scripts that access the ONTAP REST API. It'll definitely make your life a lot easier and is more object oriented. See info here: https://pypi.org/project/netapp-ontap/.

Juluri
2,606 Views

Thats Super!!!, its working, thank you very much Twesha.

Public