Configuration#

The python client for Nutanix Security APIs can be configured with the following parameters

Parameter

Description

Required

Default Value

scheme

URI scheme for connecting to the cluster (HTTP or HTTPS using SSL/TLS)

No

https

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

connect_timeout

Connection timeout in milliseconds for all operations

No

30000

read_timeout

Read timeout in milliseconds for all operations

No

30000

download_directory

Directory where downloaded files will be stored in

No

Current Working Directory

download_directory

Directory where downloaded files will be stored in

No

Current Working Directory

download_chunk_size

Chunk size in bytes for files to download

No

8*1024 bytes

root_ca_certificate_file

PEM encoded Root CA certificate file path

No

N/A

client_certificate_file

PEM encoded client certificate file path

No

N/A

client_key_file

PEM encoded client key file path

No

N/A

Sample Configuration#

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

Proxy Configuration#

1config = Configuration()
2
3# Configure the cluster as shown previously along with the following proxy configuration
4config.proxy_scheme = "https"
5config.proxy_host = "127.0.0.1"
6config.proxy_port = 8080
7config.proxy_username = "proxy_admin"
8config.proxy_password = "proxy_password"
9api_client = ApiClient(configuration=config)

mTLS Configuration#

1config = Configuration()
2
3# Configure the cluster as shown previously along with the following mTLS configuration
4# (use path of your own client certificates)
5config.root_ca_certificate_file = "/home/certs/ca.pem"
6config.client_certificate_file = "/home/certs/AdonisService/AdonisService.crt"
7config.client_key_file = "/home/certs/AdonisService/AdonisService.key"
8api_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.

    1config = Configuration()
    2
    3# Configure the cluster as shown previously
    4
    5# Set API Key
    6config.set_api_key('abcde12345')
    7api_client = ApiClient(configuration=config)
    

Additional Headers#

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

1client = ApiClient(configuration=config)
2client.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))

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