forked from ungleich-public/cdist
parent
2885c6a248
commit
89b6215115
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue