bootstrap-vz/base/main.py

49 lines
1.5 KiB
Python
Raw Normal View History

import logging
log = logging.getLogger(__name__)
2013-05-16 08:00:28 +02:00
def main():
2013-06-23 22:30:41 +02:00
import log
2013-06-09 20:29:54 +02:00
args = get_args()
2013-06-23 22:30:41 +02:00
logfile = log.get_logfile_path(args.manifest)
log.setup_logger(logfile=logfile, debug=args.debug)
2013-06-09 20:29:54 +02:00
run(args)
2013-06-26 20:14:37 +02:00
2013-06-09 20:29:54 +02:00
def get_args():
2013-05-16 08:00:28 +02:00
from argparse import ArgumentParser
parser = ArgumentParser(description='Bootstrap Debian for the cloud.')
parser.add_argument('--debug', action='store_true',
help='Print debugging information')
parser.add_argument('manifest', help='Manifest file to use for bootstrapping', metavar='MANIFEST')
2013-06-09 20:29:54 +02:00
return parser.parse_args()
2013-05-16 08:00:28 +02:00
def run(args):
from manifest import load_manifest
(provider, manifest) = load_manifest(args.manifest)
2013-05-16 08:00:28 +02:00
2013-06-09 16:23:08 +02:00
from tasklist import TaskList
tasklist = TaskList()
provider.tasks(tasklist, manifest)
for plugin in manifest.loaded_plugins:
plugin.tasks(tasklist, manifest)
2013-05-16 08:00:28 +02:00
2013-06-09 16:15:23 +02:00
from bootstrapinfo import BootstrapInformation
bootstrap_info = BootstrapInformation(manifest=manifest, debug=args.debug)
try:
tasklist.run(bootstrap_info)
log.info('Successfully completed bootstrapping')
2013-06-30 20:06:49 +02:00
except (Exception, KeyboardInterrupt) as e:
log.exception(e)
log.error('Rolling back')
rollback_tasklist = TaskList()
provider.rollback_tasks(rollback_tasklist, tasklist.tasks_completed, manifest)
for plugin in manifest.loaded_plugins:
rollback_tasks = getattr(plugin, 'rollback_tasks', None)
if callable(rollback_tasks):
plugin.rollback_tasks(rollback_tasklist, tasklist.tasks_completed, manifest)
rollback_tasklist.run(bootstrap_info)
log.info('Successfully completed rollback')