Introduce UNKNOWN ContainerState
This commit is contained in:
parent
0c590c820e
commit
cedd257f63
@ -23,6 +23,7 @@ class ContainerState(enum.Enum):
|
|||||||
FREEZING = 'FREEZING'
|
FREEZING = 'FREEZING'
|
||||||
FROZEN = 'FROZEN'
|
FROZEN = 'FROZEN'
|
||||||
THAWED = 'THAWED'
|
THAWED = 'THAWED'
|
||||||
|
UNKNOWN = 'UNKNOWN'
|
||||||
|
|
||||||
DEFINITION_MEMBERS = {'build', 'depends', 'layers', 'mounts', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt'}
|
DEFINITION_MEMBERS = {'build', 'depends', 'layers', 'mounts', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt'}
|
||||||
|
|
||||||
@ -65,8 +66,11 @@ class Container:
|
|||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
# Get current state of the container, uses LXC monitor socket accessible only in ocntainer's namespace
|
# Get current state of the container, uses LXC monitor socket accessible only in ocntainer's namespace
|
||||||
|
try:
|
||||||
state = subprocess.run(['lxc-info', '-sH', '-P', config.CONTAINERS_DIR, self.name], capture_output=True, check=True)
|
state = subprocess.run(['lxc-info', '-sH', '-P', config.CONTAINERS_DIR, self.name], capture_output=True, check=True)
|
||||||
return ContainerState[state.stdout.strip().decode()]
|
return ContainerState[state.stdout.strip().decode()]
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return ContainerState.UNKNOWN
|
||||||
|
|
||||||
def is_running(self):
|
def is_running(self):
|
||||||
# Convenience method to determine if the container is running
|
# Convenience method to determine if the container is running
|
||||||
|
Loading…
Reference in New Issue
Block a user