Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
how do i create a session object with Python ontap rest api
2023-04-06
09:51 PM
2,779 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Everyone,
How do i create an ONTAP session object with username/password and use it for other rest API calls? Can anyone provide an example with connection object
def session(self) -> requests.Session:
"""A `requests.Session` object which is used for all API calls.
This session is reused for each API call made with this connection. Multiple
requests may therefore be sent through the same TCP connection assuming
the host supports keep-alive.
Returns:
A `requests.Session` object which is used for all API calls.
"""
Solved! See The Solution
1 ACCEPTED SOLUTION
kbhonagiri has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Instead of using the specific resource object to make REST API calls, you can use the ONTAP session object.
Here is an example of using the session object with a username and password to make a simple get call:
from netapp_ontap import HostConnection
from netapp_ontap.resources import Cluster
connection = HostConnection(host, username="username", password="password", verify=False)
response = connection.session.get(f'https://{host}/api/cluster/')
print(f'Status Code: {response.status_code}, Content: {response.json()}')
4 REPLIES 4
kbhonagiri has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Instead of using the specific resource object to make REST API calls, you can use the ONTAP session object.
Here is an example of using the session object with a username and password to make a simple get call:
from netapp_ontap import HostConnection
from netapp_ontap.resources import Cluster
connection = HostConnection(host, username="username", password="password", verify=False)
response = connection.session.get(f'https://{host}/api/cluster/')
print(f'Status Code: {response.status_code}, Content: {response.json()}')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. How can i use python client library using session object instead of making direct rest API call ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I might be misunderstanding your question, but another way to write my previous code above using the specific Cluster object would be:
from netapp_ontap import HostConnection
from netapp_ontap.resources import Cluster
logging.basicConfig(level=logging.DEBUG)
utils.DEBUG=1
with HostConnection(host, username='username', password='password', verify=False):
cluster = Cluster()
cluster.get()
print(cluster)
You can find more examples for all the netapp_ontap PCL resources here: https://library.netapp.com/ecmdocs/ECMLP2884819/html/resources/index.html
Does that answer your question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, this helped
response = connection.session.get(f'https://{host}/api/cluster/')
