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