genvid.toolbox.BastionAPI

class genvid.toolbox.BastionAPI(**kwargs)

Bases: genvid.toolbox.httpapi.BaseHttpApiTool, genvid.toolbox.consul.ConsulTool

Client for the Bastion API.

NAME = 'bastion-api'
add_backend(backend_id: str, backend_type: str, variables: dict = {}, timeout=0.0)

Add a new backend template.

Parameters:
  • backend_id – The backend ID.
  • backend_type – The type of backend.
  • variables – A list of default variables for the backend.
  • timeout – The timeout in seconds.
cluster_do_clean(cluster_id, timeout=0.0)

Execute clean for a cluster. This action will stop all Nomad jobs and remove Consul KV.

Parameters:
  • cluster_id – The cluster ID.
  • timeout – The timeout in seconds.
Returns:

cluster_do_setup(cluster_id, timeout=0.0)

Execute setup for a cluster. This action is used to start cluster-api.

Parameters:
  • cluster_id – The cluster ID.
  • timeout – The timeout in seconds.
Returns:

cluster_get_setup_jobs(cluster_id: str, timeout=0.0) → typing.List[dict]

Get the list of setup jobs.

Parameters:
  • cluster_id – The cluster ID.
  • timeout – The timeout in seconds.
Returns:

A list of setup job definition.

cluster_set_setup_jobs(cluster_id: str, jobs: typing.List[dict], timeout=0.0)

Set the list of setup jobs.

Parameters:
  • cluster_id – The cluster ID.
  • jobs – A list of setup job definition.
  • timeout – The timeout in seconds.
delete_backend(backend_id: str, timeout=0.0)

Remove a backend template.

Parameters:
  • backend_id – The backend ID.
  • timeout – The timeout in seconds.
delete_cluster(cluster_id: str, force: bool = False, timeout=0.0) → None

Delete a cluster.

Parameters:
  • cluster_id – The cluster ID.
  • force – Force the cluster to be deleted.
  • timeout – The timeout in seconds.
delete_cluster_image(cluster_id, image_id: str, timeout=0.0)

Delete link definitions.

Parameters:
  • cluster_id – The cluster ID.
  • image_id – The image ID.
  • timeout – The timeout in seconds.
delete_cluster_images(cluster_id, timeout=0.0)

Delete multiple image definitions.

Parameters:
  • cluster_id – The cluster ID.
  • timeout – The timeout in seconds.
get_backend(backend_id: str, timeout=0.0) → dict

Get a backend template.

Parameters:
  • backend_id – The backend ID.
  • timeout – The timeout in seconds.
get_backends(timeout=0.0) → dict

Get the list of all backend templates.

Parameters:timeout – The timeout in seconds.
get_base_url(timeout=0.0) → str

Get the base URL.

get_cluster(cluster_id: str, timeout=0.0) → dict

Get a cluster.

Parameters:
  • cluster_id – The cluster ID.
  • timeout – The timeout in seconds.
get_cluster_images(cluster_id, timeout=0.0) → dict

Retrieve multiple image definitions.

Parameters:
  • cluster_id – The cluster ID.
  • timeout – The timeout in seconds.
Returns:

The data associated with the image definitions.

get_cluster_service(cluster_id, service_id, timeout=0.0) → typing.List[str]

Get a service address.

Parameters:
  • cluster_id – The cluster ID.
  • service_id – The service ID.
  • timeout – The timeout in seconds.
Returns:

get_clusters(timeout=0.0) → typing.List[dict]

Get the clusters.

Parameters:timeout – The timeout in seconds.
get_global(timeout=0.0) → dict

Get the global configuration.

Parameters:timeout – The timeout in seconds.

Get the list of links.

Parameters:
  • category – The link’s category.
  • link_id – The link’s ID.
  • timeout – The timeout in seconds.
Returns:

A list of strings.

jobs = None

Get the JobsAPI

logs = None

Get the LogsAPI

set_cluster(cluster_id: str, backend_id: str = 'default', backend_variables: dict = {}, category: str = '', timeout=0.0) → None

