Add the _IsInstanceAlive method which checks whether instance is running or not.
Signed-off-by: Yuto KAWAMURA(kawamuray) <[email protected]> --- lib/hypervisor/hv_lxc.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/hypervisor/hv_lxc.py b/lib/hypervisor/hv_lxc.py index 6f883e9..9a339a6 100644 --- a/lib/hypervisor/hv_lxc.py +++ b/lib/hypervisor/hv_lxc.py @@ -226,6 +226,18 @@ class LXCHypervisor(hv_base.BaseHypervisor): """ return [iinfo[0] for iinfo in self.GetAllInstancesInfo()] + @classmethod + def _IsInstanceAlive(cls, instance_name): + """Return True if instance is alive. + + """ + result = utils.RunCmd(["lxc-ls", "--running"]) + if result.failed: + raise HypervisorError("Failed to get running LXC containers list: %s" % + result.output) + + return instance_name in result.stdout.split() + def GetInstanceInfo(self, instance_name, hvparams=None): """Get instance properties. -- 1.8.5.5
