Merge inventory from beta branch.
This commit is contained in:
parent
2b6177c9f7
commit
e2a1519332
28 changed files with 1769 additions and 36 deletions
|
|
@ -7,10 +7,10 @@ import collections
|
|||
|
||||
|
||||
# set of beta sub-commands
|
||||
BETA_COMMANDS = set(('install', ))
|
||||
BETA_COMMANDS = set(('install', 'inventory', ))
|
||||
# set of beta arguments for sub-commands
|
||||
BETA_ARGS = {
|
||||
'config': set(('jobs', )),
|
||||
'config': set(('jobs', 'tag', 'all_tagged_hosts', )),
|
||||
}
|
||||
EPILOG = "Get cdist at http://www.nico.schottelius.org/software/cdist/"
|
||||
# Parser others can reuse
|
||||
|
|
@ -121,6 +121,17 @@ def get_parsers():
|
|||
'banner', parents=[parser['loglevel']])
|
||||
parser['banner'].set_defaults(func=cdist.banner.banner)
|
||||
|
||||
parser['inventory_common'] = argparse.ArgumentParser(add_help=False)
|
||||
parser['inventory_common'].add_argument(
|
||||
'-I', '--inventory',
|
||||
help=('Use specified custom inventory directory. '
|
||||
'Inventory directory is set up by the following rules: '
|
||||
'if this argument is set then specified directory is used, '
|
||||
'if CDIST_INVENTORY_DIR env var is set then its value is '
|
||||
'used, if HOME env var is set then ~/.cdist/inventory is '
|
||||
'used, otherwise distribution inventory directory is used.'),
|
||||
dest="inventory_dir", required=False)
|
||||
|
||||
# Config
|
||||
parser['config_main'] = argparse.ArgumentParser(add_help=False)
|
||||
parser['config_main'].add_argument(
|
||||
|
|
@ -156,6 +167,10 @@ def get_parsers():
|
|||
# remote-copy and remote-exec defaults are environment variables
|
||||
# if set; if not then None - these will be futher handled after
|
||||
# parsing to determine implementation default
|
||||
parser['config_main'].add_argument(
|
||||
'-r', '--remote-out-dir',
|
||||
help='Directory to save cdist output in on the target host',
|
||||
dest="remote_out_path")
|
||||
parser['config_main'].add_argument(
|
||||
'--remote-copy',
|
||||
help='Command to use for remote copy (should behave like scp)',
|
||||
|
|
@ -170,6 +185,15 @@ def get_parsers():
|
|||
|
||||
# Config
|
||||
parser['config_args'] = argparse.ArgumentParser(add_help=False)
|
||||
parser['config_args'].add_argument(
|
||||
'-A', '--all-tagged',
|
||||
help=('use all hosts present in tags db'),
|
||||
action="store_true", dest="all_tagged_hosts", default=False)
|
||||
parser['config_args'].add_argument(
|
||||
'-a', '--all',
|
||||
help=('list hosts that have all specified tags, '
|
||||
'if -t/--tag is specified'),
|
||||
action="store_true", dest="has_all_tags", default=False)
|
||||
parser['config_args'].add_argument(
|
||||
'host', nargs='*', help='host(s) to operate on')
|
||||
parser['config_args'].add_argument(
|
||||
|
|
@ -183,17 +207,19 @@ def get_parsers():
|
|||
'-p', '--parallel',
|
||||
help='operate on multiple hosts in parallel',
|
||||
action='store_true', dest='parallel')
|
||||
parser['config_args'].add_argument(
|
||||
'-r', '--remote-out-dir',
|
||||
help='Directory to save cdist output in on the target host',
|
||||
dest="remote_out_path")
|
||||
parser['config_args'].add_argument(
|
||||
'-s', '--sequential',
|
||||
help='operate on multiple hosts sequentially (default)',
|
||||
action='store_false', dest='parallel')
|
||||
parser['config_args'].add_argument(
|
||||
'-t', '--tag',
|
||||
help=('host is specified by tag, not hostname/address; '
|
||||
'list all hosts that contain any of specified tags'),
|
||||
dest='tag', required=False, action="store_true", default=False)
|
||||
parser['config'] = parser['sub'].add_parser(
|
||||
'config', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['config_main'],
|
||||
parser['inventory_common'],
|
||||
parser['config_args']])
|
||||
parser['config'].set_defaults(func=cdist.config.Config.commandline)
|
||||
|
||||
|
|
@ -202,6 +228,134 @@ def get_parsers():
|
|||
parents=[parser['config']])
|
||||
parser['install'].set_defaults(func=cdist.install.Install.commandline)
|
||||
|
||||
# Inventory
|
||||
parser['inventory'] = parser['sub'].add_parser(
|
||||
'inventory', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['inventory_common']])
|
||||
parser['invsub'] = parser['inventory'].add_subparsers(
|
||||
title="Inventory commands", dest="subcommand")
|
||||
|
||||
parser['add-host'] = parser['invsub'].add_parser(
|
||||
'add-host', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['inventory_common']])
|
||||
parser['add-host'].add_argument(
|
||||
'host', nargs='*', help='host(s) to add')
|
||||
parser['add-host'].add_argument(
|
||||
'-f', '--file',
|
||||
help=('Read additional hosts to add from specified file '
|
||||
'or from stdin if \'-\' (each host on separate line). '
|
||||
'If no host or host file is specified then, by default, '
|
||||
'read from stdin.'),
|
||||
dest='hostfile', required=False)
|
||||
|
||||
parser['add-tag'] = parser['invsub'].add_parser(
|
||||
'add-tag', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['inventory_common']])
|
||||
parser['add-tag'].add_argument(
|
||||
'host', nargs='*',
|
||||
help='list of host(s) for which tags are added')
|
||||
parser['add-tag'].add_argument(
|
||||
'-f', '--file',
|
||||
help=('Read additional hosts to add tags from specified file '
|
||||
'or from stdin if \'-\' (each host on separate line). '
|
||||
'If no host or host file is specified then, by default, '
|
||||
'read from stdin. If no tags/tagfile nor hosts/hostfile'
|
||||
' are specified then tags are read from stdin and are'
|
||||
' added to all hosts.'),
|
||||
dest='hostfile', required=False)
|
||||
parser['add-tag'].add_argument(
|
||||
'-T', '--tag-file',
|
||||
help=('Read additional tags to add from specified file '
|
||||
'or from stdin if \'-\' (each tag on separate line). '
|
||||
'If no tag or tag file is specified then, by default, '
|
||||
'read from stdin. If no tags/tagfile nor hosts/hostfile'
|
||||
' are specified then tags are read from stdin and are'
|
||||
' added to all hosts.'),
|
||||
dest='tagfile', required=False)
|
||||
parser['add-tag'].add_argument(
|
||||
'-t', '--taglist',
|
||||
help=("Tag list to be added for specified host(s), comma separated"
|
||||
" values"),
|
||||
dest="taglist", required=False)
|
||||
|
||||
parser['del-host'] = parser['invsub'].add_parser(
|
||||
'del-host', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['inventory_common']])
|
||||
parser['del-host'].add_argument(
|
||||
'host', nargs='*', help='host(s) to delete')
|
||||
parser['del-host'].add_argument(
|
||||
'-a', '--all', help=('Delete all hosts'),
|
||||
dest='all', required=False, action="store_true", default=False)
|
||||
parser['del-host'].add_argument(
|
||||
'-f', '--file',
|
||||
help=('Read additional hosts to delete from specified file '
|
||||
'or from stdin if \'-\' (each host on separate line). '
|
||||
'If no host or host file is specified then, by default, '
|
||||
'read from stdin.'),
|
||||
dest='hostfile', required=False)
|
||||
|
||||
parser['del-tag'] = parser['invsub'].add_parser(
|
||||
'del-tag', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['inventory_common']])
|
||||
parser['del-tag'].add_argument(
|
||||
'host', nargs='*',
|
||||
help='list of host(s) for which tags are deleted')
|
||||
parser['del-tag'].add_argument(
|
||||
'-a', '--all',
|
||||
help=('Delete all tags for specified host(s)'),
|
||||
dest='all', required=False, action="store_true", default=False)
|
||||
parser['del-tag'].add_argument(
|
||||
'-f', '--file',
|
||||
help=('Read additional hosts to delete tags for from specified '
|
||||
'file or from stdin if \'-\' (each host on separate line). '
|
||||
'If no host or host file is specified then, by default, '
|
||||
'read from stdin. If no tags/tagfile nor hosts/hostfile'
|
||||
' are specified then tags are read from stdin and are'
|
||||
' deleted from all hosts.'),
|
||||
dest='hostfile', required=False)
|
||||
parser['del-tag'].add_argument(
|
||||
'-T', '--tag-file',
|
||||
help=('Read additional tags from specified file '
|
||||
'or from stdin if \'-\' (each tag on separate line). '
|
||||
'If no tag or tag file is specified then, by default, '
|
||||
'read from stdin. If no tags/tagfile nor'
|
||||
' hosts/hostfile are specified then tags are read from'
|
||||
' stdin and are added to all hosts.'),
|
||||
dest='tagfile', required=False)
|
||||
parser['del-tag'].add_argument(
|
||||
'-t', '--taglist',
|
||||
help=("Tag list to be deleted for specified host(s), "
|
||||
"comma separated values"),
|
||||
dest="taglist", required=False)
|
||||
|
||||
parser['list'] = parser['invsub'].add_parser(
|
||||
'list', parents=[parser['loglevel'], parser['beta'],
|
||||
parser['inventory_common']])
|
||||
parser['list'].add_argument(
|
||||
'host', nargs='*', help='host(s) to list')
|
||||
parser['list'].add_argument(
|
||||
'-a', '--all',
|
||||
help=('list hosts that have all specified tags, '
|
||||
'if -t/--tag is specified'),
|
||||
action="store_true", dest="has_all_tags", default=False)
|
||||
parser['list'].add_argument(
|
||||
'-f', '--file',
|
||||
help=('Read additional hosts to list from specified file '
|
||||
'or from stdin if \'-\' (each host on separate line). '
|
||||
'If no host or host file is specified then, by default, '
|
||||
'list all.'), dest='hostfile', required=False)
|
||||
parser['list'].add_argument(
|
||||
'-H', '--host-only', help=('Suppress tags listing'),
|
||||
action="store_true", dest="list_only_host", default=False)
|
||||
parser['list'].add_argument(
|
||||
'-t', '--tag',
|
||||
help=('host is specified by tag, not hostname/address; '
|
||||
'list all hosts that contain any of specified tags'),
|
||||
action="store_true", default=False)
|
||||
|
||||
parser['inventory'].set_defaults(
|
||||
func=cdist.inventory.Inventory.commandline)
|
||||
|
||||
# Shell
|
||||
parser['shell'] = parser['sub'].add_parser(
|
||||
'shell', parents=[parser['loglevel']])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue