Commit 36e247e1 authored by Guido Trotter's avatar Guido Trotter
Browse files

Add nodegroup bash autocomplation



We autocomplete both by nodegroup name and uuid.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 6f076453
...@@ -117,6 +117,15 @@ def WritePreamble(sw): ...@@ -117,6 +117,15 @@ def WritePreamble(sw):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
sw.Write("_ganeti_nodegroup() {")
sw.IncIndent()
try:
nodegroups_path = os.path.join(constants.DATA_DIR, "ssconf_nodegroups")
sw.Write("cat %s 2>/dev/null || :", utils.ShellQuote(nodegroups_path))
finally:
sw.DecIndent()
sw.Write("}")
# Params: <offset> <options with values> <options without values> # Params: <offset> <options with values> <options without values>
# Result variable: $first_arg_idx # Result variable: $first_arg_idx
sw.Write("_ganeti_find_first_arg() {") sw.Write("_ganeti_find_first_arg() {")
...@@ -324,6 +333,8 @@ class CompletionWriter: ...@@ -324,6 +333,8 @@ class CompletionWriter:
WriteCompReply(sw, "-W \"$(_ganeti_os)\"", cur=cur) WriteCompReply(sw, "-W \"$(_ganeti_os)\"", cur=cur)
elif suggest == cli.OPT_COMPL_ONE_IALLOCATOR: elif suggest == cli.OPT_COMPL_ONE_IALLOCATOR:
WriteCompReply(sw, "-W \"$(_ganeti_iallocator)\"", cur=cur) WriteCompReply(sw, "-W \"$(_ganeti_iallocator)\"", cur=cur)
elif suggest == cli.OPT_COMPL_ONE_NODEGROUP:
WriteCompReply(sw, "-W \"$(_ganeti_nodegroup)\"", cur=cur)
elif suggest == cli.OPT_COMPL_INST_ADD_NODES: elif suggest == cli.OPT_COMPL_INST_ADD_NODES:
sw.Write("local tmp= node1= pfx= curvalue=\"${optcur#*:}\"") sw.Write("local tmp= node1= pfx= curvalue=\"${optcur#*:}\"")
......
...@@ -194,6 +194,7 @@ __all__ = [ ...@@ -194,6 +194,7 @@ __all__ = [
"OPT_COMPL_ONE_IALLOCATOR", "OPT_COMPL_ONE_IALLOCATOR",
"OPT_COMPL_ONE_INSTANCE", "OPT_COMPL_ONE_INSTANCE",
"OPT_COMPL_ONE_NODE", "OPT_COMPL_ONE_NODE",
"OPT_COMPL_ONE_NODEGROUP",
"OPT_COMPL_ONE_OS", "OPT_COMPL_ONE_OS",
"cli_option", "cli_option",
"SplitNodeOption", "SplitNodeOption",
...@@ -515,7 +516,8 @@ def check_bool(option, opt, value): # pylint: disable-msg=W0613 ...@@ -515,7 +516,8 @@ def check_bool(option, opt, value): # pylint: disable-msg=W0613
OPT_COMPL_ONE_INSTANCE, OPT_COMPL_ONE_INSTANCE,
OPT_COMPL_ONE_OS, OPT_COMPL_ONE_OS,
OPT_COMPL_ONE_IALLOCATOR, OPT_COMPL_ONE_IALLOCATOR,
OPT_COMPL_INST_ADD_NODES) = range(100, 106) OPT_COMPL_INST_ADD_NODES,
OPT_COMPL_ONE_NODEGROUP) = range(100, 107)
OPT_COMPL_ALL = frozenset([ OPT_COMPL_ALL = frozenset([
OPT_COMPL_MANY_NODES, OPT_COMPL_MANY_NODES,
...@@ -524,6 +526,7 @@ OPT_COMPL_ALL = frozenset([ ...@@ -524,6 +526,7 @@ OPT_COMPL_ALL = frozenset([
OPT_COMPL_ONE_OS, OPT_COMPL_ONE_OS,
OPT_COMPL_ONE_IALLOCATOR, OPT_COMPL_ONE_IALLOCATOR,
OPT_COMPL_INST_ADD_NODES, OPT_COMPL_INST_ADD_NODES,
OPT_COMPL_ONE_NODEGROUP,
]) ])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment