NetApp ONTAP Python Client Library

9.18.1.0 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to an ONTAP cluster using environment variables for credentials and retrieve basic cluster information (name and UUID). It sets `verify=False` for simplicity in the example, but `verify=True` and proper certificate handling are recommended for production environments.

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}")

view raw JSON →