1
0

index.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .. _development-salt-extend:
  2. ===========
  3. Salt Extend
  4. ===========
  5. ``salt-extend`` is a templating tool for extending SaltStack. If you're looking to add a module to
  6. SaltStack, then the ``salt-extend`` utility can guide you through the process.
  7. You can use Salt Extend to quickly create templated modules for adding new behaviours to some of the module subsystems within Salt.
  8. Salt Extend takes a template directory and merges it into a SaltStack source code directory.
  9. Command line usage
  10. ------------------
  11. *See* :ref:`salt-extend <salt-extend>`
  12. Choosing a template
  13. -------------------
  14. The following templates are available:
  15. module
  16. ******
  17. Creates a new execution module within salt/modules/{{module_name}}.py
  18. module_unit
  19. ***********
  20. Creates a new execution module unit test suite within tests/unit/modules/test_{{module_name}}.py
  21. state
  22. *****
  23. Creates a new state module within salt/states/{{module_name}}.py
  24. state_unit
  25. **********
  26. Creates a new state module unit test suite within tests/unit/states/test_{{module_name}}.py
  27. Adding templates
  28. ----------------
  29. 1. Create a directory under <src>/templates
  30. 2. Create a file ``template.yml`` containing properties for
  31. * ``description`` - a description of the template
  32. * ``questions`` - a collection of additional questions to ask the user, the name of the item will
  33. be used as the key in the context dictionary within the jinja template.
  34. * ``question`` - The question to ask the user, as a string
  35. * ``default`` - (optional) the default value, can contain Jinja2 template syntax and has access to the default context properties
  36. Example template.yml
  37. ********************
  38. .. code-block:: yaml
  39. description: "Execution module"
  40. questions:
  41. depending_libraries:
  42. question: "What libraries does this module depend upon?"
  43. virtual_name:
  44. question: "What module virtual name to use?"
  45. default: "{{module_name}}"
  46. 3. Create the files within <src>/templates/<your template> to match the target
  47. .. note::
  48. File names can contain Jinja 2 template syntax, e.g. *'{{module_name}}.py}}'*
  49. Example file in the template directory
  50. **************************************
  51. .. code-block:: python
  52. print("Hello {{module_name}}")
  53. __virtual__ = "{{__virtual_name__}}"
  54. Default context properties
  55. **************************
  56. The default context provides the following properties
  57. * ``description`` - A description of the template
  58. * ``short_description`` - A short description of the module as entered by the user
  59. * ``version`` - The version name of the next release
  60. * ``module_name`` - The module name as entered by the user
  61. * ``release_date`` - The current date in the format *YYYY-MM-DD*
  62. * ``year`` - The current year in the format *YYYY*
  63. As well as any additional properties entered from the questions section of ``template.yml``
  64. API
  65. ---
  66. salt.utils.extend module
  67. ************************
  68. .. automodule:: salt.utils.extend
  69. :members: