Merge branch 'clarify-stdin-input' into 'master'
Clarify stdin input Closes #836 See merge request ungleich-public/cdist!934
This commit is contained in:
commit
2e6c12c27c
5 changed files with 29 additions and 64 deletions
|
@ -273,8 +273,7 @@ def get_parsers():
|
|||
'-f', '--file',
|
||||
help=('Read specified file for a list of additional hosts to '
|
||||
'operate on or if \'-\' is given, read stdin (one host per '
|
||||
'line). If no host or host file is specified then, by '
|
||||
'default, read hosts from stdin.'),
|
||||
'line).'),
|
||||
dest='hostfile', required=False)
|
||||
parser['config_args'].add_argument(
|
||||
'-p', '--parallel', nargs='?', metavar='HOST_MAX',
|
||||
|
@ -326,9 +325,7 @@ def get_parsers():
|
|||
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.'),
|
||||
'or from stdin if \'-\' (each host on separate line). '),
|
||||
dest='hostfile', required=False)
|
||||
|
||||
parser['add-tag'] = parser['invsub'].add_parser(
|
||||
|
@ -342,20 +339,12 @@ def get_parsers():
|
|||
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.'),
|
||||
'or from stdin if \'-\' (each host on separate line). '),
|
||||
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.'),
|
||||
'or from stdin if \'-\' (each tag on separate line). '),
|
||||
dest='tagfile', required=False)
|
||||
parser['add-tag'].add_argument(
|
||||
'-t', '--taglist',
|
||||
|
@ -376,9 +365,7 @@ def get_parsers():
|
|||
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.'),
|
||||
'or from stdin if \'-\' (each host on separate line). '),
|
||||
dest='hostfile', required=False)
|
||||
|
||||
parser['del-tag'] = parser['invsub'].add_parser(
|
||||
|
@ -396,20 +383,13 @@ def get_parsers():
|
|||
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.'),
|
||||
'file or from stdin if \'-\' (each host on separate '
|
||||
'line). '),
|
||||
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.'),
|
||||
'or from stdin if \'-\' (each tag on separate line). '),
|
||||
dest='tagfile', required=False)
|
||||
parser['del-tag'].add_argument(
|
||||
'-t', '--taglist',
|
||||
|
|
|
@ -175,9 +175,11 @@ class Config:
|
|||
raise cdist.Error(("Cannot read both, manifest and host file, "
|
||||
"from stdin"))
|
||||
|
||||
# if no host source is specified then read hosts from stdin
|
||||
if not (args.hostfile or args.host):
|
||||
args.hostfile = '-'
|
||||
if args.tag or args.all_tagged_hosts:
|
||||
raise cdist.Error(("Target host tag(s) missing"))
|
||||
else:
|
||||
raise cdist.Error(("Target host(s) missing"))
|
||||
|
||||
if args.manifest == '-':
|
||||
# read initial manifest from stdin
|
||||
|
|
|
@ -299,7 +299,7 @@ class InventoryHost(Inventory):
|
|||
self.all = all
|
||||
|
||||
if not self.hosts and not self.hostfile:
|
||||
self.hostfile = "-"
|
||||
raise cdist.Error("Host(s) missing")
|
||||
|
||||
def _new_hostpath(self, hostpath):
|
||||
# create empty file
|
||||
|
@ -355,7 +355,7 @@ class InventoryTag(Inventory):
|
|||
else:
|
||||
self.allhosts = False
|
||||
if not self.tags and not self.tagfile:
|
||||
self.tagfile = "-"
|
||||
raise cdist.Error("Tag(s) missing")
|
||||
|
||||
if self.hostfile == "-" and self.tagfile == "-":
|
||||
raise cdist.Error("Cannot read both, hosts and tags, from stdin")
|
||||
|
|
|
@ -307,11 +307,10 @@ class InventoryTestCase(test.CdistTestCase):
|
|||
raise e
|
||||
|
||||
# InventoryTag
|
||||
@unittest.expectedFailure
|
||||
def test_inventory_tag_init(self):
|
||||
invTag = inventory.InventoryTag(db_basedir=inventory_dir,
|
||||
action="add")
|
||||
self.assertTrue(invTag.allhosts)
|
||||
self.assertEqual(invTag.tagfile, "-")
|
||||
|
||||
def test_inventory_tag_stdin_multiple_hosts(self):
|
||||
try:
|
||||
|
|
|
@ -177,10 +177,8 @@ Install command is currently in beta.
|
|||
|
||||
**-f HOSTFILE, --file HOSTFILE**
|
||||
Read specified file for a list of additional hosts to operate on
|
||||
or if '-' is given, read stdin (one host per line).
|
||||
If no host or host file is specified then, by default,
|
||||
read hosts from stdin. For the file format see
|
||||
:strong:`HOSTFILE FORMAT` below.
|
||||
or if '-' is given, read stdin (one host per line). For the file
|
||||
format see :strong:`HOSTFILE FORMAT` below.
|
||||
|
||||
**-g CONFIG_FILE, --config-file CONFIG_FILE**
|
||||
Use specified custom configuration file.
|
||||
|
@ -299,9 +297,8 @@ Add host(s) to inventory database.
|
|||
|
||||
**-f HOSTFILE, --file HOSTFILE**
|
||||
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. Hostfile format is the same as config hostfile format.
|
||||
from stdin if '-' (each host on separate line).
|
||||
Hostfile format is the same as config hostfile format.
|
||||
|
||||
**-g CONFIG_FILE, --config-file CONFIG_FILE**
|
||||
Use specified custom configuration file.
|
||||
|
@ -327,11 +324,8 @@ Add tag(s) to inventory database.
|
|||
|
||||
**-f HOSTFILE, --file HOSTFILE**
|
||||
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. Hostfile format is the same as config hostfile format.
|
||||
or from stdin if '-' (each host on separate line).
|
||||
Hostfile format is the same as config hostfile format.
|
||||
|
||||
**-g CONFIG_FILE, --config-file CONFIG_FILE**
|
||||
Use specified custom configuration file.
|
||||
|
@ -346,11 +340,8 @@ Add tag(s) to inventory database.
|
|||
|
||||
**-T TAGFILE, --tag-file TAGFILE**
|
||||
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. Tagfile format is the same as config hostfile format.
|
||||
from stdin if '-' (each tag on separate line).
|
||||
Tagfile format is the same as config hostfile format.
|
||||
|
||||
**-t TAGLIST, --taglist TAGLIST**
|
||||
Tag list to be added for specified host(s), comma
|
||||
|
@ -372,9 +363,8 @@ Delete host(s) from inventory database.
|
|||
|
||||
**-f HOSTFILE, --file HOSTFILE**
|
||||
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. Hostfile format is the same as config hostfile format.
|
||||
from stdin if '-' (each host on separate line).
|
||||
Hostfile format is the same as config hostfile format.
|
||||
|
||||
**-g CONFIG_FILE, --config-file CONFIG_FILE**
|
||||
Use specified custom configuration file.
|
||||
|
@ -404,11 +394,8 @@ Delete tag(s) from inventory database.
|
|||
**-f HOSTFILE, --file HOSTFILE**
|
||||
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. Hostfile
|
||||
format is the same as config hostfile format.
|
||||
separate line). Hostfile format is the same as
|
||||
config hostfile format.
|
||||
|
||||
**-g CONFIG_FILE, --config-file CONFIG_FILE**
|
||||
Use specified custom configuration file.
|
||||
|
@ -423,11 +410,8 @@ Delete tag(s) from inventory database.
|
|||
|
||||
**-T TAGFILE, --tag-file TAGFILE**
|
||||
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. Tagfile format is the same as config hostfile format.
|
||||
if '-' (each tag on separate line).
|
||||
Tagfile format is the same as config hostfile format.
|
||||
|
||||
**-t TAGLIST, --taglist TAGLIST**
|
||||
Tag list to be deleted for specified host(s), comma
|
||||
|
|
Loading…
Reference in a new issue