Commit acd19189 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Move FormatParameterDict from gnt_instance.py to cli.py



This function is useful for other cli-tools who need to display
a dict based parameter field.
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarAdeodato Simo <dato@google.com>
parent 904b3bfe
......@@ -178,6 +178,7 @@ __all__ = [
"ToStderr", "ToStdout",
"FormatError",
"FormatQueryResult",
"FormatParameterDict",
"GenerateTable",
"AskUser",
"FormatTimestamp",
......@@ -2941,3 +2942,21 @@ class JobExecutor(object):
else:
ToStderr("Failure for %s: %s", name, result)
return [row[1:3] for row in self.jobs]
def FormatParameterDict(buf, param_dict, actual, level=1):
"""Formats a parameter dictionary.
@type buf: L{StringIO}
@param buf: the buffer into which to write
@type param_dict: dict
@param param_dict: the own parameters
@type actual: dict
@param actual: the current parameter set (including defaults)
@param level: Level of indent
"""
indent = " " * level
for key in sorted(actual):
val = param_dict.get(key, "default (%s)" % actual[key])
buf.write("%s- %s: %s\n" % (indent, key, val))
......@@ -1120,21 +1120,6 @@ def _FormatList(buf, data, indent_level):
_FormatList(buf, elem, indent_level+1)
def _FormatParameterDict(buf, per_inst, actual):
"""Formats a parameter dictionary.
@type buf: L{StringIO}
@param buf: the buffer into which to write
@type per_inst: dict
@param per_inst: the instance's own parameters
@type actual: dict
@param actual: the current parameter set (including defaults)
"""
for key in sorted(actual):
val = per_inst.get(key, "default (%s)" % actual[key])
buf.write(" - %s: %s\n" % (key, val))
def ShowInstanceConfig(opts, args):
"""Compute instance run-time status.
......@@ -1183,7 +1168,8 @@ def ShowInstanceConfig(opts, args):
buf.write(" - primary: %s\n" % instance["pnode"])
buf.write(" - secondaries: %s\n" % utils.CommaJoin(instance["snodes"]))
buf.write(" Operating system: %s\n" % instance["os"])
_FormatParameterDict(buf, instance["os_instance"], instance["os_actual"])
FormatParameterDict(buf, instance["os_instance"], instance["os_actual"],
level=2)
if instance.has_key("network_port"):
buf.write(" Allocated network port: %s\n" %
compat.TryToRoman(instance["network_port"],
......@@ -1210,7 +1196,8 @@ def ShowInstanceConfig(opts, args):
vnc_bind_address)
buf.write(" - console connection: vnc to %s\n" % vnc_console_port)
_FormatParameterDict(buf, instance["hv_instance"], instance["hv_actual"])
FormatParameterDict(buf, instance["hv_instance"], instance["hv_actual"],
level=2)
buf.write(" Hardware:\n")
buf.write(" - VCPUs: %s\n" %
compat.TryToRoman(instance["be_actual"][constants.BE_VCPUS],
......
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