1
0

salt-extend 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python
  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. from salt.scripts import salt_extend
  22. import sys
  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(description="Quickly boilerplate an extension to SaltStack")
  27. parser.add_argument(
  28. "--extension",
  29. "-e",
  30. help="Extension type, e.g. 'module', 'state'.")
  31. parser.add_argument(
  32. "--salt-directory",
  33. "-o",
  34. help="Directory where your salt installation is kept (defaults to .).")
  35. parser.add_argument(
  36. "--name",
  37. "-n",
  38. help="Module name.")
  39. parser.add_argument(
  40. "--description",
  41. "-d",
  42. help="Short description of what the module does.")
  43. parser.add_argument(
  44. "--no-merge",
  45. help="Don't merge the module into the salt directory, keep in a temp location",
  46. action="store_true")
  47. parser.add_argument(
  48. "--debug",
  49. help="Display detailed logs whilst applying templates",
  50. action="store_true")
  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",
  57. "-e",
  58. help="Extension type, e.g. 'module', 'state'.")
  59. parser.add_option(
  60. "--salt-directory",
  61. "-o",
  62. help="Directory where your salt installation is kept (defaults to .).")
  63. parser.add_option(
  64. "--name",
  65. "-n",
  66. help="Module name.")
  67. parser.add_option(
  68. "--description",
  69. "-d",
  70. help="Short description of what the module does.")
  71. parser.add_option(
  72. "--no-merge",
  73. help="Don't merge the module into the salt directory, keep in a temp location",
  74. action="store_true")
  75. parser.add_option(
  76. "--debug",
  77. help="Display detailed logs whilst applying templates",
  78. action="store_true")
  79. return parser.parse_args()
  80. if __name__ == '__main__':
  81. if PY26:
  82. (args, _) = _parse_args_optparse()
  83. else:
  84. args = _parse_args_argparse()
  85. if args.debug:
  86. logging.basicConfig(level=logging.DEBUG)
  87. salt_extend(
  88. extension=args.extension,
  89. name=args.name,
  90. description=args.description,
  91. salt_dir=args.salt_directory,
  92. merge=not args.no_merge)