diff --git a/bootstrapvz/plugins/ec2_launch/__init__.py b/bootstrapvz/plugins/ec2_launch/__init__.py index c1e8caf..69c29c7 100644 --- a/bootstrapvz/plugins/ec2_launch/__init__.py +++ b/bootstrapvz/plugins/ec2_launch/__init__.py @@ -9,3 +9,5 @@ def resolve_tasks(taskset, manifest): taskset.add(tasks.LaunchEC2Instance) if 'print_public_ip' in manifest.plugins['ec2_launch']: taskset.add(tasks.PrintPublicIPAddress) + if manifest.plugins['ec2_launch'].get('deregister_ami', False): + taskset.add(tasks.DeregisterAMI) diff --git a/bootstrapvz/plugins/ec2_launch/manifest-schema.yml b/bootstrapvz/plugins/ec2_launch/manifest-schema.yml index faba1e8..9d7992e 100644 --- a/bootstrapvz/plugins/ec2_launch/manifest-schema.yml +++ b/bootstrapvz/plugins/ec2_launch/manifest-schema.yml @@ -16,3 +16,5 @@ properties: instance_type: {type: string} print_public_ip: {type: string} tags: {type: object} + deregister_ami: {type: boolean} + additionalProperties: false diff --git a/bootstrapvz/plugins/ec2_launch/tasks.py b/bootstrapvz/plugins/ec2_launch/tasks.py index c597254..5d4abc5 100644 --- a/bootstrapvz/plugins/ec2_launch/tasks.py +++ b/bootstrapvz/plugins/ec2_launch/tasks.py @@ -62,3 +62,24 @@ class PrintPublicIPAddress(Task): f.write('') f.close() + + +class DeregisterAMI(Task): + description = 'Deregistering AMI' + phase = phases.image_registration + predecessors = [LaunchEC2Instance] + + @classmethod + def run(cls, info): + ec2 = info._ec2 + logger = logging.getLogger(__name__) + + def instance_running(): + ec2['instance'].update() + return ec2['instance'].state == 'running' + + if waituntil(instance_running, timeout=120, interval=5): + info._ec2['connection'].deregister_image(info._ec2['image']) + info._ec2['snapshot'].delete() + else: + logger.error('Timeout while booting instance')