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!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

32 Zeilen
1.3KB

  1. import subprocess
  2. from .zfs import *
  3. import random
  4. import shutil
  5. def jail_run(path, command):
  6. command = ['jail', '-c', 'host.hostname=' + os.path.split(path)[1], 'mount.devfs=1', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + path, 'command', '/bin/sh', '-c', command]
  7. print('Running:', ' '.join(command))
  8. res = subprocess.run(command)
  9. if res.returncode != 0:
  10. raise RuntimeError('Command failed')
  11. def command_jail_run(args):
  12. base, _ = zfs_snapshot_by_tag_or_sha256(args.image)
  13. # root = '/'.join(base.split('/')[:-1])
  14. for _ in range(10**6):
  15. name = bytes([ random.randint(0, 256) for _ in range(4) ]).hex()[:7]
  16. name = base.split('/')[0] + '/focker/jails/' + name
  17. if not zfs_exists(name):
  18. break
  19. zfs_run(['zfs', 'clone', base, name])
  20. try:
  21. shutil.copyfile('/etc/resolv.conf', os.path.join(zfs_mountpoint(name), 'etc/resolv.conf'))
  22. jail_run(zfs_mountpoint(name), args.command)
  23. # subprocess.check_output(['jail', '-c', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + zfs_mountpoint(name), 'command', command])
  24. finally:
  25. subprocess.run(['umount', zfs_mountpoint(name) + '/dev'])
  26. zfs_run(['zfs', 'destroy', '-f', name])
  27. # raise