From 4ea3de4e17b05e564e193559821fb7d7c69642bb Mon Sep 17 00:00:00 2001
From: Balazs Lecz <leczb@google.com>
Date: Wed, 7 Jul 2010 18:02:26 +0000
Subject: [PATCH] Add oper_vcpus instance status field

This introduces a new instance status field, named "oper_vcpus".
It contains the actual number of VCPUs an instance is using as
seen by the hypervisor.

Signed-off-by: Balazs Lecz <leczb@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/cmdlib.py         | 12 +++++++++++-
 lib/rapi/rlib2.py     |  2 +-
 man/gnt-instance.sgml | 10 +++++++++-
 qa/qa_rapi.py         |  2 +-
 scripts/gnt-instance  |  9 +++++++--
 5 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 7cd510007..1c64ed234 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -5063,7 +5063,10 @@ class LUQueryInstances(NoHooksLU):
                                    if name not in constants.HVC_GLOBALS] +
                                   ["be/%s" % name
                                    for name in constants.BES_PARAMETERS])
-  _FIELDS_DYNAMIC = utils.FieldSet("oper_state", "oper_ram", "status")
+  _FIELDS_DYNAMIC = utils.FieldSet("oper_state",
+                                   "oper_ram",
+                                   "oper_vcpus",
+                                   "status")
 
 
   def CheckArguments(self):
@@ -5194,6 +5197,13 @@ class LUQueryInstances(NoHooksLU):
             val = live_data[instance.name].get("memory", "?")
           else:
             val = "-"
+        elif field == "oper_vcpus":
+          if instance.primary_node in bad_nodes:
+            val = None
+          elif instance.name in live_data:
+            val = live_data[instance.name].get("vcpus", "?")
+          else:
+            val = "-"
         elif field == "vcpus":
           val = i_be[constants.BE_VCPUS]
         elif field == "disk_template":
diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index 628ca4ec1..19da11500 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -58,7 +58,7 @@ I_FIELDS = ["name", "admin_state", "os",
             "network_port",
             "disk.sizes", "disk_usage",
             "beparams", "hvparams",
-            "oper_state", "oper_ram", "status",
+            "oper_state", "oper_ram", "oper_vcpus", "status",
             ] + _COMMON_FIELDS
 
 N_FIELDS = ["name", "offline", "master_candidate", "drained",
diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml
index 4ebd582fb..dd68fd15c 100644
--- a/man/gnt-instance.sgml
+++ b/man/gnt-instance.sgml
@@ -1149,6 +1149,13 @@ instance5: 11225
                   by the hypervisor</simpara>
               </listitem>
             </varlistentry>
+            <varlistentry>
+              <term>oper_vcpus</term>
+              <listitem>
+                <simpara>the actual number of VCPUs the instance is using
+                  as seen by the hypervisor</simpara>
+              </listitem>
+            </varlistentry>
             <varlistentry>
               <term>ip</term>
               <listitem>
@@ -1400,7 +1407,8 @@ instance5: 11225
         <para>
           There is a subtle grouping about the available output
           fields: all fields except for <option>oper_state</option>,
-          <option>oper_ram</option> and <option>status</option> are
+          <option>oper_ram</option>, <option>oper_vcpus</option> and
+          <option>status</option> are
           configuration value and not run-time values. So if you don't
           select any of the these fields, the query will be satisfied
           instantly from the cluster configuration, without having to
diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py
index 09dd74a3a..a8a54f738 100644
--- a/qa/qa_rapi.py
+++ b/qa/qa_rapi.py
@@ -88,7 +88,7 @@ INSTANCE_FIELDS = ("name", "os", "pnode", "snodes",
                    "disk_template", "disk.sizes",
                    "nic.ips", "nic.macs", "nic.modes", "nic.links",
                    "beparams", "hvparams",
-                   "oper_state", "oper_ram", "status", "tags")
+                   "oper_state", "oper_ram", "oper_vcpus", "status", "tags")
 
 NODE_FIELDS = ("name", "dtotal", "dfree",
                "mtotal", "mnode", "mfree",
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 475514e9b..53491de53 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -258,6 +258,7 @@ def ListInstances(opts, args):
       "snodes": "Secondary_Nodes", "admin_state": "Autostart",
       "oper_state": "Running",
       "oper_ram": "Memory", "disk_template": "Disk_template",
+      "oper_vcpus": "VCPUs",
       "ip": "IP_address", "mac": "MAC_address",
       "nic_mode": "NIC_Mode", "nic_link": "NIC_Link",
       "bridge": "Bridge",
@@ -316,6 +317,9 @@ def ListInstances(opts, args):
       elif field == "oper_ram":
         if val is None:
           val = "(node down)"
+      elif field == "oper_vcpus":
+        if val is None:
+          val = "(node down)"
       elif field == "sda_size" or field == "sdb_size":
         if val is None:
           val = "N/A"
@@ -1423,8 +1427,9 @@ commands = {
     "[<instance>...]",
     "Lists the instances and their status. The available fields are"
     " (see the man page for details): status, oper_state, oper_ram,"
-    " name, os, pnode, snodes, admin_state, admin_ram, disk_template,"
-    " ip, mac, nic_mode, nic_link, sda_size, sdb_size, vcpus, serial_no,"
+    " oper_vcpus, name, os, pnode, snodes, admin_state, admin_ram,"
+    " disk_template, ip, mac, nic_mode, nic_link, sda_size, sdb_size,"
+    " vcpus, serial_no,"
     " nic.count, nic.mac/N, nic.ip/N, nic.mode/N, nic.link/N,"
     " nic.macs, nic.ips, nic.modes, nic.links,"
     " disk.count, disk.size/N, disk.sizes,"
-- 
GitLab