salt/scripts/salt-extend

104 lines
3.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
'''
Quickstart for creating an/or extending the functionality of your SaltStack installation
2016-07-25 03:59:07 +00: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
'''
import logging
from salt.scripts import salt_extend
2016-07-29 00:00:28 +00:00
import sys
2016-07-29 00:00:28 +00:00
PY26 = sys.version_info[0] == 2 and sys.version_info[1] == 6
def _parse_args_argparse():
2016-07-25 00:54:39 +00:00
import argparse
2016-07-25 03:59:07 +00:00
parser = argparse.ArgumentParser(description="Quickly boilerplate an extension to SaltStack")
2016-07-25 00:54:39 +00:00
parser.add_argument(
"--extension",
"-e",
help="Extension type, e.g. 'module', 'state'.")
parser.add_argument(
"--salt-directory",
"-o",
2016-07-25 00:54:39 +00:00
help="Directory where your salt installation is kept (defaults to .).")
parser.add_argument(
"--name",
"-n",
help="Module name.")
parser.add_argument(
"--description",
"-d",
help="Short description of what the module does.")
2016-07-25 00:54:39 +00: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 00:00:28 +00: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 00:00:28 +00:00
salt_extend(
extension=args.extension,
name=args.name,
description=args.description,
salt_dir=args.salt_directory,
merge=not args.no_merge)