This also removes unneeded backend code
---
 lib/backend.py      |   94 ++++++++++++--------------------------------------
 lib/rpc.py          |   35 ++++++++++++++++---
 lib/server/noded.py |   14 -------
 3 files changed, 53 insertions(+), 90 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index b3f5bbe..5511381 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -441,13 +441,34 @@ def GetNodeSnapshot(req_items):
   for req_type, names in req_items.items():
     if req_type == constants.CACHE_REQ_HV:
       hv_dict = ret_dict[constants.CACHE_REQ_HV] = {}
+      all_inst_info = {}
       for name in names:
         data_dict = hv_dict[name] = {}
-        hyp_info = hypervisor.GetHypervisor(name).GetNodeInfo()
+        hyper = hypervisor.GetHypervisor(name)
+        hyp_info = hyper.GetNodeInfo()
         if hyp_info is not None:
           data_dict[constants.CACHE_REQ_HV_NODE_DATA] = hyp_info
 
-        data_dict[constants.CACHE_REQ_HV_INST_DATA] = GetAllInstancesInfo(name)
+        instances_info = {}
+        inst_info = hyper.GetAllInstancesInfo()
+        if inst_info:
+          for name, _, memory, vcpus, state, times in inst_info:
+            data = {
+              "memory": memory,
+              "vcpus": vcpus,
+              "state": state,
+              "time": times,
+              }
+            if name in all_inst_info:
+              # we only check static parameters, like memory and vcpus,
+              # and not state and time which can change between the
+              # invocations of the different hypervisors
+              for key in "memory", "vcpus":
+                if data[key] != all_inst_info[name][key]:
+                  _Fail("Instance %s is running twice"
+                        " with different parameters", name)
+            instances_info[name] = all_inst_info[name] = data
+        data_dict[constants.CACHE_REQ_HV_INST_DATA] = instances_info
     elif req_type == constants.CACHE_REQ_DISKINFO:
       diskinfo_dict = ret_dict[constants.CACHE_REQ_DISKINFO] = {}
       vginfo = bdev.LogicalVolume.GetVGInfo(names)
@@ -833,32 +854,6 @@ def GetInstanceList(hypervisor_list):
   return results
 
 
-def GetInstanceInfo(instance, hname):
-  """Gives back the information about an instance as a dictionary.
-
-  @type instance: string
-  @param instance: the instance name
-  @type hname: string
-  @param hname: the hypervisor type of the instance
-
-  @rtype: dict
-  @return: dictionary with the following keys:
-      - memory: memory size of instance (int)
-      - state: xen state of instance (string)
-      - time: cpu time of instance (float)
-
-  """
-  output = {}
-
-  iinfo = hypervisor.GetHypervisor(hname).GetInstanceInfo(instance)
-  if iinfo is not None:
-    output["memory"] = iinfo[2]
-    output["state"] = iinfo[4]
-    output["time"] = iinfo[5]
-
-  return output
-
-
 def GetInstanceMigratable(instance):
   """Gives whether an instance can be migrated.
 
@@ -883,49 +878,6 @@ def GetInstanceMigratable(instance):
                       iname, link_name, idx)
 
 
-def GetAllInstancesInfo(hypervisor_list):
-  """Gather data about all instances.
-
-  This is the equivalent of L{GetInstanceInfo}, except that it
-  computes data for all instances at once, thus being faster if one
-  needs data about more than one instance.
-
-  @type hypervisor_list: list
-  @param hypervisor_list: list of hypervisors to query for instance data
-
-  @rtype: dict
-  @return: dictionary of instance: data, with data having the following keys:
-      - memory: memory size of instance (int)
-      - state: xen state of instance (string)
-      - time: cpu time of instance (float)
-      - vcpus: the number of vcpus
-
-  """
-  output = {}
-
-  for hname in hypervisor_list:
-    iinfo = hypervisor.GetHypervisor(hname).GetAllInstancesInfo()
-    if iinfo:
-      for name, _, memory, vcpus, state, times in iinfo:
-        value = {
-          "memory": memory,
-          "vcpus": vcpus,
-          "state": state,
-          "time": times,
-          }
-        if name in output:
-          # we only check static parameters, like memory and vcpus,
-          # and not state and time which can change between the
-          # invocations of the different hypervisors
-          for key in "memory", "vcpus":
-            if value[key] != output[name][key]:
-              _Fail("Instance %s is running twice"
-                    " with different parameters", name)
-        output[name] = value
-
-  return output
-
-
 def _InstanceLogName(kind, os_name, instance, component):
   """Compute the OS log filename for a given instance and operation.
 
