Add cluster name to instance migration RPC
[ganeti-local] / lib / hypervisor / hv_base.py
index 1cc054a..381d298 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012, 2013 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -169,9 +169,6 @@ class BaseHypervisor(object):
   ANCILLARY_FILES_OPT = []
   CAN_MIGRATE = False
 
-  def __init__(self):
-    pass
-
   def StartInstance(self, instance, block_devices, startup_paused):
     """Start an instance."""
     raise NotImplementedError
@@ -209,32 +206,39 @@ class BaseHypervisor(object):
     """Reboot an instance."""
     raise NotImplementedError
 
-  def ListInstances(self):
+  def ListInstances(self, hvparams=None):
     """Get the list of running instances."""
     raise NotImplementedError
 
-  def GetInstanceInfo(self, instance_name):
+  def GetInstanceInfo(self, instance_name, hvparams=None):
     """Get instance properties.
 
     @type instance_name: string
     @param instance_name: the instance name
+    @type hvparams: dict of strings
+    @param hvparams: hvparams to be used with this instance
 
     @return: tuple (name, id, memory, vcpus, state, times)
 
     """
     raise NotImplementedError
 
-  def GetAllInstancesInfo(self):
+  def GetAllInstancesInfo(self, hvparams=None):
     """Get properties of all instances.
 
+    @type hvparams: dict of strings
+    @param hvparams: hypervisor parameter
     @return: list of tuples (name, id, memory, vcpus, stat, times)
 
     """
     raise NotImplementedError
 
-  def GetNodeInfo(self):
+  def GetNodeInfo(self, hvparams=None):
     """Return information about the node.
 
+    @type hvparams: dict of strings
+    @param hvparams: hypervisor parameters
+
     @return: a dict with the following keys (values in MiB):
           - memory_total: the total memory size on the node
           - memory_free: the available memory on the node for instances
@@ -266,9 +270,14 @@ class BaseHypervisor(object):
 
     return (cls.ANCILLARY_FILES, cls.ANCILLARY_FILES_OPT)
 
-  def Verify(self):
+  def Verify(self, hvparams=None):
     """Verify the hypervisor.
 
+    @type hvparams: dict of strings
+    @param hvparams: hypervisor parameters to be verified against
+
+    @return: Problem description if something is wrong, C{None} otherwise
+
     """
     raise NotImplementedError
 
@@ -327,9 +336,11 @@ class BaseHypervisor(object):
     """
     pass
 
-  def MigrateInstance(self, instance, target, live):
+  def MigrateInstance(self, cluster_name, instance, target, live):
     """Migrate an instance.
 
+    @type cluster_name: string
+    @param cluster_name: name of the cluster
     @type instance: L{objects.Instance}
     @param instance: the instance to be migrated
     @type target: string
@@ -366,7 +377,7 @@ class BaseHypervisor(object):
     """
     raise NotImplementedError
 
-  def _InstanceStartupMemory(self, instance):
+  def _InstanceStartupMemory(self, instance, hvparams=None):
     """Get the correct startup memory for an instance
 
     This function calculates how much memory an instance should be started
@@ -379,7 +390,7 @@ class BaseHypervisor(object):
     @return: memory the instance should be started with
 
     """
-    free_memory = self.GetNodeInfo()["memory_free"]
+    free_memory = self.GetNodeInfo(hvparams=hvparams)["memory_free"]
     max_start_mem = min(instance.beparams[constants.BE_MAXMEM], free_memory)
     start_mem = max(instance.beparams[constants.BE_MINMEM], max_start_mem)
     return start_mem
@@ -437,13 +448,16 @@ class BaseHypervisor(object):
                                      (name, errstr, value))
 
   @classmethod
-  def PowercycleNode(cls):
+  def PowercycleNode(cls, hvparams=None):
     """Hard powercycle a node using hypervisor specific methods.
 
     This method should hard powercycle the node, using whatever
     methods the hypervisor provides. Note that this means that all
     instances running on the node must be stopped too.
 
+    @type hvparams: dict of strings
+    @param hvparams: hypervisor params to be used on this node
+
     """
     raise NotImplementedError
 
@@ -521,3 +535,17 @@ class BaseHypervisor(object):
       result = utils.RunCmd(["reboot", "-n", "-f"])
       if not result:
         logging.error("Can't run shutdown: %s", result.output)
+
+  @staticmethod
+  def _FormatVerifyResults(msgs):
+    """Formats the verification results, given a list of errors.
+
+    @param msgs: list of errors, possibly empty
+    @return: overall problem description if something is wrong,
+        C{None} otherwise
+
+    """
+    if msgs:
+      return "; ".join(msgs)
+    else:
+      return None