NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform.
You will still be able to view content, but posting and replying will be temporarily disabled.
To learn more, please review the information in this blog post.

ONTAP Rest API Discussions

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

Juluri
4,543 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
4,510 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
4,511 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
4,500 Views

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

Public