Show OS variant information in gnt-os info
authorDimitris Bliablias <bl.dimitris@gmail.com>
Thu, 20 Mar 2014 20:27:37 +0000 (22:27 +0200)
committerMichele Tartara <mtartara@google.com>
Fri, 21 Mar 2014 10:22:27 +0000 (10:22 +0000)
Currently, the non-standard/modified per-OS hypervisor parameters, or
OS specific parameters can be listed only by the 'gnt-cluster info'
command, which is a non-standard place to show them. Extend the
'gnt-os info' command to display the available/supported OS variants
in the cluster.

This fixes issue 266.

Signed-off-by: Dimitris Bliablias <bl.dimitris@gmail.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>

lib/client/gnt_os.py
lib/cmdlib/operating_system.py
lib/query.py

index ae7b9eb..e6fe970 100644 (file)
@@ -75,7 +75,8 @@ def ShowOSInfo(opts, args):
   """
   op = opcodes.OpOsDiagnose(output_fields=["name", "valid", "variants",
                                            "parameters", "api_versions",
-                                           "blacklisted", "hidden"],
+                                           "blacklisted", "hidden", "os_hvp",
+                                           "osparams"],
                             names=[])
   result = SubmitOpCode(op, opts=opts)
 
@@ -85,7 +86,13 @@ def ShowOSInfo(opts, args):
 
   do_filter = bool(args)
 
-  for (name, valid, variants, parameters, api_versions, blk, hid) in result:
+  total_os_hvp = {}
+  total_osparams = {}
+
+  for (name, valid, variants, parameters, api_versions, blk, hid, os_hvp,
+       osparams) in result:
+    total_os_hvp.update(os_hvp)
+    total_osparams.update(osparams)
     if do_filter:
       if name not in args:
         continue
@@ -108,8 +115,18 @@ def ShowOSInfo(opts, args):
     ToStdout("")
 
   if args:
+    all_names = total_os_hvp.keys() + total_osparams.keys()
     for name in args:
-      ToStdout("%s: ", name)
+      if not name in all_names:
+        ToStdout("%s: ", name)
+      else:
+        info = [
+          (name, [
+            ("OS-specific hypervisor parameters", total_os_hvp.get(name, {})),
+            ("OS parameters", total_osparams.get(name, {})),
+            ]),
+          ]
+        PrintGenericInfo(info)
       ToStdout("")
 
   return 0
index 11d1398..9a857b8 100644 (file)
@@ -104,7 +104,8 @@ class OsQuery(QueryBase):
     for (os_name, os_data) in pol.items():
       info = query.OsInfo(name=os_name, valid=True, node_status=os_data,
                           hidden=(os_name in cluster.hidden_os),
-                          blacklisted=(os_name in cluster.blacklisted_os))
+                          blacklisted=(os_name in cluster.blacklisted_os),
+                          os_hvp={}, osparams={})
 
       variants = set()
       parameters = set()
@@ -131,6 +132,13 @@ class OsQuery(QueryBase):
       info.parameters = list(parameters)
       info.api_versions = list(api_versions)
 
+      for variant in variants:
+        name = "+".join([os_name, variant])
+        if name in cluster.os_hvp.keys():
+          info.os_hvp[name] = cluster.os_hvp.get(name)
+        if name in cluster.osparams.keys():
+          info.osparams[name] = cluster.osparams.get(name)
+
       data[os_name] = info
 
     # Prepare data in requested order
index 93b7c5e..7cdb719 100644 (file)
@@ -2446,6 +2446,8 @@ class OsInfo(objects.ConfigObject):
     "api_versions",
     "parameters",
     "node_status",
+    "os_hvp",
+    "osparams"
     ]
 
 
@@ -2478,6 +2480,12 @@ def _BuildOsFields():
     (_MakeField("node_status", "NodeStatus", QFT_OTHER,
                 "Status from node"),
      None, 0, _GetItemAttr("node_status")),
+    (_MakeField("os_hvp", "OsHypervisorParams", QFT_OTHER,
+                "Operating system specific hypervisor parameters"),
+     None, 0, _GetItemAttr("os_hvp")),
+    (_MakeField("osparams", "OsParameters", QFT_OTHER,
+                "Operating system specific parameters"),
+     None, 0, _GetItemAttr("osparams")),
     ]
 
   return _PrepareFieldList(fields, [])