ONTAP Rest API Discussions

Highlighted

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

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.

 

 

 

 

 

2 REPLIES 2
Highlighted

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

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

Highlighted

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

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

Check out the KB!
NetApp Insights To Action
All Community Forums