Ankaios

This script defines the Ankaios class for interacting with the Ankaios control interface.

Classes

  • Ankaios:

    Handles the interaction with the Ankaios control interface.

Usage

  • Create an Ankaios object, connect and disconnect from the control interface:
    ankaios = Ankaios()
    ...
    ankaios.disconnect()
    
  • Connect and disconnect using a context manager:
    with Ankaios() as ankaios:
        ...
    
  • Apply a manifest:
    ret = ankaios.apply_manifest(manifest)
    print(ret.to_dict())
    
  • Delete a manifest:
    ret = ankaios.delete_manifest(manifest)
    print(ret.to_dict())
    
  • Run a workload:
    ret = ankaios.apply_workload(workload)
    print(ret.to_dict())
    
  • Get a workload:
    workload = ankaios.get_workload(workload_name)
    
  • Delete a workload:
    ret = ankaios.delete_workload(workload_name)
    print(ret.to_dict())
    
  • Get the state:
    state = ankaios.get_state()
    
  • Get the agents:
    agents = ankaios.get_agents()
    
  • Get the workload states:
    workload_states = ankaios.get_workload_states()
    
  • Get the workload states for workloads with a specific name:
    workload_states = ankaios.get_workload_states_for_name(workload_name)
    
  • Get the workload states for a specific agent:
    workload_states = ankaios.get_workload_states_on_agent(agent_name)
    
  • Get the workload execution state for instance name:
    ret = ankaios.get_execution_state_for_instance_name(instance_name)
    print(f"State: {ret.state}, substate: {ret.substate}")
    
  • Wait for a workload to reach a state:
    try:
        ankaios.wait_for_workload_to_reach_state(
            instance_name,
            WorkloadStateEnum.RUNNING
        )
    except TimeoutError:
        print(f"State not reached in time.")
    else:
        print(f"State reached.")
    

Ankaios Class

class ankaios_sdk.ankaios.Ankaios(log_level=AnkaiosLogLevel.INFO)[source]

Bases: object

This class is used to interact with the Ankaios using an intuitive API. The class automatically handles the session creation and the requests and responses sent and received over the Ankaios Control Interface.

logger

The logger for the Ankaios class.

Type:

logging.Logger

DEFAULT_TIMEOUT = 5.0

The default timeout, if not manually provided.

Type:

(float)

__init__(log_level=AnkaiosLogLevel.INFO)[source]

Initialize the Ankaios object. The logger will be created and the connection to the control interface will be established.

__enter__()[source]

Used for context management.

Returns:

The current object.

Return type:

Ankaios

__exit__(exc_type, exc_value, traceback)[source]

Used for context management. Disconnects from the control interface.

Parameters:
  • exc_type (type) – The exception type.

  • exc_value (Exception) – The exception instance.

  • traceback (traceback) – The traceback object.

Return type:

None

property state: ControlInterfaceState

Get the state of the control interface.

Returns:

The state of the control interface.

Return type:

ControlInterfaceState

set_logger_level(level)[source]

Set the log level of the logger.

Parameters:

level (AnkaiosLogLevel) – The log level to be set.

Return type:

None

apply_manifest(manifest, timeout=5.0)[source]

Send a request to apply a manifest.

Parameters:
  • manifest (Manifest) – The manifest object to be applied.

  • timeout (float) – The maximum time to wait for the response.

Returns:

The update state success object.

Return type:

UpdateStateSuccess

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred while applying the manifest.

delete_manifest(manifest, timeout=5.0)[source]

Send a request to delete a manifest.

Parameters:
  • manifest (Manifest) – The manifest object to be deleted.

  • timeout (float) – The maximum time to wait for the response.

Returns:

The update state success object.

Return type:

UpdateStateSuccess

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred while deleting the manifest.

apply_workload(workload, timeout=5.0)[source]

Send a request to run a workload.

Parameters:
  • workload (Workload) – The workload object to be run.

  • timeout (float) – The maximum time to wait for the response.

Returns:

The update state success object.

Return type:

UpdateStateSuccess

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred while running the workload.