diff --git a/lib/rpc.py b/lib/rpc.py
index 44c559d..0e204da 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -859,7 +859,7 @@ class RpcRunner(object):
 
 
   @_RpcTimeout(_TMO_URGENT)
-  def call_instance_info(self, node, instance, hname):
+  def call_instance_info(self, node, instance, hname, use_cache=True):
     """Returns information about a single instance.
 
     This is a single-node call.
@@ -872,7 +872,19 @@ class RpcRunner(object):
     @param hname: the hypervisor type of the instance
 
     """
-    return self._SingleNodeCall(node, "instance_info", [instance, hname])
+    req_items = {
+      constants.CACHE_REQ_HV: [hname]
+      }
+    result = self.call_node_snapshot([node], req_items,
+                                     use_cache=use_cache)[node]
+
+    if not result.fail_msg:
+      payload = result.payload
+      hv_data = payload[constants.CACHE_REQ_HV][hname]
+      hv_inst_data = hv_data[constants.CACHE_REQ_HV_INST_DATA]
+      result.payload = hv_inst_data[instance]
+
+    return result
 
   @_RpcTimeout(_TMO_NORMAL)
   def call_instance_migratable(self, node, instance):
@@ -890,7 +902,7 @@ class RpcRunner(object):
                                 [self._InstDict(instance)])
 
   @_RpcTimeout(_TMO_URGENT)
-  def call_all_instances_info(self, node_list, hypervisor_list):
+  def call_all_instances_info(self, node_list, hypervisor_list, 
use_cache=True):
     """Returns information about all instances on the given nodes.
 
     This is a multi-node call.
@@ -901,8 +913,21 @@ class RpcRunner(object):
     @param hypervisor_list: the hypervisors to query for instances
 
     """
-    return self._MultiNodeCall(node_list, "all_instances_info",
-                               [hypervisor_list])
+    req_items = {
+      constants.CACHE_REQ_HV: hypervisor_list
+      }
+    results = self.call_node_snapshot(node_list, req_items, 
use_cache=use_cache)
+
+    for result in results.values():
+      if not result.fail_msg:
+        payload = result.payload
+        inst_data = {}
+        for hname in hypervisor_list:
+          hv_data = payload[constants.CACHE_REQ_HV][hname]
+          inst_data.update(hv_data[constants.CACHE_REQ_HV_INST_DATA])
+        result.payload = inst_data
+
+    return results
 
   @_RpcTimeout(_TMO_URGENT)
   def call_instance_list(self, node_list, hypervisor_list):
diff --git a/lib/server/noded.py b/lib/server/noded.py
index 9b44fdd..060dafa 100644
--- a/lib/server/noded.py
+++ b/lib/server/noded.py
@@ -607,13 +607,6 @@ class NodeHttpServer(http.server.HttpServer):
     return backend.InstanceReboot(instance, reboot_type, shutdown_timeout)
 
   @staticmethod
-  def perspective_instance_info(params):
-    """Query instance information.
-
-    """
-    return backend.GetInstanceInfo(params[0], params[1])
-
-  @staticmethod
   def perspective_instance_migratable(params):
     """Query whether the specified instance can be migrated.
 
@@ -622,13 +615,6 @@ class NodeHttpServer(http.server.HttpServer):
     return backend.GetInstanceMigratable(instance)
 
   @staticmethod
-  def perspective_all_instances_info(params):
-    """Query information about all instances.
-
-    """
-    return backend.GetAllInstancesInfo(params[0])
-
-  @staticmethod
   def perspective_instance_list(params):
     """Query the list of running instances.
 
-- 
1.7.3.1

Reply via email to