+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)
+
+