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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

focker.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from argparse import ArgumentParser
  2. import yaml
  3. import os
  4. from weir import zfs, process
  5. def clone(self, name, props={}, force=False):
  6. url = zfs._urlsplit(self.name)
  7. url_1 = zfs._urlsplit(name)
  8. if url.netloc != url_1.netloc:
  9. raise ValueError('Clone has to happen on the same host')
  10. cmd = ['zfs', 'clone']
  11. for prop, value in props.items():
  12. cmd.append('-o')
  13. cmd.append(prop + '=' + str(value))
  14. cmd.append(url.path)
  15. cmd.append(url_1.path)
  16. process.check_call(cmd, netloc=url.netloc)
  17. zfs.ZFSSnapshot.clone = clone
  18. def process_step(step, name):
  19. cmd=['jail', '-c']
  20. cmd.append('path=' + '/focker/' + name)
  21. def process_steps(steps, name):
  22. if isinstance(steps, list):
  23. for step in steps:
  24. process_step(step, name)
  25. else:
  26. process_step(steps, name)
  27. def build(args):
  28. fname = os.path.join(args.focker_dir, 'Fockerfile.yml')
  29. print('fname:', fname)
  30. if not os.path.exists(fname):
  31. raise ValueError('No Fockerfile.yml could be found in the specified directory')
  32. with open(fname, 'r') as f:
  33. spec = yaml.safe_load(f)
  34. print('spec:', spec)
  35. if 'from' not in spec:
  36. raise ValueError('Missing base specification')
  37. from_ = zfs.findprops('/', props=['focker:tags'])
  38. from_ = filter(lambda a: a['value'] == spec['from'] \
  39. and '@' in a['name'], from_)
  40. from_ = list(from_)
  41. if len(from_) == 0:
  42. raise ValueError('Requested base not found')
  43. if len(from_) > 1:
  44. raise ValueError('Ambiguous base specification')
  45. base = from_[0]['name']
  46. root = '/'.join(base.split('/')[:-1])
  47. print('base:', base)
  48. print('root:', root)
  49. base = zfs.open(base)
  50. name = '/'.join([root, 'x y z'])
  51. base.clone(name)
  52. process_steps(args['steps'], name)
  53. def run(args):
  54. pass
  55. def create_parser():
  56. parser = ArgumentParser()
  57. subparsers = parser.add_subparsers()
  58. parser_build = subparsers.add_parser('build')
  59. parser_build.set_defaults(func=build)
  60. parser_build.add_argument('focker_dir', type=str)
  61. parser_run = subparsers.add_parser('run')
  62. parser_run.set_defaults(func=run)
  63. parser_rm = subparsers.add_parser('rm')
  64. parser_rmi = subparsers.add_parser('rmi')
  65. parser_ps = subparsers.add_parser('ps')
  66. parser_images = subparsers.add_parser('images')
  67. return parser
  68. parser = create_parser()
  69. args = parser.parse_args()
  70. args.func(args)