Skip to content

Repository files navigation

NGX Storage Manager API v2 SDK — Python

Unified Python client for the NGX Storage Manager API v2. One client owns auth, TLS, bounded 725-busy retry, controller failover, and work-mode selection; every driver (Cinder FC, Cinder iSCSI, Cinder NFS) imports this SDK instead of writing its own NGX HTTP client.

Mirrors the Go SDK (ngxstorage-sdk-go) with the same architecture and canonical backend fields.

Features

  • API-key auth (Bearer) — never logged
  • Controller failover with work-mode resolution (single-master, master-ready, cluster)
  • Bounded 725-busy retry (6 attempts, 10–30s exponential backoff)
  • Transport failover replays safe methods (GET/DELETE) only — POST never replayed
  • Optional TLS verification (skipped by default — NGX Storage Arrays are self-signed)
  • Pluggable BaseMiddleware chain
  • Per-resource services covering every API v2 group

Install

pip install -e .

Quick start

fromngxstorageimportNGXClient, ClientConfigclient=NGXClient(ClientConfig(
controllers=["192.168.1.201", "192.168.1.202"],
api_key="your-api-key",
pool_name="pool1",
# NGX Storage Arrays are self-signed; verification is skipped by default.# Provide ca_bundle to enforce a customer trust chain.insecure_skip_verify=True,
))
# Resolve the serving controller + pool once before serving traffic.client.refresh_controller()
# LUN (block)lun=client.luns.create("vol1", 100)
client.luns.expand(lun["id"], 200)
client.luns.delete(lun["id"])
# NFS share (created with export disabled)share=client.shares.create("share1", 100*1024**3)
client.shares.set_export_enabled(share["id"], True)
# Snapshot + clonesnap=client.snapshots.create(lun["id"], "snap1")
clone_id=client.snapshots.clone(snap["id"], "clone1")
# iSCSI target + CHAPclient.iscsi_targets.add_lun(target_id, lun["id"], owner)
client.auth_groups.add_chap(group_id, "user", "pass")
# Pool capacity / cluster statusavailable, reserved=client.pools.get_configured_capacity()
cluster=client.status.cluster()

Configuration

ClientConfig fields:

FieldDescription
controllers1–2 controller IPs/hostnames (required)
api_keyBearer token (required, never logged)
pool_nameCanonical pool name; empty skips pool ownership checks
insecure_skip_verifySkip TLS verification (default True for self-signed NGX)
ca_bundleOptional path to a customer CA bundle
middlewaresBaseMiddleware chain, outermost-first
timeoutPer-request timeout (default 60s)
max_retries / base_delay / max_delay725-busy retry bounds

ClientConfig.__repr__ redacts the API key.

Services

ServiceAccessorOperations
LUNclient.lunscreate, get, list, delete, modify, expand
Share (NFS)client.sharescreate, get, list, list_names, delete, modify, expand, set_export_enabled, set_read_only
Snapshotclient.snapshotscreate, get, list, list_detail, delete, clone, restore
FC targetclient.fc_targetslist, get, add_lun, remove_lun
iSCSI targetclient.iscsi_targetslist, get, create, delete, add_lun, remove_lun
Auth groupclient.auth_groupscreate, get, list, delete, add_chap, delete_chap
Portal groupclient.portal_groupslist, get, create, delete
Poolclient.poolslist, get, overview, get_configured_capacity
Statusclient.statuscluster, services, capacity, iops, bandwidth

Error handling

The SDK raises typed exceptions; classify without string matching:

fromngxstorageimportAPIErrorfromngxstorage.errorsimportis_not_found, is_busy, is_already_existstry:
client.luns.delete(lun_id)
exceptAPIErrorasexc:
ifis_not_found(exc):
pass# idempotent successelifis_busy(exc):
pass# 725, already retried

APIError carries status_code, code, message, method, endpoint. Sentinels: PoolNotFound, ClusterNotReady, TransportError.

Security

  • The API key, CHAP passwords, and S3 secret keys are never logged.
  • TLS verification is optional: skipped by default because NGX Storage Arrays use self-signed certificates and most customers have no private CA/DNS. Pass ca_bundle to enforce a customer trust chain.
  • POST mutations are never replayed after an ambiguous transport failure.

Canonical backend fields

Reads use the live backend JSON contract (nested capacity.soft_quota, exports.nfs.enabled/read_only); writes use the canonical flat fields (soft_quota, nfs_export, nfs_read_only). The SDK does not probe alternate names.

Test

pip install -e ".[test]"
PYTHONPATH=src pytest

License

Apache-2.0

About

Unified NGX Storage Manager API v2 Python SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages