Question

I use the lxc module for python and i need the python command to check up the current container state. Or i need a boolean command to check whether the container is current running.

Was it helpful?

Solution

I found the solution at self. It's possible to use the command wait to get a check for the current container state.

import lxc

container = lxc.Container("Test")
container.start()
if container.wait("RUNNING", timeout=5)
   container.stop()
   container.destroy()

This Command returns a true if it reach the state within the timeout. In other cases returns a false. And so we can make a check for the current container state with the standard library!

OTHER TIPS

Working with lxc (python3-lxc) version 1.0.3 I use

import lxc
container = lxc.Container("Test")

container.defined
True

to check if the container exists (in /var/lib/lxc) and

container.running
True

to see if the container runs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top