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 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. from argparse import ArgumentParser
  2. import yaml
  3. import os
  4. # from weir import zfs, process
  5. from .image import command_image_build, \
  6. command_image_tag, \
  7. command_image_untag, \
  8. command_image_list, \
  9. command_image_prune, \
  10. command_image_remove
  11. from .volume import command_volume_create, \
  12. command_volume_prune, \
  13. command_volume_list, \
  14. command_volume_tag, \
  15. command_volume_untag
  16. import sys
  17. from .zfs import zfs_init
  18. from .jail import command_jail_create, \
  19. command_jail_run, \
  20. command_jail_list, \
  21. command_jail_tag, \
  22. command_jail_untag, \
  23. command_jail_prune
  24. def create_parser():
  25. parser_top = ArgumentParser()
  26. subparsers_top = parser_top.add_subparsers()
  27. # image
  28. subparsers = subparsers_top.add_parser('image').add_subparsers()
  29. parser = subparsers.add_parser('build')
  30. parser.set_defaults(func=command_image_build)
  31. parser.add_argument('focker_dir', type=str)
  32. parser.add_argument('--tags', '-t', type=str, nargs='+', default=[])
  33. parser = subparsers.add_parser('tag')
  34. parser.set_defaults(func=command_image_tag)
  35. parser.add_argument('reference', type=str)
  36. parser.add_argument('tags', type=str, nargs='+')
  37. parser = subparsers.add_parser('untag')
  38. parser.set_defaults(func=command_image_untag)
  39. parser.add_argument('tags', type=str, nargs='+', default=[])
  40. parser = subparsers.add_parser('list')
  41. parser.set_defaults(func=command_image_list)
  42. parser.add_argument('--full-sha256', '-f', action='store_true')
  43. parser = subparsers.add_parser('prune')
  44. parser.set_defaults(func=command_image_prune)
  45. parser = subparsers.add_parser('remove')
  46. parser.set_defaults(func=command_image_remove)
  47. parser.add_argument('reference', type=str)
  48. # parser.add_argument('--remove-children', '-r', action='store_true')
  49. parser.add_argument('--remove-dependents', '-R', action='store_true')
  50. # jail
  51. subparsers = subparsers_top.add_parser('jail').add_subparsers()
  52. parser = subparsers.add_parser('create')
  53. parser.set_defaults(func=command_jail_create)
  54. parser.add_argument('image', type=str)
  55. parser.add_argument('--command', '-c', type=str, default='/bin/sh')
  56. parser.add_argument('--tags', '-t', type=str, nargs='+', default=[])
  57. parser.add_argument('--env', '-e', type=str, nargs='+', default=[])
  58. parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[])
  59. parser.add_argument('--hostname', '-n', type=str)
  60. parser = subparsers.add_parser('run')
  61. parser.set_defaults(func=command_jail_run)
  62. parser.add_argument('image', type=str)
  63. parser.add_argument('--command', '-c', type=str, default='/bin/sh')
  64. parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[])
  65. parser = subparsers.add_parser('list')
  66. parser.set_defaults(func=command_jail_list)
  67. parser.add_argument('--full-sha256', '-f', action='store_true')
  68. parser = subparsers.add_parser('tag')
  69. parser.set_defaults(func=command_jail_tag)
  70. parser.add_argument('reference', type=str)
  71. parser.add_argument('tags', type=str, nargs='+')
  72. parser = subparsers.add_parser('untag')
  73. parser.set_defaults(func=command_jail_untag)
  74. parser.add_argument('tags', type=str, nargs='+')
  75. parser = subparsers.add_parser('prune')
  76. parser.set_defaults(func=command_jail_prune)
  77. parser.add_argument('--force', '-f', action='store_true')
  78. # volume
  79. subparsers = subparsers_top.add_parser('volume').add_subparsers()
  80. parser = subparsers.add_parser('create')
  81. parser.set_defaults(func=command_volume_create)
  82. parser.add_argument('--tags', '-t', type=str, nargs='+', default=[])
  83. parser = subparsers.add_parser('prune')
  84. parser.set_defaults(func=command_volume_prune)
  85. parser = subparsers.add_parser('list')
  86. parser.set_defaults(func=command_volume_list)
  87. parser.add_argument('--full-sha256', '-f', action='store_true')
  88. parser = subparsers.add_parser('tag')
  89. parser.set_defaults(func=command_volume_tag)
  90. parser.add_argument('reference', type=str)
  91. parser.add_argument('tags', type=str, nargs='+')
  92. parser = subparsers.add_parser('untag')
  93. parser.set_defaults(func=command_volume_untag)
  94. parser.add_argument('tags', type=str, nargs='+')
  95. return parser_top
  96. def main():
  97. zfs_init()
  98. parser = create_parser()
  99. args = parser.parse_args()
  100. if not hasattr(args, 'func'):
  101. sys.exit('You must choose a mode')
  102. args.func(args)
  103. if __name__ == '__main__':
  104. main()