Remove the logger.py module
[ganeti-local] / lib / rpc.py
index 1b1b9d1..168f0af 100644 (file)
 import os
 import socket
 import httplib
+import logging
 
 import simplejson
 
-from ganeti import logger
 from ganeti import utils
 from ganeti import objects
 
@@ -63,7 +63,7 @@ class NodeController:
       hc.endheaders()
       hc.send(parent.body)
     except socket.error, err:
-      logger.Error("Error connecting to %s: %s" % (node, str(err)))
+      logging.exception("Error connecting to node %s", node)
       self.failed = True
 
   def get_response(self):
@@ -81,7 +81,7 @@ class NodeController:
     except ValueError:
       return False
     if not length:
-      logger.Error("Zero-length reply from %s" % self.node)
+      logging.error("Zero-length reply from node %s", self.node)
       return False
     payload = resp.read(length)
     unload = simplejson.loads(payload)
@@ -158,6 +158,25 @@ class RpcRunner(object):
     """
     self._cfg = cfg
 
+  def _InstDict(self, instance):
+    """Convert the given instance to a dict.
+
+    This is done via the instance's ToDict() method and additionally
+    we fill the hvparams with the cluster defaults.
+
+    @type instance: L{objects.Instance}
+    @param instance: an Instance object
+    @rtype: dict
+    @return: the instance dict, with the hvparams filled with the
+        cluster defaults
+
+    """
+    idict = instance.ToDict()
+    cluster = self._cfg.GetClusterInfo()
+    idict["hvparams"] = cluster.FillHV(instance)
+    idict["beparams"] = cluster.FillBE(instance)
+    return idict
+
   def call_volume_list(self, node_list, vg_name):
     """Gets the logical volumes present in a given volume group.
 
@@ -201,7 +220,7 @@ class RpcRunner(object):
     This is a single-node call.
 
     """
-    c = Client("instance_start", [instance.ToDict(), extra_args])
+    c = Client("instance_start", [self._InstDict(instance), extra_args])
     c.connect(node)
     c.run()
     return c.getresult().get(node, False)
@@ -212,7 +231,7 @@ class RpcRunner(object):
     This is a single-node call.
 
     """
-    c = Client("instance_shutdown", [instance.ToDict()])
+    c = Client("instance_shutdown", [self._InstDict(instance)])
     c.connect(node)
     c.run()
     return c.getresult().get(node, False)
@@ -233,7 +252,7 @@ class RpcRunner(object):
         interpretation of this parameter is left to the hypervisor)
 
     """
-    c = Client("instance_migrate", [instance.ToDict(), target, live])
+    c = Client("instance_migrate", [self._InstDict(instance), target, live])
     c.connect(node)
     c.run()
     return c.getresult().get(node, False)
@@ -244,30 +263,31 @@ class RpcRunner(object):
     This is a single-node call.
 
     """
-    c = Client("instance_reboot", [instance.ToDict(), reboot_type, extra_args])
+    c = Client("instance_reboot", [self._InstDict(instance),
+                                   reboot_type, extra_args])
     c.connect(node)
     c.run()
     return c.getresult().get(node, False)
 
-  def call_instance_os_add(self, node, inst, osdev, swapdev):
+  def call_instance_os_add(self, node, inst):
     """Installs an OS on the given instance.
 
     This is a single-node call.
 
     """
-    params = [inst.ToDict(), osdev, swapdev]
+    params = [self._InstDict(inst)]
     c = Client("instance_os_add", params)
     c.connect(node)
     c.run()
     return c.getresult().get(node, False)
 
-  def call_instance_run_rename(self, node, inst, old_name, osdev, swapdev):
+  def call_instance_run_rename(self, node, inst, old_name):
     """Run the OS rename script for an instance.
 
     This is a single-node call.
 
     """
-    params = [inst.ToDict(), old_name, osdev, swapdev]
+    params = [self._InstDict(inst), old_name]
     c = Client("instance_run_rename", params)
     c.connect(node)
     c.run()
@@ -373,7 +393,7 @@ class RpcRunner(object):
     for node_name in retux:
       ret = retux.get(node_name, False)
       if type(ret) != dict:
-        logger.Error("could not connect to node %s" % (node_name))
+        logging.error("could not connect to node %s", node_name)
         ret = {}
 
       utils.CheckDict(ret,
@@ -694,7 +714,8 @@ class RpcRunner(object):
     This is a single-node call.
 
     """
-    params = [snap_bdev.ToDict(), dest_node, instance.ToDict(), cluster_name]
+    params = [snap_bdev.ToDict(), dest_node,
+              self._InstDict(instance), cluster_name]
     c = Client("snapshot_export", params)
     c.connect(node)
     c.run()
@@ -711,7 +732,7 @@ class RpcRunner(object):
     flat_disks = []
     for disk in snap_disks:
       flat_disks.append(disk.ToDict())
-    params = [instance.ToDict(), flat_disks]
+    params = [self._InstDict(instance), flat_disks]
     c = Client("finalize_export", params)
     c.connect(node)
     c.run()
@@ -738,7 +759,8 @@ class RpcRunner(object):
     This is a single-node call.
 
     """
-    params = [inst.ToDict(), osdev, swapdev, src_node, src_image, cluster_name]
+    params = [self._InstDict(inst), osdev, swapdev,
+              src_node, src_image, cluster_name]
     c = Client("instance_os_import", params)
     c.connect(node)
     c.run()
@@ -878,6 +900,25 @@ class RpcRunner(object):
     return result
 
 
+  @staticmethod
+  def call_jobqueue_set_drain(node_list, drain_flag):
+    """Set the drain flag on the queue.
+
+    This is a multi-node call.
+
+    @type node_list: list
+    @param node_list: the list of nodes to query
+    @type drain_flag: bool
+    @param drain_flag: if True, will set the drain flag, otherwise reset it.
+
+    """
+    c = Client("jobqueue_set_drain", [drain_flag])
+    c.connect_list(node_list)
+    c.run()
+    result = c.getresult()
+    return result
+
+
   def call_hypervisor_validate_params(self, node_list, hvname, hvparams):
     """Validate the hypervisor params.