ONTAP Rest API Discussions

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

Juluri

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

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

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

Juluri

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

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public