pcf.particle.aws.ec2 package¶
Subpackages¶
Submodules¶
pcf.particle.aws.ec2.ebs_volume module¶
-
class
pcf.particle.aws.ec2.ebs_volume.
EBSVolume
(particle_definition)¶ Bases:
pcf.core.aws_resource.AWSResource
This is the EBS Volume particle. This also contains functions to attach and detach to an ec2 volume. There is a custom config called attach, which when set to True will auto attach to a parent EC2
-
START_PARAM_FILTER
= {'AvailabilityZone', 'Encrypted', 'Iops', 'KmsKeyId', 'Size', 'SnapshotId', 'TagSpecifications', 'VolumeType'}¶
-
UNIQUE_KEYS
= ['aws_resource.custom_config.volume_name']¶
-
UPDATE_PARAM_FILTER
= {'Iops': '', 'Size': '', 'VolumeType': ''}¶
-
_set_unique_keys
()¶ Logic that sets keys from state definition that are used to uniquely identify the EBS volume
-
_start
()¶ Calls boto3 create_volume().
Returns: boto3 create_volume() response
-
_stop
()¶ Calls _terminate()
-
_terminate
()¶ Calls boto3 delete_volume().
Returns: boto3 delete_volume() response
-
_update
()¶ Calls boto3 modify_volume(). If tags are changes then also calls delete_tags() and then create_tags()
Returns: boto3 modify_volume() response
-
attach_volume
(device='/dev/sdf', ec2_parent_id=None)¶ Calls boto3 attach_volume().
Parameters: - device (str) – ec2 device to attach to. Default: /dev/sdf
- ec2_parent_id (str) – ec2 parent instance id. Default: Parent ec2 instanceId
Returns: boto3 attach_volume() response
-
detach_volume
()¶ Calls boto3 detach_volume().
Returns: boto3 detach_volume() response
-
equivalent_states
= {<State.running: 1>: 1, <State.stopped: 2>: 0, <State.terminated: 3>: 0}¶
-
flavor
= 'ebs_volume'¶
-
get_status
()¶ Calls boto3 describe_volumes using VolumeId.
Returns: status
-
is_state_definition_equivalent
()¶ Determines if state definitions are equivalent including list of tags.
Returns: Bool
-
state_lookup
= {'attaching': <State.pending: 4>, 'available': <State.running: 1>, 'creating': <State.pending: 4>, 'deleted': <State.terminated: 3>, 'deleting': <State.pending: 4>, 'detaching': <State.terminated: 3>, 'in-use': <State.running: 1>}¶
-
sync_state
()¶ Updates the current_state_definition and the current state. Will attach to parent ec2 if parent exists and custom config flag is set. Will detach on termination. If you do not want it terminated, set termination protection and call detach function.
-
pcf.particle.aws.ec2.ec2_instance module¶
-
class
pcf.particle.aws.ec2.ec2_instance.
EC2Instance
(particle_definition)¶ Bases:
pcf.core.aws_resource.AWSResource
This is the EC2 particle. There are a variety of possible states for this particle which can be seen in the state lookup dictionary. There are also specific input requirements for the various commands which can be seen in the different PARAM_CONVERSIONS.
-
EBS_PARAM_CONVERSIONS
= {'DeleteOnTermination': '', 'Iops': '', 'SnapshotId': '', 'VolumeSize': 'Size', 'VolumeType': ''}¶
-
START_PARAM_FILTER
= {'BlockDeviceMappings', 'IamInstanceProfile', 'ImageId', 'InstanceInitiatedShutdownBehavior', 'InstanceType', 'KeyName', 'MaxCount', 'MinCount', 'SecurityGroupIds', 'SubnetId', 'TagSpecifications', 'UserData'}¶
-
STATE_PARAM_FILTER
= {'IamInstanceProfile', 'ImageId', 'InstanceInitiatedShutdownBehavior', 'InstanceType', 'KeyName', 'SecurityGroupIds', 'SubnetId', 'TagSpecifications', 'UserData'}¶
-
UNIQUE_KEYS
= ['aws_resource.custom_config.instance_name']¶
-
_get_arn
()¶ Calls _get_instance_reservations() to get ecs reservations. Parses reservations and returns inputs for _construct_arn() which returns the EC2 arn.
Returns: _construct_arn()
-
_get_instance_reservations
()¶ Uses instance_name as a filter for boto3 describe_instances()
Returns: boto3 describe_instances() response
-
_set_unique_keys
()¶ Logic that sets keys from state definition that are used to uniquely identify the EC2 instance
-
_start
()¶ Calls boto3 start_instances(). This is called for stopped to running state transition.
Returns: boto3 start_instances() response
-
_stop
()¶ Calls boto3 stop_instances().
Returns: boto3 stop_instances() response
-
_terminate
()¶ Calls boto3 delete_tags() and terminate_instances
Returns: boto3 terminate_instances() response
-
_update
()¶ Logic that updates the particle. This is implemented for each individual particle
-
create
()¶ Calls boto3 create_instances(). This is called for terminated to running state transition.
Returns: boto3 create_instances() response
-
equivalent_states
= {}¶
-
flavor
= 'ec2_instance'¶
-
get_current_definition
()¶ Calls boto3 describe_instances. Adds some fields that are required for matching desired state such as Userdata hash, TagSpecifications, and InstanceInitiatedShutdownBehavior
Returns: state definition
-
get_desired_state_definition
()¶ Adds some custom field to the user given desired_state_file. These are UserData (rendered version) and TagSpecifications
Returns: desired_state_definition
-
get_identifier
()¶ Uses arn to return instance id.
Returns: instance_id
-
get_instance_id
()¶ Returns: get_identifier()
-
get_label
()¶ Returns: instance_name
-
is_state_definition_equivalent
()¶ Determines if state definitions are equivalent
Returns: bool
-
render_desired_user_data
()¶ Opens the userdata template file and renders the file with userdata parameters.
Returns: userdate
-
state_lookup
= {'missing': <State.terminated: 3>, 'pending': <State.pending: 4>, 'running': <State.running: 1>, 'shutting-down': <State.pending: 4>, 'stopped': <State.stopped: 2>, 'stopping': <State.pending: 4>, 'terminated': <State.terminated: 3>}¶
-
sync_state
()¶ Calls get_current_definition() and updates the current_state_definition and the state.
-
-
pcf.particle.aws.ec2.ec2_instance.
_construct_arn
(owner_id, region_name, instance_id)¶ Parameters: - owner_id (str) – owner id
- region_name (str) – region that EC2 is deployed
- instance_id (str) – instance on of the EC2
Returns: EC2 arn
-
pcf.particle.aws.ec2.ec2_instance.
_get_instance_id_from_arn
(arn)¶ Parses the arn to return only the instance id
Parameters: arn (str) – EC2 arn Returns: EC2 Instance id