2014-03-23 23:12:07 +01:00
|
|
|
from bootstrapvz.base import Task
|
|
|
|
from bootstrapvz.common import phases
|
2013-06-24 23:12:39 +02:00
|
|
|
|
2013-06-23 12:00:17 +02:00
|
|
|
|
2013-07-13 13:55:12 +02:00
|
|
|
class Create(Task):
|
2016-06-04 11:35:59 +02:00
|
|
|
description = 'Creating the EBS volume'
|
|
|
|
phase = phases.volume_creation
|
2013-06-26 20:14:37 +02:00
|
|
|
|
2016-06-04 11:35:59 +02:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2018-01-14 23:49:36 +02:00
|
|
|
tags = []
|
|
|
|
|
|
|
|
# Setting up tags on the EBS volume
|
|
|
|
if 'tags' in info.manifest.data:
|
|
|
|
raw_tags = info.manifest.data['tags']
|
|
|
|
formatted_tags = {k: v.format(**info.manifest_vars) for k, v in raw_tags.items()}
|
|
|
|
tags = [{'Key': k, 'Value': v} for k, v in formatted_tags.items()]
|
|
|
|
|
2018-03-15 17:46:33 +02:00
|
|
|
# EBS volumes support encryption. KMS key id is optional and default key
|
|
|
|
# is used when it is not defined.
|
|
|
|
encrypted = info.manifest.data['provider'].get('encrypted', False)
|
2018-06-14 09:38:36 +03:00
|
|
|
kms_key_id = info.manifest.data['provider'].get('kms_key_id', None)
|
2018-03-15 17:46:33 +02:00
|
|
|
|
|
|
|
info.volume.create(info._ec2['connection'], info._ec2['host']['availabilityZone'], tags=tags, encrypted=encrypted, kms_key_id=kms_key_id)
|
2013-06-23 12:00:17 +02:00
|
|
|
|
2013-06-26 20:14:37 +02:00
|
|
|
|
2013-10-09 00:09:34 +02:00
|
|
|
class Attach(Task):
|
2016-06-04 11:35:59 +02:00
|
|
|
description = 'Attaching the volume'
|
|
|
|
phase = phases.volume_creation
|
|
|
|
predecessors = [Create]
|
2013-10-09 00:09:34 +02:00
|
|
|
|
2016-06-04 11:35:59 +02:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
info.volume.attach(info._ec2['host']['instanceId'])
|
2013-10-09 00:09:34 +02:00
|
|
|
|
|
|
|
|
2013-07-13 13:55:12 +02:00
|
|
|
class Snapshot(Task):
|
2016-06-04 11:35:59 +02:00
|
|
|
description = 'Creating a snapshot of the EBS volume'
|
|
|
|
phase = phases.image_registration
|
2013-07-07 19:24:52 +02:00
|
|
|
|
2016-06-04 11:35:59 +02:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
info._ec2['snapshot'] = info.volume.snapshot()
|
2016-11-12 19:58:51 +00:00
|
|
|
|
2017-01-21 22:44:16 +00:00
|
|
|
# Setting up tags on the snapshot
|
|
|
|
if 'tags' in info.manifest.data:
|
|
|
|
raw_tags = info.manifest.data['tags']
|
|
|
|
formatted_tags = {k: v.format(**info.manifest_vars) for k, v in raw_tags.items()}
|
|
|
|
tags = [{'Key': k, 'Value': v} for k, v in formatted_tags.items()]
|
|
|
|
info._ec2['connection'].create_tags(Resources=[info._ec2['snapshot']],
|
|
|
|
Tags=tags)
|