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'
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_cluster(cluster_id: str, timeout=0.0) → None

Delete a cluster

Parameters:
  • cluster_id – The cluster ID
  • timeout – The timeout in seconds
delete_cluster_image(cluster_id, image_id: str, timeout=0.0)

Delete links 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 images definitions

Parameters:
  • cluster_id – The cluster ID
  • 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 images definitions

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

The data associated with the images definitions.

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

Execute clean for a cluster. This action will stop all nomad jobs and remove consul KV

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

set_cluster(cluster_id: str, source: str = '', category: str = '', timeout=0.0) → None

Create a cluster

Parameters:
  • cluster_id – The cluster ID
  • source – The terraform source to execute
  • category – A category for the cluster.
  • timeout – The timeout in seconds
set_cluster_images(cluster_id, data: dict, timeout=0.0)

Set images 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_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_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 get 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_log(instance_id: str, command_id: str, origin: str = 'start', offset: int = 0, size: int = 20000, timeout=0.0) → dict

Get a 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 return
  • 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_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

Parameters:timeout – The timeout in seconds
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 logs 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
  • lines – An approximate number of lines to show
  • timeout – The timeout in seconds
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
class bastion_api.BastionAPI

Implementation of genvid.toolbox.BastionAPI