4.6.2. Instances

API for working with instances.

class axonius_api_client.api.system.instances.Instances(auth, **kwargs)[source]

Bases: axonius_api_client.api.mixins.ModelMixins

API for working with instances.

Examples

Notes

Certain functionality is not yet exposed, please submit a feature request via support@axonius.com if you would like to:

  • Deactivate an instance

  • Connect an instance

  • Tag an instance

Parameters

auth (axonius_api_client.auth.models.Model) –

get()[source]

Get metadata about all instances.

Examples

Create a client using axonius_api_client.connect.Connect

>>> data = client.instances.get()
>>> list(data)
['connection_data', 'instances']
>>> len(data["instances"])
1
Return type

dict

get_core(key=None)[source]

Get the core instance.

Examples

Create a client using axonius_api_client.connect.Connect

>>> instance = client.instances.get_core()
>>> instance['node_name']
'Master'
>>> instance['cpu_usage']
39
>>> instance['data_disk_free_space']
74431500
>>> instance['hostname']
'builds-vm-jim-pre-3-10-1601596999-000'
>>> instance['ips']
['10.20.0.61']
>>> instance['data_disk_free_space_percent']
36.62
>>> instance['memory_free_space_percent']
1.46
>>> instance['swap_free_space_percent']
0.0
Parameters

key (typing.Optional[str]) – key to return or just return whole object

Return type

typing.Union[dict, str, bool, int, float]

get_collectors()[source]

Get the collector instances.

Examples

Create a client using axonius_api_client.connect.Connect

>>> collectors = client.instances.get_collectors()
>>> len(collectors)
0
Return type

typing.List[dict]

get_by_name(name, key=None)[source]

Get an instance by name.

Examples

Create a client using axonius_api_client.connect.Connect

>>> instance = client.instances.get_by_name("Master")
>>> instance['cpu_usage']
39
>>> instance['data_disk_free_space']
74431500
>>> instance['hostname']
'builds-vm-jim-pre-3-10-1601596999-000'
>>> instance['ips']
['10.20.0.61']
>>> instance['data_disk_free_space_percent']
36.62
>>> instance['memory_free_space_percent']
1.46
>>> instance['swap_free_space_percent']
0.0
Parameters
  • name (str) – name of instance

  • key (typing.Optional[str]) – key to return or just return whole object

Return type

typing.Union[dict, str, bool, int, float]

set_name(name, new_name)[source]

Set the name of an instance.

Examples

Create a client using axonius_api_client.connect.Connect

Get the current name

>>> orig_value = client.instances.get_core(key='name')
>>> orig_value
'Master'

Set a new name

>>> new_value = client.instances.set_name(name=orig_value, new_name='Temp')
>>> new_value
'Temp'

Revert back to the original name

>>> reset_value = client.instances.set_name(name=new_value, new_name=orig_value)
>>> reset_value
'Master'
Parameters
  • name (str) – name of instance

  • new_name (str) – new name to set on instance

Return type

str

get_hostname(name)[source]

Get the host name of an instance.

Examples

Create a client using axonius_api_client.connect.Connect

Get the hostname

>>> hostname = client.instances.get_hostname(name='Master')
>>> hostname
'builds-vm-jim-pre-3-10-1601596999-000'
Parameters
  • name (str) – name of instance

  • value – new hostname to set on instance

Return type

str

set_hostname(name, value)[source]

Set the hostname of an instance.

Examples

Create a client using axonius_api_client.connect.Connect

Get the current hostname

>>> orig_value = client.instances.get_hostname(name='Master')
>>> orig_value
'builds-vm-jim-pre-3-10-1601596999-000'

Set a new hostname

>>> new_value = client.instances.set_hostname(name='Master', value="hostname")
>>> new_value
"hostname"

Revert to the old hostname

>>> reset_value = client.instances.set_hostname(name='Master', value=orig_value)
>>> reset_value
'builds-vm-jim-pre-3-10-1601596999-000'
Parameters
  • name (str) – name of instance

  • value (str) – new hostname to set on instance

Return type

str

get_is_env_name(name)[source]

See if an instance name is being used for the environment name.

Examples

Create a client using axonius_api_client.connect.Connect

>>> client.instances.get_is_env_name(name='Master')
False

Notes

Environment name is the name shown in the banner at the bottom of the GUI.

Parameters

name (str) – name of instance

Return type

bool

set_is_env_name(name, enabled)[source]

Set if an instance name is being used for the environment name.

Examples

Create a client using axonius_api_client.connect.Connect

Enable an instance name as the environment name

>>> client.instances.set_is_env_name(name='Master', enabled=True)
True

Disable an instance name as the environment name

>>> client.instances.set_is_env_name(name='Master', enabled=False)
False

Notes

Environment name is the name shown in the banner at the bottom of the GUI.

Parameters
  • name (str) – name of instance

  • enabled (bool) – enable/disable instance name as the environment name

Return type

bool

get_central_core_mode()[source]

Get a bool that shows if a core is in central core mode.

Examples

Create a client using axonius_api_client.connect.Connect

>>> client.instances.get_central_core_mode()
False
Return type

bool

set_central_core_mode(enabled)[source]

Convert a normal core into a central core.

Examples

Create a client using axonius_api_client.connect.Connect

Enable central core mode on a core

>>> client.instances.set_central_core_mode(enabled=True)
True

Disable central core mode on a core

>>> client.instances.set_central_core_mode(enabled=False)
False
Parameters

enabled (bool) – enable/disable central core mode

Return type

bool

get_core_delete_mode()[source]

Get a bool that shows if a core is in central core mode.

