Add instance_balloon_memory rpc
authorGuido Trotter <ultrotter@google.com>
Fri, 9 Dec 2011 15:22:27 +0000 (15:22 +0000)
committerGuido Trotter <ultrotter@google.com>
Tue, 17 Jan 2012 13:01:55 +0000 (13:01 +0000)
Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

lib/backend.py
lib/rpc_defs.py
lib/server/noded.py

index 1af69a1..338a30d 100644 (file)
@@ -1376,6 +1376,27 @@ def InstanceReboot(instance, reboot_type, shutdown_timeout):
     _Fail("Invalid reboot_type received: %s", reboot_type)
 
 
+def InstanceBalloonMemory(instance, memory):
+  """Resize an instance's memory.
+
+  @type instance: L{objects.Instance}
+  @param instance: the instance object
+  @type memory: int
+  @param memory: new memory amount in MB
+  @rtype: None
+
+  """
+  hyper = hypervisor.GetHypervisor(instance.hypervisor)
+  running = hyper.ListInstances()
+  if instance.name not in running:
+    logging.info("Instance %s is not running, cannot balloon", instance.name)
+    return
+  try:
+    hyper.BalloonInstanceMemory(instance, memory)
+  except errors.HypervisorError, err:
+    _Fail("Failed to balloon instance memory: %s", err, exc=True)
+
+
 def MigrationInfo(instance):
   """Gather information about an instance to be migrated.
 
index 288acf2..44bdc4c 100644 (file)
@@ -224,6 +224,10 @@ _INSTANCE_CALLS = [
     ("instance", ED_INST_DICT, "Instance object"),
     ("timeout", None, None),
     ], None, None, "Stops an instance"),
+  ("instance_balloon_memory", SINGLE, None, TMO_NORMAL, [
+    ("instance", ED_INST_DICT, "Instance object"),
+    ("memory", None, None),
+    ], None, None, "Modify the amount of an instance's runtime memory"),
   ("instance_run_rename", SINGLE, None, TMO_SLOW, [
     ("instance", ED_INST_DICT, "Instance object"),
     ("old_name", None, None),
index 3495526..ba3cb90 100644 (file)
@@ -622,6 +622,15 @@ class NodeHttpServer(http.server.HttpServer):
     return backend.InstanceReboot(instance, reboot_type, shutdown_timeout)
 
   @staticmethod
+  def perspective_instance_balloon_memory(params):
+    """Modify instance runtime memory.
+
+    """
+    instance_dict, memory = params
+    instance = objects.Instance.FromDict(instance_dict)
+    return backend.InstanceBalloonMemory(instance, memory)
+
+  @staticmethod
   def perspective_instance_info(params):
     """Query instance information.