Use _IsInstanceAlive instead of 'name in self.ListInstances()'.
It is faster and more accurate because we should kill a LXC container if
processes are running within, even if its rootfs does not exist.

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 57d6cfb..395a8c9 100644
--- a/lib/hypervisor/hv_lxc.py
+++ b/lib/hypervisor/hv_lxc.py
@@ -451,7 +451,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