Examples

Create a client using axonius_api_client.connect.Connect

>>> client.instances.get_core_delete_mode()
True
Return type

bool

set_core_delete_mode(enabled)[source]

Configure a normal core to delete backups after they have been restored.

Examples

Create a client using axonius_api_client.connect.Connect

Set backups to delete after restore

>>> client.instances.set_core_delete_mode(enabled=True)
True

Set backups to NOT delete after restore

>>> client.instances.set_core_delete_mode(enabled=False)
False
Parameters

enabled (bool) – enable/disable deletion of backups after they have been restored by a core

Return type

bool

get_central_core_config()[source]

Get the current central core configuration.

Examples

Create a client using axonius_api_client.connect.Connect

>>> client.instances.get_central_core_config()
{'core_delete_backups': False, 'central_core_enabled': False}
Return type

dict

restore_from_aws_s3(key_name, bucket_name=None, access_key_id=None, secret_access_key=None, preshared_key=None, allow_re_restore=False, delete_backups=False)[source]

Perform a restore on a core from a file in an AWS S3 Bucket.

Parameters
  • key_name (str) – Name of backup file from central core in [bucket_name] to restore to this core

  • bucket_name (typing.Optional[str]) – Name of bucket in S3 to get [key_name] from (Overrides Global Settings > Amazon S3 Settings > Amazon S3 bucket name)

  • access_key_id (typing.Optional[str]) – AWS Access Key Id to use to access [bucket_name] (Overrides Global Settings > Amazon S3 Settings > AWS Access Key Id)

  • secret_access_key (typing.Optional[str]) – AWS Secret Access Key to use to access [bucket_name] (Overrides Global Settings > Amazon S3 Settings > AWS Secret Access Key)

  • preshared_key (typing.Optional[str]) – Password to use to decrypt [key_name] (Overrides: Global Settings > Amazon S3 Settings > Backup encryption passphrase)

  • allow_re_restore (bool) – Restore [key_name] even if it has already been restored

  • delete_backups (bool) – Delete [key_name] from [bucket_name] after restore has finished (Overrides the current value of get_core_delete_mode())

Return type

dict

property feature_flags

Get the feature flags for the core.

Return type

dict

property has_cloud_compliance

Get the status of cloud compliance module being enabled.

Return type

bool

property trial_expiry

Get the trial expiration date.

Return type

typing.Optional[datetime.datetime]

property trial_days_left

Get the number of days left for the trial.

Return type

typing.Optional[int]

property license_expiry

Get the license expiration date.

Return type

typing.Optional[datetime.datetime]

property license_days_left

Get the number of days left for the license.

Return type

typing.Optional[int]

_get()[source]

Direct API method to get instances.

Return type

dict

_delete(node_id)[source]

Direct API method to delete an instance.

Notes

Untested!

Parameters

node_id (str) – node id of instance

_update(node_id, node_name, hostname, **kwargs)[source]

Direct API method to update an instance.

Parameters
  • node_id (str) – node id of instance

  • node_name (str) – node name of instance

  • hostname (str) – hostname of instance

  • **kwargs – instance metadata configuration

Return type

dict

_get_central_core()[source]

Direct API method to get the current central core configuration.

Return type

dict

_update_central_core(enabled, delete_backups)[source]

Direct API method to set the current central core configuration.

Parameters
  • enabled (bool) – enable/disable central core mode (ignored if not True/False)

  • delete_backups (bool) – enable/disable deletion of backups on a core after resture (ignored if not True/False)

Return type

dict

_restore(restore_type, restore_opts)[source]

Direct API method to perform a central core restore operation.

Parameters
  • restore_type (str) – currently only AWS supported?

  • restore_opts (dict) – options specific to restore_type

Return type

dict

_feature_flags()[source]

Direct API method to get the feature flags for the core.

Return type

dict

property router

Router for this API model.

Returns

REST API route defs

Return type

routers.Router

__init__(auth, **kwargs)

Mixins for API Models.

Parameters
__repr__()

Show info for this model object.

Return type

str

__str__()

Show info for this model object.

Return type

str

_build_err_msg(response, error=None, exc=None)

Build an error message from a response.

Parameters
Return type

str

_check_response_code(response, error_status=True)

Check the status code of a response.

Parameters
  • responserequests.Response object to check

  • error_status (bool) – throw exc if response status code is bad

Raises

ResponseNotOk – if response has a status code that is an error and error_status is True

_check_response_json(response, error_json_bad_status=True, error_json_invalid=True, uses_api_response=False)

Check the text body of a response is JSON.

Parameters
Raises
  • JsonInvalid – if error_json_invalid is True and response has invalid json

  • JsonError – if error_json_bad_status is True and response is a json dict that has a non-empty error key or a status key that == error

Return type

typing.Any

_init(**kwargs)

Post init method for subclasses to use for extra setup.

request(path, method='get', raw=False, is_json=True, empty_ok=False, error_status=True, error_json_bad_status=True, error_json_invalid=True, **kwargs)

Send a REST API request.

Parameters
  • path (str) – path to use in request

  • method (str) – method to use in request

  • raw (bool) – return the raw response object

  • is_json (bool) – return the response as deserialized json or just return the text body

  • error_status (bool) – throw error if response has a bad status code

  • error_json_bad_status (bool) – throw error if json response has non-empty error key

  • error_json_invalid (bool) – throw error if response can not be deserialized into json

  • **kwargs – Passed to axonius_api_client.http.Http.__call__()

  • empty_ok (bool) –

Return type

typing.Any

Returns

requests.Response or str or dict or int or list