Commit a3f0f306 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Add Python hypervisor instance state



Add 'HvInstanceState' which represents the state of an instance
(either 'running' or 'shutdown') and fix the remaining hypervisor
backends to return a value of this type.  Before this patch, each
backend was returning their own value, some were returning strings,
others integers.  However, the value that represents the state of an
instance was never actually used in Ganeti, until instance shutdown
detection became necessary.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 270df828
......@@ -1377,7 +1377,7 @@ def GetInstanceInfo(instance, hname, hvparams=None):
@rtype: dict
@return: dictionary with the following keys:
- memory: memory size of instance (int)
- state: xen state of instance (string)
- state: state of instance (HvInstanceState)
- time: cpu time of instance (float)
- vcpus: the number of vcpus (int)
......
......@@ -144,6 +144,19 @@ def ParamInSet(required, my_set):
return (required, fn, err, None, None)
class HvInstanceState(object):
RUNNING = 0
SHUTDOWN = 1
@staticmethod
def IsRunning(s):
return s == HvInstanceState.RUNNING
@staticmethod
def IsShutdown(s):
return s == HvInstanceState.SHUTDOWN
class BaseHypervisor(object):
"""Abstract virtualisation technology interface
......
......@@ -123,7 +123,7 @@ class ChrootManager(hv_base.BaseHypervisor):
dir_name = self._InstanceDir(instance_name)
if not self._IsDirLive(dir_name):
raise HypervisorError("Instance %s is not running" % instance_name)
return (instance_name, 0, 0, 0, 0, 0)
return (instance_name, 0, 0, 0, hv_base.HvInstanceState.RUNNING, 0)
def GetAllInstancesInfo(self, hvparams=None):
"""Get properties of all instances.
......
......@@ -80,7 +80,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
inst_id = fh.readline().strip()
memory = utils.TryConvert(int, fh.readline().strip())
vcpus = utils.TryConvert(int, fh.readline().strip())
stat = "---b-"
stat = hv_base.HvInstanceState.RUNNING
times = 0
return (instance_name, inst_id, memory, vcpus, stat, times)
finally:
......@@ -104,13 +104,13 @@ class FakeHypervisor(hv_base.BaseHypervisor):
inst_id = "-1"
memory = 0
vcpus = 1
stat = "-----"
stat = hv_base.HvInstanceState.SHUTDOWN
times = -1
try:
inst_id = fh.readline().strip()
memory = utils.TryConvert(int, fh.readline().strip())
vcpus = utils.TryConvert(int, fh.readline().strip())
stat = "---b-"
stat = hv_base.HvInstanceState.RUNNING
times = 0
finally:
fh.close()
......
......@@ -1163,7 +1163,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
return None
_, memory, vcpus = self._InstancePidInfo(pid)
istat = "---b-"
istat = hv_base.HvInstanceState.RUNNING
times = 0
try:
......
......@@ -189,7 +189,8 @@ class LXCHypervisor(hv_base.BaseHypervisor):
cpu_list = self._GetCgroupCpuList(instance_name)
memory = self._GetCgroupMemoryLimit(instance_name) / (1024 ** 2)
return (instance_name, 0, memory, len(cpu_list), 0, 0)
return (instance_name, 0, memory, len(cpu_list),
hv_base.HvInstanceState.RUNNING, 0)
def GetAllInstancesInfo(self, hvparams=None):
"""Get properties of all instances.
......
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