2013-06-30 23:26:45 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
2013-06-30 23:56:09 +02:00
|
|
|
from providers.ec2.tasks import connection
|
|
|
|
from providers.ec2.tasks import ebs
|
2013-07-09 20:45:57 +02:00
|
|
|
from providers.ec2.tasks import bootstrap
|
2013-06-30 23:26:45 +02:00
|
|
|
import time
|
2013-07-09 20:45:57 +02:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
2013-06-30 23:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CreateVolumeFromSnapshot(Task):
|
2013-07-09 20:32:50 +02:00
|
|
|
description = 'Creating EBS volume from a snapshot'
|
2013-06-30 23:26:45 +02:00
|
|
|
phase = phases.volume_creation
|
2013-06-30 23:56:09 +02:00
|
|
|
after = [connection.Connect]
|
|
|
|
before = [ebs.AttachVolume]
|
2013-06-30 23:26:45 +02:00
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
volume_size = int(info.manifest.volume['size']/1024)
|
2013-06-30 23:56:09 +02:00
|
|
|
snapshot = info.manifest.plugins['prebootstrapped']['snapshot']
|
2013-06-30 23:26:45 +02:00
|
|
|
info.volume = info.connection.create_volume(volume_size,
|
|
|
|
info.host['availabilityZone'],
|
2013-06-30 23:56:09 +02:00
|
|
|
snapshot=snapshot)
|
2013-06-30 23:26:45 +02:00
|
|
|
while info.volume.volume_state() != 'available':
|
|
|
|
time.sleep(5)
|
|
|
|
info.volume.update()
|
2013-07-09 20:45:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
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)
|