From cedd257f638ccacf59380f20e36a4839896edaf8 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sun, 26 Apr 2020 18:32:06 +0200 Subject: [PATCH] Introduce UNKNOWN ContainerState --- usr/lib/python3.8/spoc/container.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr/lib/python3.8/spoc/container.py b/usr/lib/python3.8/spoc/container.py index a887ba3..b42faee 100644 --- a/usr/lib/python3.8/spoc/container.py +++ b/usr/lib/python3.8/spoc/container.py @@ -23,6 +23,7 @@ class ContainerState(enum.Enum): FREEZING = 'FREEZING' FROZEN = 'FROZEN' THAWED = 'THAWED' + UNKNOWN = 'UNKNOWN' DEFINITION_MEMBERS = {'build', 'depends', 'layers', 'mounts', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt'} @@ -65,8 +66,11 @@ class Container: def get_state(self): # Get current state of the container, uses LXC monitor socket accessible only in ocntainer's namespace - state = subprocess.run(['lxc-info', '-sH', '-P', config.CONTAINERS_DIR, self.name], capture_output=True, check=True) - return ContainerState[state.stdout.strip().decode()] + try: + state = subprocess.run(['lxc-info', '-sH', '-P', config.CONTAINERS_DIR, self.name], capture_output=True, check=True) + return ContainerState[state.stdout.strip().decode()] + except subprocess.CalledProcessError: + return ContainerState.UNKNOWN def is_running(self): # Convenience method to determine if the container is running