Prebootstrapped plugin now autocreates a snapshot

of the bootstrapped plugin, if no snapshot ID is provided.
This commit is contained in:
Anders Ingemann 2013-07-09 20:45:57 +02:00
parent 4e2503ad9c
commit 55741b822f
2 changed files with 24 additions and 6 deletions

View file

@ -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):

View file

@ -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)