get_workload(workload_name, timeout=5.0)[source]

Get the workload with the provided name from the requested complete state.

Parameters:
  • workload_name (str) – The name of the workload.

  • timeout (float) – The maximum time to wait for the response, in seconds.

Returns:

The workload object.

Return type:

Workload

delete_workload(workload_name, timeout=5.0)[source]

Send a request to delete a workload.

Parameters:
  • workload_name (str) – The name of the workload to be deleted.

  • timeout (float) – The maximum time to wait for the response.

Returns:

The update state success object.

Return type:

UpdateStateSuccess

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred while deleting the workload.

update_configs(configs, timeout=5.0)[source]

Update the configs. The names will be the keys of the dictionary.

Parameters:
  • configs (dict) – The configs dictionary.

  • timeout (float) – The maximum time to wait for the response.

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred.

add_config(name, config, timeout=5.0)[source]

Adds the config with the provided name. If the config exists, it will be replaced.

Parameters:
  • name (str) – The name of the config.

  • config (Union[dict, list, str]) – The config dictionary.

  • timeout (float) – The maximum time to wait for the response.

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred.

get_configs(timeout=5.0)[source]

Get the configs. The keys will be the names.

Returns:

The configs dictionary.

Return type:

dict

get_config(name, timeout=5.0)[source]

Get the config with the provided name.

Parameters:

name (str) – The name of the config.

Returns:

The config in a dict format.

Return type:

dict

delete_all_configs(timeout=5.0)[source]

Delete all the configs.

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred.

delete_config(name, timeout=5.0)[source]

Delete the config.

Parameters:
  • name (str) – The name of the config.

  • timeout (float) – The maximum time to wait for the response.

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred.

get_state(timeout=5.0, field_masks=None)[source]

Send a request to get the complete state.

Parameters:
  • timeout (float) – The maximum time to wait for the response, in seconds.

  • field_masks (list[str]) – The list of field masks to filter the state.

Returns:

The complete state object.

Return type:

CompleteState

Raises:
  • TimeoutError – If the request timed out.

  • AnkaiosException – If an error occurred while getting the state.

get_agents(timeout=5.0)[source]

Get the agents from the requested complete state.

Parameters:

timeout (float) – The maximum time to wait for the response, in seconds.

Returns:

The agents dictionary.

Return type:

dict

get_workload_states(timeout=5.0)[source]

Get the workload states from the requested complete state.

Parameters:

timeout (float) – The maximum time to wait for the response, in seconds.

Returns:

The collection of workload states.

Return type:

WorkloadStateCollection

get_execution_state_for_instance_name(instance_name, timeout=5.0)[source]

Get the workload states for a specific workload instance name from the requested complete state.

Parameters:
  • instance_name (WorkloadInstanceName) – The instance name of the workload.

  • timeout (float) – The maximum time to wait for the response, in seconds.

Returns:

The specified workload’s execution state.

Return type:

WorkloadExecutionState

Raises:

AnkaiosException – If the workload state was not retrieved successfully.

get_workload_states_on_agent(agent_name, timeout=5.0)[source]

Get the workload states on a specific agent from the requested complete state.

Parameters:
  • agent_name (str) – The name of the agent.

  • timeout (float) – The maximum time to wait for the response, in seconds.

Returns:

The collection of workload states.

Return type:

WorkloadStateCollection

get_workload_states_for_name(workload_name, timeout=5.0)[source]

Get the workload states for a specific workload name from the requested complete state.

Parameters:
  • workload_name (str) – The name of the workload.

  • timeout (float) – The maximum time to wait for the response, in seconds.

Returns:

The collection of workload states.

Return type:

WorkloadStateCollection

wait_for_workload_to_reach_state(instance_name, state, timeout=5.0)[source]

Waits for the workload to reach the specified state.

Parameters:
  • instance_name (WorkloadInstanceName) – The instance name of the workload.

  • state (WorkloadStateEnum) – The state to wait for.

  • timeout (float) – The maximum time to wait for the response, in seconds.

Raises:

TimeoutError – If the state was not reached in time.

Return type:

None