@@ -1,4 +1,5 @@ | |||
from argparse import ArgumentParser | |||
import argparse | |||
import yaml | |||
import os | |||
# from weir import zfs, process | |||
@@ -16,6 +17,10 @@ from .volume import command_volume_create, \ | |||
import sys | |||
from .zfs import zfs_init | |||
from .jail import command_jail_create, \ | |||
command_jail_start, \ | |||
command_jail_stop, \ | |||
command_jail_remove, \ | |||
command_jail_exec, \ | |||
command_jail_run, \ | |||
command_jail_list, \ | |||
command_jail_tag, \ | |||
@@ -67,6 +72,23 @@ def create_parser(): | |||
parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[]) | |||
parser.add_argument('--hostname', '-n', type=str) | |||
parser = subparsers.add_parser('start') | |||
parser.set_defaults(func=command_jail_start) | |||
parser.add_argument('reference', type=str) | |||
parser = subparsers.add_parser('stop') | |||
parser.set_defaults(func=command_jail_stop) | |||
parser.add_argument('reference', type=str) | |||
parser = subparsers.add_parser('remove') | |||
parser.set_defaults(func=command_jail_remove) | |||
parser.add_argument('reference', type=str) | |||
parser = subparsers.add_parser('exec') | |||
parser.set_defaults(func=command_jail_exec) | |||
parser.add_argument('reference', type=str) | |||
parser.add_argument('command', type=str, nargs=argparse.REMAINDER, default=['/bin/sh']) | |||
parser = subparsers.add_parser('run') | |||
parser.set_defaults(func=command_jail_run) | |||
parser.add_argument('image', type=str) | |||
@@ -116,9 +116,12 @@ def jail_run(path, command, mounts=[]): | |||
def jail_stop(path): | |||
try: | |||
jid = get_jid(path) | |||
subprocess.run(['jail', '-r', jid]) | |||
jailname = os.path.split(path)[-1] | |||
subprocess.run(['jail', '-r', jailname]) | |||
except ValueError: | |||
print('JID could not be determined') | |||
# import time | |||
# time.sleep(1) | |||
mi = getmntinfo() | |||
for m in mi: | |||
mntonname = m['f_mntonname'].decode('utf-8') | |||
@@ -165,6 +168,32 @@ def command_jail_create(args): | |||
print(path) | |||
def command_jail_start(args): | |||
name, _ = zfs_find(args.reference, focker_type='jail') | |||
path = zfs_mountpoint(name) | |||
jailname = os.path.split(path)[-1] | |||
subprocess.run(['jail', '-c', jailname]) | |||
def command_jail_stop(args): | |||
name, _ = zfs_find(args.reference, focker_type='jail') | |||
path = zfs_mountpoint(name) | |||
jail_stop(path) | |||
def command_jail_remove(args): | |||
name, _ = zfs_find(args.reference, focker_type='jail') | |||
path = zfs_mountpoint(name) | |||
jail_remove(path) | |||
def command_jail_exec(args): | |||
name, _ = zfs_find(args.reference, focker_type='jail') | |||
path = zfs_mountpoint(name) | |||
jid = get_jid(path) | |||
subprocess.run(['jexec', str(jid)] + args.command) | |||
def command_jail_run(args): | |||
base, _ = zfs_snapshot_by_tag_or_sha256(args.image) | |||
# root = '/'.join(base.split('/')[:-1]) | |||