Nutanix Lcm Versioned APIs
Project description
Python Client For Nutanix Lcm Versioned APIs
The Python client for Nutanix Lcm Versioned APIs is designed for Python client application developers offering them simple and flexible access to APIs that manage Infrastructure, Software and Firmware Upgrades.
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.a1
- Package version: 4.0.1a1
Requirements.
Python 3.6, 3.7, and 3.8 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-lcm-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-lcm-py-client
Then import the package:
import ntnx_lcm_py_client
Getting Started
Configuration
The python client for Nutanix Lcm Versioned APIs can be configured with the following parameters
Parameter | Description | Required | Default Value |
---|---|---|---|
host | IPv4/IPv6 address or FQDN of the cluster to which the client will connect to | Yes | N/A |
port | Port on the cluster to which the client will connect to | No | 9440 |
username | Username to connect to a cluster | Yes | N/A |
password | Password to connect to a cluster | Yes | N/A |
debug | Runs the client in debug mode if specified | No | False |
verify_ssl | Verify SSL certificate of cluster the client will connect to | No | True |
max_retry_attempts | Maximum number of retry attempts while connecting to the cluster | No | 5 |
backoff_factor | A backoff factor to apply between attempts after the second try. | No | 3 |
logger_file | File location to which debug logs are written to | No | N/A |
timeout | Global timeout in milliseconds for all operations | No | 30000 |
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)
Authentication
Nutanix APIs currently support HTTP Basic Authentication only, and the Python client can be configured using the username and password parameters to send Basic headers along with every request.
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 python 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 using the following formula:
{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
client = ApiClient(configuration=config)
Usage
Invoking an operation
# Initialize the API
bundles_api_instance = BundlesApi(api_client=client) # client configured in previous step
extId = 'extId_example' # UUID.
# Get bundle details for bundle UUID.
try:
api_response = bundles_api_instance.get_bundle(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
bundles_api_instance = BundlesApi(api_client=client) # client configured in previous step
extId = 'extId_example' # UUID.
# Get bundle details for bundle UUID.
try:
api_response = bundles_api_instance.get_bundle(extId)
except ApiException as e:
# Extract E-Tag Header
etag_value = ApiClient.get_etag(api_response)
# Update bundle information for a specified UUID
try:
# The body parameter in the following operation is received from the previous GET request's response which needs to be updated.
api_response = bundles_api_instance.put_bundle(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.
Parameter | Description |
---|---|
_page | specifies 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 be set to its nearest bound. In other words, a page number of less than 0 would be set to 0 and a page number greater than the total available pages would be set to the last page. |
_limit | specifies 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 be set to the default maximum number of records, which is 100. |
_filter | allows 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. |
_orderby | allows 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. |
_select | allows 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. |
_expand | allows clients to request related resources when a resource that satisfies a particular request is retrieved. Each expand 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. Allowed system query options are $filter,$select, $orderby. |
# Initialize the API
bundles_api_instance = BundlesApi(api_client=client) # client configured in previous step
extId = 'extId_example' # UUID.
# Query list of bundles
try:
api_response = bundles_api_instance.get_bundles(
_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 Nutanix proprietary license. Full license text is available in LICENSE.
Contact us
In case of issues please reach out to us at the mailing list
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ntnx-lcm-py-client-4.0.1a1.tar.gz
.
File metadata
- Download URL: ntnx-lcm-py-client-4.0.1a1.tar.gz
- Upload date:
- Size: 85.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14c64b3c287c4f3cb21b0be64007fc9c762b397796c49d58d9c2fe0ff2abc6d4 |
|
MD5 | 387ec8b52b69ebd26c15b1a3b6df98ca |
|
BLAKE2b-256 | 13cd420e42ee21d5c2cae96ff5bd7adf48a35e5d62852fda2b5445ecab1dc278 |
File details
Details for the file ntnx_lcm_py_client-4.0.1a1-py3-none-any.whl
.
File metadata
- Download URL: ntnx_lcm_py_client-4.0.1a1-py3-none-any.whl
- Upload date:
- Size: 326.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bac20a15d6d7967aa6dd7d8d578e02402e8b042c32f8a5ede83067c078ca3c9 |
|
MD5 | 07272a4d30b2aebffe83f766d4a30e0b |
|
BLAKE2b-256 | 30b3ad2b152c7106e0c17de9d50dd1e07b1a19056720985b0a3d6eb5c8aadd57 |