From b2201e65708f609dc4397e2683e79f79bd3f9161 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Tue, 28 Apr 2020 15:10:56 +0200 Subject: [PATCH] Added focker bootstrap command. --- focker/bootstrap.py | 22 ++++++++++++++++++++++ focker/focker.py | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 focker/bootstrap.py diff --git a/focker/bootstrap.py b/focker/bootstrap.py new file mode 100644 index 0000000..527d189 --- /dev/null +++ b/focker/bootstrap.py @@ -0,0 +1,22 @@ +import subprocess +import hashlib +from .misc import find_prefix +from .zfs import zfs_poolname, \ + zfs_mountpoint, \ + zfs_tag + + +def command_bootstrap(args): + version = subprocess.check_output(['freebsd-version']).decode('utf-8') + print('FreeBSD version:', version) + tags = [ 'freebsd-' + version.split('-')[0], 'freebsd-latest' ] + sha256 = hashlib.sha256(('FreeBSD ' + version).encode('utf-8')).hexdigest() + poolname = zfs_poolname() + name = find_prefix(poolname + '/focker/images/', sha256) + subprocess.check_output(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) + zfs_tag(name, tags) + res = subprocess.run(['bsdinstall', 'jail', zfs_mountpoint(name)]) + if res.returncode != 0: + raise ValueError('bsdinstall failed') + subprocess.check_output(['zfs', 'set', 'rdonly=on', name]) + subprocess.check_output(['zfs', 'snapshot', name + '@1']) diff --git a/focker/focker.py b/focker/focker.py index 6ce8cf5..6596e0a 100644 --- a/focker/focker.py +++ b/focker/focker.py @@ -37,6 +37,7 @@ from .jail import command_jail_create, \ from .compose import \ command_compose_build, \ command_compose_run +from .bootstrap import command_bootstrap class ListForwarderFunctor(object): @@ -71,6 +72,9 @@ def create_parser(): subparsers_top = parser_top.add_subparsers(dest='L1_command') subparsers_top.required = True + parser = ListForwarder([subparsers_top.add_parser(cmd) for cmd in ['bootstrap', 'boot', 'bs']]) + parser.set_defaults(func=command_bootstrap) + # image subparsers = ListForwarder([ subparsers_top.add_parser(cmd).add_subparsers(dest='L2_command') \ for cmd in ['image', 'ima', 'img', 'im', 'i'] ])