1
0

salt-extend 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python3
  2. """
  3. Quickstart for creating an/or extending the functionality of your SaltStack installation
  4. usage: salt-extend [-h] [--extension EXTENSION]
  5. [--salt-directory SALT_DIRECTORY] [--name NAME]
  6. [--description DESCRIPTION] [--no-merge]
  7. optional arguments:
  8. -h, --help show this help message and exit
  9. --extension EXTENSION, -e EXTENSION
  10. Extension type, e.g. 'module', 'state'.
  11. --salt-directory SALT_DIRECTORY, -o SALT_DIRECTORY
  12. Directory where your salt installation is kept
  13. (defaults to .).
  14. --name NAME, -n NAME Module name.
  15. --description DESCRIPTION, -d DESCRIPTION
  16. Short description of what the module does.
  17. --no-merge Don't merge the module into the salt directory, keep
  18. in a temp location
  19. """
  20. import logging
  21. import sys
  22. from salt.scripts import salt_extend
  23. PY26 = sys.version_info[0] == 2 and sys.version_info[1] == 6
  24. def _parse_args_argparse():
  25. import argparse
  26. parser = argparse.ArgumentParser(
  27. description="Quickly boilerplate an extension to SaltStack"
  28. )
  29. parser.add_argument(
  30. "--extension", "-e", help="Extension type, e.g. 'module', 'state'."
  31. )
  32. parser.add_argument(
  33. "--salt-directory",
  34. "-o",
  35. help="Directory where your salt installation is kept (defaults to .).",
  36. )
  37. parser.add_argument("--name", "-n", help="Module name.")
  38. parser.add_argument(
  39. "--description", "-d", help="Short description of what the module does."
  40. )
  41. parser.add_argument(
  42. "--no-merge",
  43. help="Don't merge the module into the salt directory, keep in a temp location",
  44. action="store_true",
  45. )
  46. parser.add_argument(
  47. "--debug",
  48. help="Display detailed logs whilst applying templates",
  49. action="store_true",
  50. )
  51. return parser.parse_args()
  52. def _parse_args_optparse():
  53. from optparse import OptionParser
  54. parser = OptionParser(usage="Quickly boilerplate an extension to SaltStack")
  55. parser.add_option(
  56. "--extension", "-e", help="Extension type, e.g. 'module', 'state'."
  57. )
  58. parser.add_option(
  59. "--salt-directory",
  60. "-o",
  61. help="Directory where your salt installation is kept (defaults to .).",
  62. )
  63. parser.add_option("--name", "-n", help="Module name.")
  64. parser.add_option(
  65. "--description", "-d", help="Short description of what the module does."
  66. )
  67. parser.add_option(
  68. "--no-merge",
  69. help="Don't merge the module into the salt directory, keep in a temp location",
  70. action="store_true",
  71. )
  72. parser.add_option(
  73. "--debug",
  74. help="Display detailed logs whilst applying templates",
  75. action="store_true",
  76. )
  77. return parser.parse_args()
  78. if __name__ == "__main__":
  79. if PY26:
  80. (args, _) = _parse_args_optparse()
  81. else:
  82. args = _parse_args_argparse()
  83. if args.debug:
  84. logging.basicConfig(level=logging.DEBUG)
  85. salt_extend(
  86. extension=args.extension,
  87. name=args.name,
  88. description=args.description,
  89. salt_dir=args.salt_directory,
  90. merge=not args.no_merge,
  91. )