diff --git a/plugins/prebootstrapped/__init__.py b/plugins/prebootstrapped/__init__.py index ebe68eb..7e5bfc7 100644 --- a/plugins/prebootstrapped/__init__.py +++ b/plugins/prebootstrapped/__init__.py @@ -1,3 +1,4 @@ +from tasks import CreateSnapshot from tasks import CreateVolumeFromSnapshot from providers.ec2.tasks import ebs @@ -5,12 +6,15 @@ from providers.ec2.tasks import ebs def tasks(tasklist, manifest): from providers.ec2.tasks import bootstrap from providers.ec2.tasks import filesystem - tasklist.replace(ebs.CreateVolume, CreateVolumeFromSnapshot()) - tasklist.remove(filesystem.FormatVolume, - filesystem.TuneVolumeFS, - filesystem.AddXFSProgs, - bootstrap.MakeTarball, - bootstrap.Bootstrap) + if manifest.plugins['prebootstrapped']['snapshot'] == "": + tasklist.add(CreateSnapshot()) + else: + tasklist.replace(ebs.CreateVolume, CreateVolumeFromSnapshot()) + tasklist.remove(filesystem.FormatVolume, + filesystem.TuneVolumeFS, + filesystem.AddXFSProgs, + bootstrap.MakeTarball, + bootstrap.Bootstrap) def rollback_tasks(tasklist, tasks_completed, manifest): diff --git a/plugins/prebootstrapped/tasks.py b/plugins/prebootstrapped/tasks.py index ccaeed8..4d8e52a 100644 --- a/plugins/prebootstrapped/tasks.py +++ b/plugins/prebootstrapped/tasks.py @@ -2,7 +2,10 @@ from base import Task from common import phases from providers.ec2.tasks import connection from providers.ec2.tasks import ebs +from providers.ec2.tasks import bootstrap import time +import logging +log = logging.getLogger(__name__) class CreateVolumeFromSnapshot(Task): @@ -20,3 +23,14 @@ class CreateVolumeFromSnapshot(Task): while info.volume.volume_state() != 'available': time.sleep(5) info.volume.update() + + +class CreateSnapshot(ebs.CreateSnapshot): + description = 'Creating a snapshot of the bootstrapped volume' + phase = phases.os_installation + after = [bootstrap.Bootstrap] + + def run(self, info): + super(CreateSnapshot, self).run(info) + msg = 'A snapshot of the bootstrapped volume was created. ID: {id}'.format(id=info.snapshot.id) + log.info(msg)