From 2c7a03734c95156a1b0f10b40c5ba04a9a2b32dd Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 28 Nov 2011 17:20:02 +0000
Subject: [PATCH] Implement memory ballooning in xen
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 lib/hypervisor/hv_xen.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 506de0aad..44a761c61 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -302,6 +302,29 @@ class XenHypervisor(hv_base.BaseHypervisor):
                                    " did not reboot in the expected interval" %
                                    (instance.name, ))
 
+  def BalloonInstanceMemory(self, instance, mem):
+    """Balloon an instance memory to a certain value.
+
+    @type instance: L{objects.Instance}
+    @param instance: instance to be accepted
+    @type mem: int
+    @param mem: actual memory size to use for instance runtime
+
+    """
+    cmd = [constants.XEN_CMD, "mem-set", instance.name, mem]
+    result = utils.RunCmd(cmd)
+    if result.failed:
+      raise errors.HypervisorError("Failed to balloon instance %s: %s (%s)" %
+                                   (instance.name, result.fail_reason,
+                                    result.output))
+    cmd = ["sed", "-ie", "s/^memory.*$/memory = %s/" % mem]
+    cmd.append(XenHypervisor._ConfigFileName(instance.name))
+    result = utils.RunCmd(cmd)
+    if result.failed:
+      raise errors.HypervisorError("Failed to update memory for %s: %s (%s)" %
+                                   (instance.name, result.fail_reason,
+                                    result.output))
+
   def GetNodeInfo(self):
     """Return information about the node.
 
-- 
GitLab