From d01baf5362231323e583ac3759059c18bbfa9cf2 Mon Sep 17 00:00:00 2001
From: Balazs Lecz <leczb@google.com>
Date: Tue, 6 Jul 2010 17:58:09 +0000
Subject: [PATCH] LXC: Use lxc-info to get instance info

Signed-off-by: Balazs Lecz <leczb@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/hypervisor/hv_lxc.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/hypervisor/hv_lxc.py b/lib/hypervisor/hv_lxc.py
index c7c6f24a1..683bc3820 100644
--- a/lib/hypervisor/hv_lxc.py
+++ b/lib/hypervisor/hv_lxc.py
@@ -142,7 +142,17 @@ class LXCHypervisor(hv_base.BaseHypervisor):
 
     """
     # TODO: read container info from the cgroup mountpoint
-    return (instance_name, 0, 0, 0, 0, 0)
+
+    result = utils.RunCmd(["lxc-info", "-n", instance_name])
+    if result.failed:
+      raise errors.HypervisorError("Can't run lxc-info: %s" % result.output)
+    # lxc-info output examples:
+    # 'ganeti-lxc-test1' is STOPPED
+    # 'ganeti-lxc-test1' is RUNNING
+    _, state = result.stdout.rsplit(None, 1)
+    if state == "RUNNING":
+      return (instance_name, 0, 0, 0, 0, 0)
+    return None
 
   def GetAllInstancesInfo(self):
     """Get properties of all instances.
-- 
GitLab