Pylxd events API

Following my post I have been trying to use the events API to get information regarding the creation of containers. However I could not find much documentation regarding this API call in particular and the example given in the pylxd documentation seems to not be working.

My test.py file:

from pylxd import Client
from pylxd import EventType

client = Client()
filter = set([EventType.Operation, EventType.Logging])
ws_client = client.events(event_filter=filter)
ws_client.connect()
ws_client.run()

The output:

$ python3 test.py

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    ws_client = client.events(event_filter=filter)
TypeError: events() got an unexpected keyword argument 'event_filter'

Without the event_filter keyword the script runs fine and I’m guessing the socket will then be used to monitor events. However I have been unable to find the location of the socket to get the output.

Are there any examples of using the events API for monitoring container creation?

Docs are wrong, try this;

Updated to print message when container created

from pylxd import Client
from pylxd import EventType
import json

def process_message(message):
    if message.is_text:
        message = json.loads(message.data)
        if message["metadata"]["action"] == "container-created":
            print("oo a container got created")

client = Client()
filter = set([EventType.Lifecycle])
# its "event_types" not "event_filter" as the docs suggest
ws_client = client.events(event_types=filter)
# Attach a callback so we process the messages as they come
ws_client.received_message = process_message
ws_client.connect()
ws_client.run()

Thanks again! That is exactly what I needed. Not sure why the official documentation is lacking a correct example. I’ll remember to check the source code too for keyword issues.