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.0KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_run, \
  19. command_jail_list, \
  20. command_jail_tag, \
  21. command_jail_untag, \
  22. command_jail_prune
  23. def create_parser():
  24. parser_top = ArgumentParser()
  25. subparsers_top = parser_top.add_subparsers()
  26. # image
  27. subparsers = subparsers_top.add_parser('image').add_subparsers()
  28. parser = subparsers.add_parser('build')
  29. parser.set_defaults(func=command_image_build)
  30. parser.add_argument('focker_dir', type=str)
  31. parser.add_argument('--tags', '-t', type=str, nargs='+', default=[])
  32. parser = subparsers.add_parser('tag')
  33. parser.set_defaults(func=command_image_tag)
  34. parser.add_argument('reference', type=str)
  35. parser.add_argument('tags', type=str, nargs='+')
  36. parser = subparsers.add_parser('untag')
  37. parser.set_defaults(func=command_image_untag)
  38. parser.add_argument('tags', type=str, nargs='+', default=[])
  39. parser = subparsers.add_parser('list')
  40. parser.set_defaults(func=command_image_list)
  41. parser.add_argument('--full-sha256', '-f', action='store_true')
  42. parser = subparsers.add_parser('prune')
  43. parser.set_defaults(func=command_image_prune)
  44. parser = subparsers.add_parser('remove')
  45. parser.set_defaults(func=command_image_remove)
  46. parser.add_argument('reference', type=str)
  47. # parser.add_argument('--remove-children', '-r', action='store_true')
  48. parser.add_argument('--remove-dependents', '-R', action='store_true')
  49. # jail
  50. subparsers = subparsers_top.add_parser('jail').add_subparsers()
  51. parser = subparsers.add_parser('run')
  52. parser.set_defaults(func=command_jail_run)
  53. parser.add_argument('image', type=str)
  54. parser.add_argument('--command', '-c', type=str, default='/bin/sh')
  55. parser.add_argument('--mounts', '-m', type=str, nargs='+', default=[])
  56. parser = subparsers.add_parser('list')
  57. parser.set_defaults(func=command_jail_list)
  58. parser.add_argument('--full-sha256', '-f', action='store_true')
  59. parser = subparsers.add_parser('tag')
  60. parser.set_defaults(func=command_jail_tag)
  61. parser.add_argument('reference', type=str)
  62. parser.add_argument('tags', type=str, nargs='+')
  63. parser = subparsers.add_parser('untag')
  64. parser.set_defaults(func=command_jail_untag)
  65. parser.add_argument('tags', type=str, nargs='+')
  66. parser = subparsers.add_parser('prune')
  67. parser.set_defaults(func=command_jail_prune)
  68. # volume
  69. subparsers = subparsers_top.add_parser('volume').add_subparsers()
  70. parser = subparsers.add_parser('create')
  71. parser.set_defaults(func=command_volume_create)
  72. parser.add_argument('--tags', '-t', type=str, nargs='+', default=[])
  73. parser = subparsers.add_parser('prune')
  74. parser.set_defaults(func=command_volume_prune)
  75. parser = subparsers.add_parser('list')
  76. parser.set_defaults(func=command_volume_list)
  77. parser.add_argument('--full-sha256', '-f', action='store_true')
  78. parser = subparsers.add_parser('tag')
  79. parser.set_defaults(func=command_volume_tag)
  80. parser.add_argument('reference', type=str)
  81. parser.add_argument('tags', type=str, nargs='+')
  82. parser = subparsers.add_parser('untag')
  83. parser.set_defaults(func=command_volume_untag)
  84. parser.add_argument('tags', type=str, nargs='+')
  85. return parser_top
  86. def main():
  87. zfs_init()
  88. parser = create_parser()
  89. args = parser.parse_args()
  90. if not hasattr(args, 'func'):
  91. sys.exit('You must choose a mode')
  92. args.func(args)
  93. if __name__ == '__main__':
  94. main()