Package: ntnx-files-py-client
Python Client For Nutanix Files Versioned APIsThe Python client for Nutanix Files Versioned APIs is designed for Python client application developers offering them simple and flexible access to APIs that manage virtual file servers, create and configure shares for client access, protect them using DR and sync policies, provision storage space and administer security controls.FeaturesInvoke Nutanix APIs with a simple interface.Handle Authentication seamlessly.Reduce boilerplate code implementation.Use standard methods for installation.VersionAPI version: v4.0.a2Package version: 4.0.1a2Requirements.Python 3.6, 3.7, and 3.8 are fully supported and tested.Installation & UsageInstalling in a virtual environmentvirtualenvis 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/LinuxTo install virtualenv via pip run:$pip3installvirtualenvCreate the virtualenv and activate it$virtualenv-ppython3<my-env>
$source<my-env>/bin/activateInstall the Nutanix client into the virtualenv<my-env>/bin/pipinstallntnx-files-py-clientWindowsTo install virtualenv via pip run:>pipinstallvirtualenvCreate the virtualenv and activate it>virtualenv<my-env>
>myenv\Scripts\activateInstall the Nutanix SDK into the virtualenv<your-env>\Scripts\pip.exeinstallntnx-files-py-clientThen import the package:importntnx_files_py_clientGetting StartedConfigurationThe python client for Nutanix Files Versioned APIs can be configured with the following parametersParameterDescriptionRequiredDefault ValuehostIPv4/IPv6 address or FQDN of the cluster to which the client will connect toYesN/AportPort on the cluster to which the client will connect toNo9440usernameUsername to connect to a clusterYesN/ApasswordPassword to connect to a clusterYesN/AdebugRuns the client in debug mode if specifiedNoFalseverify_sslVerify SSL certificate of cluster the client will connect toNoTruemax_retry_attemptsMaximum number of retry attempts while connecting to the clusterNo5backoff_factorA backoff factor to apply between attempts after the second try.No3logger_fileFile location to which debug logs are written toNoN/AtimeoutGlobal timeout in milliseconds for all operationsNo30000Sample Configurationconfig=Configuration()config.host='10.19.50.27'# IPv4/IPv6 address or FQDN of the clusterconfig.port=9440# Port to which to connect toconfig.username='admin'# UserName to connect to the clusterconfig.password='password'# Password to connect to the clusterapi_client=ApiClient(configuration=config)AuthenticationNutanix 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 HeadersThe 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 MechanismThe 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))408 - Request Timeout502 - Bad Gateway503 - Service Unavailableconfig=Configuration()config.max_retry_attempts=3# Max retry attempts while reconnecting on a loss of connectionconfig.backoff_factor=3# Backoff factor to use during retry attemptsclient=ApiClient(configuration=config)UsageInvoking an operation# Initialize the APIadmin_users_api_instance=AdminUsersApi(api_client=client)# client configured in previous stepextId='extId_example'# UUID.# Get admin user by extIdtry:api_response=admin_users_api_instance.get_admin_user_by_ext_id(extId)exceptApiExceptionase:Setting headers for individual operationsHeaders can be configured globally on the python client using themethod to set default headers. However, sometimes headers need to be set on an individual operation basis. Nutanix APIs require that concurrent updates are protected usingETag headers.# Initialize the APIadmin_users_api_instance=AdminUsersApi(api_client=client)# client configured in previous stepextId='extId_example'# UUID.# Get admin user by extIdtry:api_response=admin_users_api_instance.get_admin_user_by_ext_id(extId)exceptApiExceptionase:# Extract E-Tag Headeretag_value=ApiClient.get_etag(api_response)# Update admin usertry:# The body parameter in the following operation is received from the previous GET request's response which needs to be updated.api_response=admin_users_api_instance.update_admin_user(body,extId,if_match=etag_value)# Use the extracted etag valueexceptApiExceptionase:List OperationsList 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 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._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 be set to the default maximum number of records, which is 100._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 theOData V4.01 URLconventions._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 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 APIadmin_users_api_instance=AdminUsersApi(api_client=client)# client configured in previous stepextId='extId_example'# UUID.# List admin userstry:api_response=admin_users_api_instance.get_admin_users(_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 presentexceptApiExceptionase:The list of filterable and sortable fields with expansion keys can be found in the documentationhere.API ReferenceThis library has a full set ofAPI Reference Documentation. This documentation is auto-generated, and the location may change.LicenseThis library is licensed under Nutanix proprietary license. Full license text is available inLICENSE.Contact usIn case of issues please reach out to us at themailing list