NetApp ONTAP Python Client Library
The netapp-ontap Python client library simplifies interaction with NetApp ONTAP's REST APIs. It provides services for connection management, asynchronous request processing, and exception handling, enabling Python developers to quickly automate ONTAP deployments. The library's version aligns with the ONTAP major and minor versions it's generated from, with feature releases typically twice a year (Q2 and Q4) and service updates every 4-12 weeks.
Warnings
- breaking Property names in ONTAP REST API that conflict with Python reserved keywords (e.g., 'class') are transposed by the library (e.g., to 'class_'). Similarly, if an action method name conflicts with a resource field, the action method might be renamed (e.g., 'sign()' to 'sign_action()').
- gotcha Client library versions are designed for specific ONTAP releases. A client library with a major version less than the target ONTAP release might not be fully compatible and unable to access newer REST APIs or correctly interpret new fields. The library may ignore unknown fields, return errors, or raise runtime exceptions.
- deprecated The `netapp-lib` library, which supported the legacy ONTAP API (ONTAPI/ZAPI), is no longer maintained. While this `netapp-ontap` library focuses on REST APIs, users transitioning from older automation might encounter references to `netapp-lib`.
- gotcha Newer ONTAP versions (e.g., 9.8 and later for TLS 1.0, 9.12.0 and later for TLS 1.1) disable older TLS protocols by default for new installations. For upgraded systems, TLS 1.0/1.1 might be automatically disabled if FIPS is enabled. This can impact connections from older clients or scripts.
Install
-
pip install netapp-ontap
Imports
- HostConnection
from netapp_ontap import HostConnection
- Cluster
from netapp_ontap import Cluster
from netapp_ontap.resources import Cluster
- Volume
from netapp_ontap.resources import Volume
Quickstart
import os
from netapp_ontap import HostConnection
from netapp_ontap.resources import Cluster
# Set connection details via environment variables for security
ONTAP_HOST = os.environ.get('ONTAP_HOST', 'your_ontap_cluster_ip_or_hostname')
ONTAP_USER = os.environ.get('ONTAP_USER', 'admin')
ONTAP_PASS = os.environ.get('ONTAP_PASS', 'password')
if ONTAP_HOST == 'your_ontap_cluster_ip_or_hostname':
print("Please set ONTAP_HOST, ONTAP_USER, and ONTAP_PASS environment variables.")
exit(1)
try:
# Establish a connection
HostConnection(ONTAP_HOST, username=ONTAP_USER, password=ONTAP_PASS, verify=False)
# Get cluster details
cluster = Cluster.get_collection(fields='uuid,name')[0]
print(f"Successfully connected to ONTAP cluster: {cluster.name} (UUID: {cluster.uuid})")
except Exception as e:
print(f"Error connecting to ONTAP or retrieving cluster details: {e}")