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 ability to mount volumes in focker jail run

tags/0.92
コミット
156dcfffce
3個のファイルの変更30行の追加5行の削除
  1. +1
    -0
      focker.py
  2. +25
    -2
      jail.py
  3. +4
    -3
      volume.py

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

@@ -57,6 +57,7 @@ def create_parser():
parser.set_defaults(func=command_jail_run)
parser.add_argument('image', type=str)
parser.add_argument('--command', '-c', type=str, default='/bin/sh')
parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[])
# volume
subparsers = subparsers_top.add_parser('volume').add_subparsers()


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

@@ -16,10 +16,31 @@ def get_jid(path):
return str(lst[0]['jid'])
def jail_run(path, command):
def do_mounts(path, mounts):
print('mounts:', mounts)
for (source, target) in mounts:
if source.startswith('/'):
name = source
else:
name, _ = zfs_find(source, focker_type='volume')
name = zfs_mountpoint(name)
while target.startswith('/'):
target = target[1:]
subprocess.check_output(['mount', '-t', 'nullfs', name, os.path.join(path, target)])
def undo_mounts(path, mounts):
for (_, target) in reversed(mounts):
while target.startswith('/'):
target = target[1:]
subprocess.check_output(['umount', '-f', os.path.join(path, target)])
def jail_run(path, command, mounts=[]):
command = ['jail', '-c', 'host.hostname=' + os.path.split(path)[1], 'persist=1', 'mount.devfs=1', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + path, 'command', '/bin/sh', '-c', command]
print('Running:', ' '.join(command))
try:
do_mounts(path, mounts)
shutil.copyfile('/etc/resolv.conf', os.path.join(path, 'etc/resolv.conf'))
res = subprocess.run(command)
finally:
@@ -28,6 +49,7 @@ def jail_run(path, command):
except ValueError:
pass
subprocess.run(['umount', '-f', os.path.join(path, 'dev')])
undo_mounts(path, mounts)
if res.returncode != 0:
# subprocess.run(['umount', os.path.join(path, 'dev')])
raise RuntimeError('Command failed')
@@ -43,7 +65,8 @@ def command_jail_run(args):
break
zfs_run(['zfs', 'clone', base, name])
try:
jail_run(zfs_mountpoint(name), args.command)
mounts = list(map(lambda a: a.split(':'), args.mounts))
jail_run(zfs_mountpoint(name), args.command, mounts)
# subprocess.check_output(['jail', '-c', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + zfs_mountpoint(name), 'command', command])
finally:
# subprocess.run(['umount', zfs_mountpoint(name) + '/dev'])


+ 4
- 3
volume.py ファイルの表示

@@ -20,11 +20,12 @@ def command_volume_prune(args):
def command_volume_list(args):
poolname = zfs_poolname()
lst = zfs_parse_output(['zfs', 'list', '-o', 'name,refer,focker:sha256,focker:tags', '-H', '-r', poolname + '/focker/volumes'])
lst = zfs_parse_output(['zfs', 'list', '-o', 'name,refer,focker:sha256,focker:tags,mountpoint', '-H', '-r', poolname + '/focker/volumes'])
lst = list(filter(lambda a: a[2] != '-', lst))
lst = list(map(lambda a: [ a[3], a[1],
a[2] if args.full_sha256 else a[2][:7] ], lst))
print(tabulate(lst, headers=['Tags', 'Size', 'SHA256']))
a[2] if args.full_sha256 else a[2][:7],
a[4] ], lst))
print(tabulate(lst, headers=['Tags', 'Size', 'SHA256', 'Mountpoint']))
def command_volume_tag(args):


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