On Wed, Jun 23, 2010 at 11:58:20AM +0200, Iustin Pop wrote:
> On Tue, Jun 22, 2010 at 06:30:06PM +0200, Iustin Pop wrote:
> > On Tue, Jun 22, 2010 at 04:10:28PM +0200, Guido Trotter wrote:
> > > On Wed, Jun 16, 2010 at 5:21 AM, Iustin Pop <[email protected]> wrote:
> > > > + for key in sorted(instance["os_actual"]):
> > > > + if key in instance["os_instance"]:
> > > > + val = instance["os_instance"][key]
> > > > + else:
> > > > + val = "default (%s)" % instance["os_actual"][key]
> > > > + buf.write(" - %s: %s\n" % (key, val))
> > >
> > > This code is quite a lot similar (almost the same) to the one for
> > > printing hv params.
> > > How about we collapse it (and perhaps we could use the same for
> > > beparams too, we'd lose capitalization, but keep the output the same
> > > as the input, and avoid changes if we ever add a be param).
> >
> > Yeah, I was thinking something like that. Let me see what I can do.
>
> OK, +the list this time :)
>
> Interdiff:
Wrong interdiff, buf was missing. Another try:
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 3b6768c..fc2f4dc 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -1111,6 +1111,21 @@ 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.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.
@@ -1159,12 +1174,7 @@ 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"])
- for key in sorted(instance["os_actual"]):
- if key in instance["os_instance"]:
- val = instance["os_instance"][key]
- else:
- val = "default (%s)" % instance["os_actual"][key]
- buf.write(" - %s: %s\n" % (key, val))
+ _FormatParameterDict(buf, instance["os_instance"], instance["os_actual"])
if instance.has_key("network_port"):
buf.write(" Allocated network port: %s\n" %
compat.TryToRoman(instance["network_port"],
@@ -1191,12 +1201,7 @@ def ShowInstanceConfig(opts, args):
vnc_bind_address)
buf.write(" - console connection: vnc to %s\n" % vnc_console_port)
- for key in sorted(instance["hv_actual"]):
- if key in instance["hv_instance"]:
- val = instance["hv_instance"][key]
- else:
- val = "default (%s)" % instance["hv_actual"][key]
- buf.write(" - %s: %s\n" % (key, val))
+ _FormatParameterDict(buf, instance["hv_instance"], instance["hv_actual"])
buf.write(" Hardware:\n")
buf.write(" - VCPUs: %s\n" %
compat.TryToRoman(instance["be_actual"][constants.BE_VCPUS],
--
iustin