Introduce UNKNOWN ContainerState

This commit is contained in:
Disassembler 2020-04-26 18:32:06 +02:00
parent 0c590c820e
commit cedd257f63
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -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