IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
ソースを参照

Added focker jail list

tags/0.92
コミット
d94c1cac73
3個のファイルの変更30行の追加3行の削除
  1. +6
    -1
      focker.py
  2. +15
    -2
      jail.py
  3. +9
    -0
      zfs.py

+ 6
- 1
focker.py ファイルの表示

@@ -15,7 +15,8 @@ from .volume import command_volume_create, \
command_volume_untag
import sys
from .zfs import zfs_init
from .jail import command_jail_run
from .jail import command_jail_run, \
command_jail_list
def create_parser():
@@ -59,6 +60,10 @@ def create_parser():
parser.add_argument('--command', '-c', type=str, default='/bin/sh')
parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[])
parser = subparsers.add_parser('list')
parser.set_defaults(func=command_jail_list)
parser.add_argument('--full-sha256', '-f', action='store_true')
# volume
subparsers = subparsers_top.add_parser('volume').add_subparsers()
parser = subparsers.add_parser('create')


+ 15
- 2
jail.py ファイルの表示

@@ -3,6 +3,7 @@ from .zfs import *
import random
import shutil
import json
from tabulate import tabulate
def get_jid(path):
@@ -59,11 +60,12 @@ def command_jail_run(args):
base, _ = zfs_snapshot_by_tag_or_sha256(args.image)
# root = '/'.join(base.split('/')[:-1])
for _ in range(10**6):
name = bytes([ random.randint(0, 255) for _ in range(4) ]).hex()[:7]
sha256 = bytes([ random.randint(0, 255) for _ in range(32) ]).hex()
name = sha256[:7]
name = base.split('/')[0] + '/focker/jails/' + name
if not zfs_exists(name):
break
zfs_run(['zfs', 'clone', base, name])
zfs_run(['zfs', 'clone', '-o', 'focker:sha256=' + sha256, base, name])
try:
mounts = list(map(lambda a: a.split(':'), args.mounts))
jail_run(zfs_mountpoint(name), args.command, mounts)
@@ -72,3 +74,14 @@ def command_jail_run(args):
# subprocess.run(['umount', zfs_mountpoint(name) + '/dev'])
zfs_run(['zfs', 'destroy', '-f', name])
# raise
def command_jail_list(args):
lst = zfs_list(fields=['focker:sha256,focker:tags,mountpoint'], focker_type='jail')
jails = subprocess.check_output(['jls', '--libxo=json'])
jails = json.loads(jails)['jail-information']['jail']
jails = { j['path']: j for j in jails }
lst = list(map(lambda a: [ a[1],
a[0] if args.full_sha256 else a[0][:7],
a[2],
jails[a[2]]['jid'] if a[2] in jails else '-' ], lst))
print(tabulate(lst, headers=['Tags', 'SHA256', 'mountpoint', 'JID']))

+ 9
- 0
zfs.py ファイルの表示

@@ -49,6 +49,15 @@ def zfs_find(reference, focker_type='image', zfs_type='filesystem'):
return (lst[0][3], lst[0][0])
def zfs_list(fields=['name'], focker_type='image', zfs_type='filesystem'):
poolname = zfs_poolname()
fields.append('focker:sha256')
lst = zfs_parse_output(['zfs', 'list', '-o', ','.join(fields),
'-H', '-t', zfs_type, '-r', poolname + '/focker/' + focker_type + 's'])
lst = list(filter(lambda a: a[-1] != '-', lst))
return lst
def zfs_prune(focker_type='image'):
poolname = zfs_poolname()
again = True


読み込み中…
キャンセル
保存