From cbd4c46406b0a34291a9962c834b7de871ce30ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Thu, 6 Sep 2012 16:06:27 -0400 Subject: [PATCH] Raise exception when getting Container instance as non-root in python3-lxc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The liblxc API currently doesn't work as non-root, so check that the euid is 0 when getting a Container instance in the python API. Signed-off-by: Stéphane Graber --- src/python-lxc/lxc/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py index 94616f59a..5fa99ed41 100644 --- a/src/python-lxc/lxc/__init__.py +++ b/src/python-lxc/lxc/__init__.py @@ -32,6 +32,7 @@ import warnings warnings.warn("The python-lxc API isn't yet stable " "and may change at any point in the future.", Warning, 2) + class ContainerNetwork(): props = {} @@ -142,6 +143,9 @@ class Container(_lxc.Container): Creates a new Container instance. """ + if os.geteuid() != 0: + raise Exception("Running as non-root.") + _lxc.Container.__init__(self, name) self.network = ContainerNetworkList(self)