Create a cluster.

Parameters:
  • cluster_id – The cluster ID.
  • backend_id – The backend ID.
  • backend_variables – The backend variables.
  • category – A category for the cluster.
  • timeout – The timeout in seconds.
set_cluster_images(cluster_id, data: dict, timeout=0.0)

Set multiple image definitions.

Parameters:
  • cluster_id – The cluster ID.
  • data – Data associated with the images.
  • timeout – The timeout in seconds.
set_global(bastion_id: str, timeout=0.0)

Set the global configuration.

Parameters:
  • bastion_id – The bastion ID. This is used to isolate multiple bastions.
  • timeout – The timeout in seconds.
terraform_add_repository(name: str, config: dict, timeout=0.0) → dict

Add a repository.

Parameters:
  • name – The unique name of the repository.
  • config – A dictionary with the repository configuration.
Returns:

The repository configuration.

terraform_clean_global_tfvars(timeout=0.0) → str

Clean the global tfvars content.

Parameters:timeout – The timeout in seconds.
terraform_delete_instance_content(instance_id: str, content_id: str, timeout=0.0)

Delete a .tf.json terraform file content.

Parameters:
  • instance_id – The instance ID.
  • content_id – The terraform file ID.
  • timeout – The timeout in seconds.
terraform_do_instance_apply(instance_id: str, timeout=0.0) → dict

Execute terraform apply for the instance.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_do_instance_destroy(instance_id: str, timeout=0.0) → dict

Execute terraform destroy for the instance.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_do_instance_get(instance_id: str, timeout=0.0) → dict

Execute terraform get for the instance.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_do_instance_import_module(instance_id: str, module_path: str = 'cluster/default', timeout=0.0, force: bool = False) → dict

Execute terraform init for the instance

Parameters:
  • instance_id – The instance ID
  • module_path – The module to use
  • timeout – The timeout in seconds
  • force – Force the import even if the cluster is in error state.
terraform_do_instance_init(instance_id: str, timeout: float = 0.0, force: bool = False) → dict

Execute terraform init for the instance

Parameters:
  • instance_id – The instance ID
  • timeout – The timeout in seconds
  • force – Force the initialization even if the cluster is in error state.
terraform_do_instance_output(instance_id: str, timeout=0.0) → dict

Return the terraform output command.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_do_instance_plan(instance_id: str, destroy: bool = False, timeout=0.0) → dict

Execute terraform plan for the instance.

Parameters:
  • instance_id – The instance ID.
  • destroy – Execute the destroy plan.
  • timeout – The timeout in seconds.
terraform_do_instance_refresh(instance_id: str, timeout=0.0) → dict

Execute terraform refresh for the instance.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_get_global_tfvars(timeout=0.0) → dict

Get the global tfvars content.

Parameters:timeout – The timeout in seconds.
terraform_get_instance(instance_id: str, timeout=0.0) → dict

Get a specific terraform instance.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_get_instance_command(instance_id: str, command_id: str, timeout=0.0) → dict

Get the command base on the instance id and the command id.

Parameters:
  • instance_id – The instance ID.
  • command_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_get_instance_command_log(instance_id: str, command_id: str, origin: str = 'start', offset: int = 0, size: int = 20000, timeout=0.0) → dict

Get an instance’s command log.

Parameters:
  • instance_id – The instance ID.
  • command_id – The command ID.
  • origin – If the log is from the start or end.
  • offset – The offset relative to the origin.
  • size – The max size of the log to be returned.
  • timeout – The timeout in seconds.
terraform_get_instance_commands(instance_id: str, current: bool = True, timeout=0.0) → typing.List[dict]

Get the commands related to a terraform instance.

Parameters:
  • instance_id – The instance ID.
  • current – If true, only return the currently running commands.
  • timeout – The timeout in seconds.
terraform_get_instance_content(instance_id: str, content_id: str, timeout=0.0)

Get a .tf.json terraform file content.

Parameters:
  • instance_id – The instance ID.
  • content_id – The terraform file ID.
  • timeout – The timeout in seconds.
