Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ntnx-opsmgmt-py-client

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntnx-opsmgmt-py-client

Nutanix Cloud Management Platform APIs

  • 4.0.1
  • PyPI
  • Socket score

Maintainers
1

Python Client For Nutanix Cloud Management Platform APIs

The Python client for Nutanix Cloud Management Platform APIs is designed for Python client application developers offering them simple and flexible access to APIs that provide functionalities that are common to APIs in namespaces aiops, devops, secops, finops.

Features

  • Invoke Nutanix APIs with a simple interface.
  • Handle Authentication seamlessly.
  • Reduce boilerplate code implementation.
  • Use standard methods for installation.

Version

  • API version: v4.0
  • Package version: 4.0.1

Requirements.

Python 3.6, 3.7, 3.8 and 3.9 are fully supported and tested.

Installation & Usage

Installing in a virtual environment

virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions. virtualenv can help you install this client without needing system install permissions. It creates an environment that has its own installation directories without sharing libraries with other virtualenv environments or the system installation.

Mac/Linux

To install virtualenv via pip run:

$ pip3 install virtualenv

Create the virtualenv and activate it

$ virtualenv -p python3 <my-env>
$ source <my-env>/bin/activate

Install the Nutanix client into the virtualenv

<my-env>/bin/pip install ntnx-opsmgmt-py-client
Windows

To install virtualenv via pip run:

> pip install virtualenv

Create the virtualenv and activate it

> virtualenv <my-env>
> myenv\Scripts\activate

Install the Nutanix SDK into the virtualenv

<your-env>\Scripts\pip.exe install ntnx-opsmgmt-py-client

Then import the package:

import ntnx_opsmgmt_py_client

Getting Started

Configuration

The python client for Nutanix Cloud Management Platform APIs can be configured with the following parameters

ParameterDescriptionRequiredDefault Value
schemeURI scheme for connecting to the cluster (HTTP or HTTPS using SSL/TLS)Nohttps
hostIPv4/IPv6 address or FQDN of the cluster to which the client will connect toYesN/A
portPort on the cluster to which the client will connect toNo9440
usernameUsername to connect to a clusterYesN/A
passwordPassword to connect to a clusterYesN/A
debugRuns the client in debug mode if specifiedNoFalse
verify_sslVerify SSL certificate of cluster the client will connect toNoTrue
max_retry_attemptsMaximum number of retry attempts while connecting to the clusterNo5
backoff_factorA backoff factor to apply between attempts after the second try.No3
max_redirectsMaximum number of redirects to followNo10
logger_fileFile location to which debug logs are written toNoN/A
connect_timeoutConnection timeout in milliseconds for all operationsNo30000
read_timeoutRead timeout in milliseconds for all operationsNo30000
download_directoryDirectory where downloaded files will be stored inNoCurrent Working Directory
download_chunk_sizeChunk size in bytes for files to downloadNo8*1024 bytes
root_ca_certificate_filePEM encoded Root CA certificate file pathNoN/A
client_certificate_filePEM encoded client certificate file pathNoN/A
client_key_filePEM encoded client key file pathNoN/A

Sample Configuration

config = Configuration()
config.host = '10.19.50.27' # IPv4/IPv6 address or FQDN of the cluster
config.port = 9440 # Port to which to connect to
config.username = 'admin' # UserName to connect to the cluster
config.password = 'password' # Password to connect to the cluster
api_client = ApiClient(configuration=config)

Proxy Configuration

config = Configuration()
# Configure the cluster as shown previously along with the following proxy configuration
# ...
config.proxy_scheme = "https"
config.proxy_host = "127.0.0.1"
config.proxy_port = 8080
config.proxy_username = "proxy_admin"
config.proxy_password = "proxy_password"
api_client = ApiClient(configuration=config)

mTLS Configuration

config = Configuration()
# Configure the cluster as shown previously along with the following mTLS configuration
# (use path of your own client certificates)
# ...
config.root_ca_certificate_file = "/home/certs/ca.pem"
config.client_certificate_file = "/home/certs/AdonisService/AdonisService.crt"
config.client_key_file = "/home/certs/AdonisService/AdonisService.key"
api_client = ApiClient(configuration=config)

Authentication

Nutanix APIs currently support two type of authentication schemes:

  • HTTP Basic Authentication - The Python client can be configured using the username and password parameters to send Basic headers along with every request.
  • API Key Authentication - The Python client can be configured to set an API key to send "X-ntnx-api-key" header with every request.
    config = Configuration()
    config.set_api_key('abcde12345')
    api_client = ApiClient(configuration=config)
    

