Search code examples
pythonlxc

How i can get the current state of a lxc container with python?


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.


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!