_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.
("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),
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.