Additional Headers

The python client can be configured to send additional headers on each request.

client = ApiClient(configuration=config)
client.add_default_header(header_name='Accept-Encoding', header_value='gzip, deflate, br')

Retry Mechanism

The client can be configured to retry requests that fail with the following status codes. The numbers of seconds before which the next retry is attempted is determined by the retryInterval:

The client will also redirect requests that fail with 302 - Found to the new location specified in the response header Location. {backoff factor} * (2 * ({number of retries so far} - 1))

config = Configuration()
config.max_retry_attempts = 3 # Max retry attempts while reconnecting on a loss of connection
config.backoff_factor = 3 # Backoff factor to use during retry attempts
config.max_redirects = 3 # Max number of redirects to follow
client = ApiClient(configuration=config)

Usage

Invoking an operation

# Initialize the API
report_config_api_instance = ReportConfigApi(api_client=client) # client configured in previous step
extId = 'extId_example' # UUID.

# Get report configuration information
try:
    api_response = report_config_api_instance.get_report_config_by_id(extId)
except ApiException as e:

Setting headers for individual operations

Headers can be configured globally on the python client using the method to set default headers. However, sometimes headers need to be set on an individual operation basis. Nutanix APIs require that concurrent updates are protected using ETag headers.

# Initialize the API
report_config_api_instance = ReportConfigApi(api_client=client) # client configured in previous step
extId = 'extId_example' # UUID.

# Get report configuration information
try:
    api_response = report_config_api_instance.get_report_config_by_id(extId)
except ApiException as e:

# Extract E-Tag Header
etag_value = ApiClient.get_etag(api_response)

# Update report configuration
try:
    # The body parameter in the following operation is received from the previous GET request's response which needs to be updated.
    api_response = report_config_api_instance.update_report_config_by_id(body, extId, if_match=etag_value) # Use the extracted etag value
except ApiException as e:

List Operations

List Operations for Nutanix APIs support pagination, filtering, sorting and projections. The table below details the parameters that can be used to set the options for pagination etc.

ParameterDescription
_pagespecifies the page number of the result set. Must be a positive integer between 0 and the maximum number of pages that are available for that resource. Any number out of this range will lead to no results being returned.
_limitspecifies the total number of records returned in the result set. Must be a positive integer between 0 and 100. Any number out of this range will lead to a validation error. If the limit is not provided a default value of 50 records will be returned in the result set
_filterallows clients to filter a collection of resources. The expression specified with $filter is evaluated for each resource in the collection, and only items where the expression evaluates to true are included in the response. Expression specified with the $filter must conform to the OData V4.01 URL conventions.
_orderbyallows clients to specify the sort criteria for the returned list of objects. Resources can be sorted in ascending order using asc or descending order using desc. If asc or desc are not specified the resources will be sorted in ascending order by default. For example, 'orderby=templateName desc' would get all templates sorted by templateName in desc order.
_selectallows clients to request a specific set of properties for each entity or complex type. Expression specified with the $select must conform to the OData V4.01 URL conventions. If a $select expression consists of a single select item that is an asterisk (i.e., *), then all properties on the matching resource will be returned.
_expandallows clients to request related resources when a resource that satisfies a particular request is retrieved. Each expanded item is evaluated relative to the entity containing the property being expanded. Other query options can be applied to an expanded property by appending a semicolon-separated list of query options, enclosed in parentheses, to the property name. Permissible system query options are $filter,$select and $orderby.
# Initialize the API
report_config_api_instance = ReportConfigApi(api_client=client) # client configured in previous step
extId = 'extId_example' # UUID.

# Get the list of report configurations
try:
    api_response = report_config_api_instance.list_report_configs(
	                   _page=page, # if page parameter is present
	                   _limit=limit, # if limit parameter is present
	                   _filter=_filter, # if filter parameter is present
	                   _orderby=_orderby, # if orderby parameter is present
	                   _select=select, # if select parameter is present
	                   _expand=expand) # if expand parameter is present
except ApiException as e:

The list of filterable and sortable fields with expansion keys can be found in the documentation here.

API Reference

This library has a full set of API Reference Documentation. This documentation is auto-generated, and the location may change.

License

This library is licensed under Apache 2.0 license. Full license text is available in LICENSE.

Contact us

In case of issues please reach out to us at the mailing list

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc