ONTAP Rest API Discussions
ONTAP Rest API Discussions
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
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()}')
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()}')
Thank you. How can i use python client library using session object instead of making direct rest API call ?
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?
Thanks, this helped
response = connection.session.get(f'https://{host}/api/cluster/')