Returns:

The content of the specified file in JSON.

terraform_get_instance_status(instance_id: str, timeout=0.0) → dict

Get the status of an instance.

The instance states can be:

  • ‘VOID’: The instance doesn’t exist.
  • ‘EMPTY’: The instance exists but is not initialized.
  • ‘DOWN’: The instance is initialized but doesn’t contains any resources.
  • ‘UP’: The instance manage some resources.
  • ‘BUSY’: The instance is currently running a command.
  • ‘ERROR’: An error has occured during the retrieval of the status.
  • ‘INVALID’: The current status of the instance is unknown.
Parameters:instance_id – The instance ID :return: A string with the instance status.
Returns:A dictionary with a single key status.
terraform_get_instance_tfvars(instance_id: str, timeout=0.0) → str

Get the instance tfvars content.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_get_instance_tfvars_default(instance_id: str, timeout=0.0) → str

Get the instance tfvars content.

Parameters:
  • instance_id – The instance ID.
  • timeout – The timeout in seconds.
terraform_get_instances(timeout=0.0) → typing.List[dict]

Get the terraform instances.i

Parameters:timeout – The timeout in seconds.
terraform_get_module(moduleId: str, timeout=0.0) → dict

Return a module information

Parameters:
  • moduleId – The module path.
  • timeout – The timeout in seconds.
Returns:

The module definition.

terraform_get_modules(prefix: str = '', timeout=0.0) → typing.List[dict]

Return the list of modules.

Parameters:
  • prefix – A prefix to filter the modules.
  • timeout – The timeout in seconds.
Returns:

A list of modules.

terraform_get_repositories(timeout=0.0) → typing.Dict[str, dict]

Return the list of terraform repositories.

Parameters:timeout – The timeout in seconds.
Returns:A map of repositories by name
terraform_print_command_log(instance_id: str, command_id: str, output=None, tail=False, follow=False, lines: int = 10, timeout=0.0)

Print a command’s log on output.

Parameters:
  • instance_id – The instance ID.
  • command_id – The command ID.
  • output – If None, default to stdout.
  • tail – If True, print the end of the log.
  • follow – If True, continue to show the log as it runs.
  • lines – An approximate number of lines to show.
  • timeout – The timeout in seconds.
terraform_remove_repository(name: str, timeout=0.0) → dict

Remove a repository.

Parameters:name – The name of the repository.
Returns:The repository configuration.
terraform_set_global_tfvars(tfvars: dict, timeout=0.0) → str

Set the global tfvars content.

Parameters:
  • tfvars – The tfvars content.
  • timeout – The timeout in seconds.
terraform_set_instance_content(instance_id: str, content_id: str, content: dict, timeout=0.0)

Set a .tf.json terraform file content.

Parameters:
  • instance_id – The instance ID.
  • content_id – The terraform file ID.
  • content – The terraform file content.
  • timeout – The timeout in seconds.
terraform_set_instance_tfvars(instance_id: str, tfvars: dict, timeout=0.0)

Set the instance tfvars content.

Parameters:
  • instance_id – The instance ID.
  • tfvars – The tfvars content.
  • timeout – The timeout in seconds.
terraform_update_repository(name: str, config: dict = {}, timeout=0.0) → dict

Update an existing repository.

Parameters:
  • name – The name of the repository.
  • config – A dictionary with the repository configuration (optional)
Returns:

The repository configuration.

terraform_wait_instance_command(instance_id: str, command_id: str, timeout=0.0) → dict

Get the command base on the instance id and the command id.

Parameters:
  • instance_id – The instance ID.
  • command_id – The instance ID.
  • timeout – The timeout in seconds.
update_backend(backend_id: str, backend_type: str, variables: dict = {}, timeout=0.0)

Update an existing backend template.

Parameters:
  • backend_id – The backend ID.
  • backend_type – The type of backend.
  • variables – A list of default variables for the backend.
  • timeout – The timeout in seconds.
class bastion_api.BastionAPI

Implementation of genvid.toolbox.BastionAPI