Use _IsInstanceAlive instead of 'name in self.ListInstances()'.
It is more fast and accurate because we should kill LXC container if
here is alive process even if its rootfs is not exists.

Signed-off-by: Yuto KAWAMURA(kawamuray) <[email protected]>
---
 lib/hypervisor/hv_lxc.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/hypervisor/hv_lxc.py b/lib/hypervisor/hv_lxc.py
index 4d358c0..037d3b7 100644
--- a/lib/hypervisor/hv_lxc.py
+++ b/lib/hypervisor/hv_lxc.py
@@ -453,7 +453,7 @@ class LXCHypervisor(hv_base.BaseHypervisor):
     if name is None:
       name = instance.name
 
-    if name in self.ListInstances():
+    if self._IsInstanceAlive(instance.name):
       lxc_stop_cmd = ["lxc-stop", "-n", name]
 
       if force:
-- 
1.8.5.5

Reply via email to