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