salt/scripts/salt-extend

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
3.3 KiB
Text
Raw Normal View History

#!/usr/bin/env python3
2020-04-02 20:10:20 -05:00
"""
Quickstart for creating an/or extending the functionality of your SaltStack installation
2016-07-25 13:59:07 +10:00
usage: salt-extend [-h] [--extension EXTENSION]
[--salt-directory SALT_DIRECTORY] [--name NAME]
[--description DESCRIPTION] [--no-merge]
optional arguments:
-h, --help show this help message and exit
--extension EXTENSION, -e EXTENSION
Extension type, e.g. 'module', 'state'.
--salt-directory SALT_DIRECTORY, -o SALT_DIRECTORY
Directory where your salt installation is kept
(defaults to .).
--name NAME, -n NAME Module name.
--description DESCRIPTION, -d DESCRIPTION
Short description of what the module does.
--no-merge Don't merge the module into the salt directory, keep
in a temp location
2020-04-02 20:10:20 -05:00
"""
import logging
2016-07-29 10:00:28 +10:00
import sys
from salt.scripts import salt_extend
2020-04-02 20:10:20 -05:00
2016-07-29 10:00:28 +10:00
PY26 = sys.version_info[0] == 2 and sys.version_info[1] == 6
def _parse_args_argparse():
2016-07-25 10:54:39 +10:00
import argparse
2016-07-25 13:59:07 +10:00
parser = argparse.ArgumentParser(
description="Quickly boilerplate an extension to SaltStack"
)
2016-07-25 10:54:39 +10:00
parser.add_argument(
"--extension", "-e", help="Extension type, e.g. 'module', 'state'."
)
parser.add_argument(
"--salt-directory",
"-o",
2016-07-25 10:54:39 +10:00
help="Directory where your salt installation is kept (defaults to .).",
2020-04-02 20:10:20 -05:00
)
2016-07-25 10:54:39 +10:00
parser.add_argument("--name", "-n", help="Module name.")
parser.add_argument(
"--description", "-d", help="Short description of what the module does."
)
2016-07-25 10:54:39 +10:00
parser.add_argument(
"--no-merge",
help="Don't merge the module into the salt directory, keep in a temp location",
action="store_true",
)
parser.add_argument(
"--debug",
help="Display detailed logs whilst applying templates",
action="store_true",
)
2016-07-29 10:00:28 +10:00
return parser.parse_args()
def _parse_args_optparse():
from optparse import OptionParser
parser = OptionParser(usage="Quickly boilerplate an extension to SaltStack")
parser.add_option(
"--extension", "-e", help="Extension type, e.g. 'module', 'state'."
)
parser.add_option(
"--salt-directory",
"-o",
help="Directory where your salt installation is kept (defaults to .).",
)
parser.add_option("--name", "-n", help="Module name.")
parser.add_option(
"--description", "-d", help="Short description of what the module does."
)
parser.add_option(
"--no-merge",
help="Don't merge the module into the salt directory, keep in a temp location",
action="store_true",
)
parser.add_option(
"--debug",
help="Display detailed logs whilst applying templates",
action="store_true",
)
return parser.parse_args()
if __name__ == "__main__":
if PY26:
(args, _) = _parse_args_optparse()
else:
args = _parse_args_argparse()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
2016-07-29 10:00:28 +10:00
salt_extend(
extension=args.extension,
name=args.name,
description=args.description,
salt_dir=args.salt_directory,
merge=not args.no_merge,
)