Use remount() to create a clean snapshot

This commit is contained in:
Anders Ingemann 2013-10-06 14:44:23 +02:00
parent b025f6ed35
commit ceae489210
2 changed files with 11 additions and 8 deletions

View file

@ -28,11 +28,12 @@ def remount(volume, fn):
p_map.root.unmount()
if not isinstance(p_map, NoPartitions):
p_map.unmap(volume)
fn()
result = fn()
p_map.map(volume)
else:
fn()
result = fn()
p_map.root.mount(root_dir)
if hasattr(p_map, 'boot'):
p_map.boot.mount(boot_dir)
volume.mount_specials()
return result

View file

@ -1,9 +1,9 @@
from base import Task
from common import phases
from providers.ec2.tasks import ebs
from common.tasks import volume
from common.tasks import bootstrap
from common.tasks import filesystem
from common.fs import remount
from shutil import copyfile
import os.path
import time
@ -11,14 +11,16 @@ import logging
log = logging.getLogger(__name__)
class Snapshot(ebs.Snapshot):
class Snapshot(Task):
description = 'Creating a snapshot of the bootstrapped volume'
phase = phases.os_installation
after = [bootstrap.Bootstrap]
after = [bootstrap.Bootstrap, filesystem.MountSpecials]
def run(self, info):
super(Snapshot, self).run(info)
msg = 'A snapshot of the bootstrapped volume was created. ID: {id}'.format(id=info.snapshot.id)
def mk_snapshot():
return info.volume.snapshot()
snapshot = remount(info.volume, mk_snapshot)
msg = 'A snapshot of the bootstrapped volume was created. ID: {id}'.format(id=snapshot.id)
log.info(msg)
@ -43,7 +45,7 @@ class CreateFromSnapshot(Task):
class CopyImage(Task):
description = 'Creating a snapshot of the bootstrapped volume'
phase = phases.os_installation
after = [bootstrap.Bootstrap]
after = [bootstrap.Bootstrap, filesystem.MountSpecials]
def run(self, info):
loopback_backup_name = 'volume-{id:x}.{ext}.backup'.format(id=info.run_id, ext=info.volume.extension)