Commit cfb5f9da authored by Guido Trotter's avatar Guido Trotter
Browse files

Implement memory ballooning in the fake hv


Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 80121c83
...@@ -123,7 +123,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -123,7 +123,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
file_name = self._InstanceFile(instance_name) file_name = self._InstanceFile(instance_name)
return os.path.exists(file_name) return os.path.exists(file_name)
def _MarkUp(self, instance): def _MarkUp(self, instance, memory):
"""Mark the instance as running. """Mark the instance as running.
This does no checks, which should be done by its callers. This does no checks, which should be done by its callers.
...@@ -133,7 +133,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -133,7 +133,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
fh = file(file_name, "w") fh = file(file_name, "w")
try: try:
fh.write("0\n%d\n%d\n" % fh.write("0\n%d\n%d\n" %
(instance.beparams[constants.BE_MAXMEM], (memory,
instance.beparams[constants.BE_VCPUS])) instance.beparams[constants.BE_VCPUS]))
finally: finally:
fh.close() fh.close()
...@@ -159,7 +159,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -159,7 +159,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
raise errors.HypervisorError("Failed to start instance %s: %s" % raise errors.HypervisorError("Failed to start instance %s: %s" %
(instance.name, "already running")) (instance.name, "already running"))
try: try:
self._MarkUp(instance) self._MarkUp(instance, instance.beparams[constants.BE_MAXMEM])
except IOError, err: except IOError, err:
raise errors.HypervisorError("Failed to start instance %s: %s" % raise errors.HypervisorError("Failed to start instance %s: %s" %
(instance.name, err)) (instance.name, err))
...@@ -186,6 +186,24 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -186,6 +186,24 @@ class FakeHypervisor(hv_base.BaseHypervisor):
""" """
return return
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
"""
if not self._IsAlive(instance.name):
raise errors.HypervisorError("Failed to balloon memory for %s: %s" %
(instance.name, "not running"))
try:
self._MarkUp(instance, mem)
except EnvironmentError, err:
raise errors.HypervisorError("Failed to balloon memory for %s: %s" %
(instance.name, utils.ErrnoOrStr(err)))
def GetNodeInfo(self): def GetNodeInfo(self):
"""Return information about the node. """Return information about the node.
...@@ -273,7 +291,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -273,7 +291,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
""" """
if success: if success:
self._MarkUp(instance) self._MarkUp(instance, instance.beparams[constants.BE_MAXMEM])
else: else:
# ensure it's down # ensure it's down
self._MarkDown(instance.name) self._MarkDown(instance.name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment