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!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

151 linhas
5.3KB

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