pcf.particle.aws.ecs package

Submodules

pcf.particle.aws.ecs.ecs_cluster module

class pcf.particle.aws.ecs.ecs_cluster.ECSCluster(particle_definition, session=None)

Bases: pcf.core.aws_resource.AWSResource

This is the implementation of Amazon’s ECS Cluster.

UNIQUE_KEYS = ['aws_resource.clusterName']
_get_arn()

Calls boto3 describe_clusters() and parses response to get ECS Cluster arn

Returns:ECS Cluster arn
_set_unique_keys()

Logic that sets keys from state definition that are used to uniquely identify the ECS Cluster

_start()

Calls boto3 create_cluster()

Returns:boto3 create_cluster() response
_stop()

Calls _terminate()

_terminate()

Calls boto3 delete_cluster()

Returns:boto3 delete_cluster() response
_update()

Logic that updates the particle. This is implemented for each individual particle

equivalent_states = {<State.running: 1>: 1, <State.stopped: 2>: 0, <State.terminated: 3>: 0}
flavor = 'ecs_cluster'
get_label()
Returns:ECS Cluster name
get_status()

Calls boto3 describe_clusters using arn.

Returns:“missing”}
Return type:status or {“status”
is_state_equivalent(state1, state2)
Parameters:
Returns:

bool

state_lookup = {'active': <State.running: 1>, 'inactive': <State.terminated: 3>, 'missing': <State.terminated: 3>}
sync_state()

Calls get_status() and updates the current_state_definition and the state.

pcf.particle.aws.ecs.ecs_instance module

class pcf.particle.aws.ecs.ecs_instance.ECSInstance(particle_definition, session=None)

Bases: pcf.core.aws_resource.AWSResource

This is the implementation of Amazon’s ECS Service. This particle requires task definition and ecs cluster particles as parents.

PROTECTED_ATTRIBUTES = 'instance-id'
START_PARAM_FILTER = {'attributes'}
UNIQUE_KEYS = []
UPDATE_PARAM_FILTER = {'attributes'}
_get_arn()

Looks for the parrent ec2 particle and uses the ec2 instance id as the key in boto3 list_attributes(). The response of list_attributes() is then parsed for the targetId which is used

Returns:ECS Instance arn
_set_unique_keys()

Logic that sets keys from state definition that are used to uniquely identify the ECS Instance

_start()

Calls boto3 update_container_instances_state() and sets the status to ACTIVE.

Returns:boto3 update_container_instances_state() response
_stop()

Calls _terminate()

_terminate()

Calls boto3 update_container_instances_state() and sets the status to DRAINING.

Returns:boto3 update_container_instances_state() response
_update()

Calls boto3 put_attributes() to update ECS Instance attributes. Does not allow for attributes that start with com.amazonaws.ecs. or instance-id to be updated.

Returns:boto3 put_attributes() response
equivalent_states = {<State.running: 1>: 1, <State.stopped: 2>: 0, <State.terminated: 3>: 0}
flavor = 'ecs_instance'
get_cluster_name()

Gets the cluster name from the ecs parent otherwise returns an exception if there is no parent ecs cluster particle.

Returns:ECS Cluster name
get_ecs_instance_id()
Returns:get_identifier()
get_status()

Calls boto3 describe_container_instances using arn.

Returns:status or {}
is_state_definition_equivalent()

Checks if the current state definition and desired state definitions are equivalent including attributes.

Returns:bool
is_state_equivalent(state1, state2)
Parameters:
Returns:

bool

sync_state()

Calls get_status() and updates the current_state_definition and the state.

pcf.particle.aws.ecs.ecs_service module

class pcf.particle.aws.ecs.ecs_service.ECSService(particle_definition, session=None)

Bases: pcf.core.aws_resource.AWSResource

This is the implementation of Amazon’s ECS Service. This particle requires task definition and ecs cluster either to be included in the initial state definition or have those particles as parents.

START_PARAM_CONVERSIONS = {'clientToken': '', 'clusterName': 'cluster', 'deploymentConfiguration': '', 'desiredCount': '', 'loadBalancers': '', 'placementConstraints': '', 'placementStrategy': '', 'roleArn': 'role', 'serviceName': '', 'taskDefinition': ''}
UNIQUE_KEYS = ['aws_resource.serviceName']
UPDATE_PARAM_CONVERSIONS = {'clusterName': 'cluster', 'deploymentConfiguration': '', 'desiredCount': '', 'serviceName': 'service', 'taskDefinition': ''}
_set_unique_keys()

Logic that sets keys from state definition that are used to uniquely identify the ECS Service

_start()

Calls boto3 create_service()

Returns:boto3 create_service() response
_stop()

Calls _terminate()

_terminate()

Calls boto3 delete_service()

Returns:boto3 delete_service() response
_update()

Calls boto3 update_service()

Returns:boto3 update_service() response
equivalent_states = {<State.running: 1>: 1, <State.stopped: 2>: 0, <State.terminated: 3>: 0}
flavor = 'ecs_service'
get_cluster_name()

Checks for a ecs service parent and returns the cluster names.

Returns:cluster_name
get_desired_state_definition()

Calls get_task_definition() and updates taskDefinition in desired_state_definition. If desired state is terminated this also sets the desiredCount to 0 in desired_state_definition.

Returns:desired_state_definition
get_service_name()
get_status()

Calls boto3 describe_services using get_service_name() and ecs_cluster_name.

Returns:“missing”}
Return type:status or {“status”
get_task_definition()

Check for a task definition parent and returns the task definition id

Returns:task_definition_id
is_state_equivalent(state1, state2)
Parameters:
Returns:

bool

state_lookup = {'active': <State.running: 1>, 'draining': <State.pending: 4>, 'inactive': <State.terminated: 3>, 'missing': <State.terminated: 3>, 'pending': <State.pending: 4>}
sync_state()

Calls get_status() and updates the current_state_definition and the state.

pcf.particle.aws.ecs.ecs_task module

class pcf.particle.aws.ecs.ecs_task.ECSTask(particle_definition, session=None)

Bases: pcf.core.aws_resource.AWSResource

This is the implementation of Amazon’s ECS Task. This particle requires task definition and ecs cluster either to be included in the initial state definition or have those particles as parents.

START_PARAM_CONVERSIONS = {'clusterArn': 'cluster', 'count': '', 'group': '', 'overrides': '', 'placementConstraints': '', 'placementStrategy': '', 'startedBy': '', 'taskDefinitionArn': 'taskDefinition'}
UNIQUE_KEYS = ['aws_resource.taskName']
_set_unique_keys()

Logic that sets keys from state definition that are used to uniquely identify the ECS Task

_start()

Calls boto3 run_task function to create a new task. If successful this gets the arn of the task and adds it to the current_state_definition.

_stop()

Calls boto3 stop_task function using the task arn. If a stop reason is not given in the desired_state_definition then “PCF default stop action” is used.

_terminate()

Calls _stop()

_update()

Logic that updates the particle. This is implemented for each individual particle

equivalent_states = {<State.running: 1>: 1, <State.stopped: 2>: 0, <State.terminated: 3>: 0}
flavor = 'ecs_task'
get_desired_state_definition()

Calls get_task_definition_arn() and get_ecs_cluster_arn() and updates desired_state_definition.

Returns:desired_state_definition
get_ecs_cluster()

Filters ecs_task parents for ecs_cluster particle. Returns none if no parents and an exception if there is more than one ecs_cluster particle as a parent.

Returns:ECS Cluster Particle or None
get_ecs_cluster_arn()

Calls get_ecs_cluster and returns the Arn attribute from that response.

Returns:ECS Cluster Arn
get_status()

Uses task arn and ecs cluster arn to call boto3 describe_tasks

Returns:ECS Task Status
get_task_arn()

Checks if the current or desired state definitions have a startedBy key which means the task has been initialized. If this key if found this calls boto3 list tasks and filters for tasks that match the startBy key and cluster name. If only one task matches then this returns the taskArn otherwise returns None.

Returns:ECS Task Arn or None
get_task_definition()

Filters ecs_task parents for ecs_task_definition particle. Returns none if no parents and an exception if there is more than one ecs_task_definition particle as a parent.

Returns:ECS Task Definition Particle or None
get_task_definition_arn()

Calls get_task_definition and returns the Arn attribute from that response.

Returns:ECS Task Definition Arn
is_state_definition_equivalent()

Determines if state definitions are equivalent

Returns:bool
is_state_equivalent(state1, state2)

Uses equivalent_states to determine if states are equivalent.

Parameters:
Returns:

bool

state_lookup = {'missing': <State.terminated: 3>, 'pending': <State.pending: 4>, 'running': <State.running: 1>, 'stopped': <State.stopped: 2>}
sync_state()

Calls get_status and updates the current_state_definition and the state.

wait()

Default time to wait during pending state.

pcf.particle.aws.ecs.ecs_task_definition module

class pcf.particle.aws.ecs.ecs_task_definition.ECSTaskDefinition(particle_definition, session=None)

Bases: pcf.core.aws_resource.AWSResource

This is the implementation of Amazon’s ECS Task Definition.

UNIQUE_KEYS = ['aws_resource.containerDefinitions.name']
_set_unique_keys()

Logic that sets keys from state definition that are used to uniquely identify the ECS Task Definition

_start()

Calls boto3 register_task_definition()

Returns:boto3 register_task_definition() response
_stop()

Calls _terminate()

_terminate()

Calls boto3 deregister_task_definition()

Returns:boto3 deregister_task_definition() response
_update()

Calls _start()

equivalent_states = {<State.running: 1>: 1, <State.stopped: 2>: 0, <State.terminated: 3>: 0}
flavor = 'ecs_task_definition'
get_status()

Calls boto3 describe_task_definition using get_task_definition_id().

Returns:“missing”}
Return type:status or {“status”
get_task_definition_id()

Parses the current and desired state definition and returns the family. If there is a revision it appends it to the family.

Returns:task definition id
is_state_equivalent(state1, state2)
Parameters:
Returns:

bool

state_lookup = {'active': <State.running: 1>, 'inactive': <State.terminated: 3>, 'missing': <State.terminated: 3>}
sync_state()

Calls get_status() and updates the current_state_definition and the state.

Module contents