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 kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

36 lines
1.4KB

  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. try:
  9. res = subprocess.run(command)
  10. finally:
  11. subprocess.run(['umount', os.path.join(path, 'dev')])
  12. if res.returncode != 0:
  13. subprocess.run(['umount', os.path.join(path, 'dev')])
  14. raise RuntimeError('Command failed')
  15. def command_jail_run(args):
  16. base, _ = zfs_snapshot_by_tag_or_sha256(args.image)
  17. # root = '/'.join(base.split('/')[:-1])
  18. for _ in range(10**6):
  19. name = bytes([ random.randint(0, 255) for _ in range(4) ]).hex()[:7]
  20. name = base.split('/')[0] + '/focker/jails/' + name
  21. if not zfs_exists(name):
  22. break
  23. zfs_run(['zfs', 'clone', base, name])
  24. try:
  25. shutil.copyfile('/etc/resolv.conf', os.path.join(zfs_mountpoint(name), 'etc/resolv.conf'))
  26. jail_run(zfs_mountpoint(name), args.command)
  27. # subprocess.check_output(['jail', '-c', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + zfs_mountpoint(name), 'command', command])
  28. finally:
  29. subprocess.run(['umount', zfs_mountpoint(name) + '/dev'])
  30. zfs_run(['zfs', 'destroy', '-f', name])
  31. # raise