{
"timestamp": "2015-06-09T19:07:24.379615253-06:00", // Current timestamp
"type": "operation", // Notification type
"metadata": {} // Extra resource or type specific metadata
}
In the comment there is ‘type specific metadata’ mentioned. How can I query the type?
Maybe I don’t need the Event API because I simply want to create and start a container via my c# program. I think I need the event api due to the async instance api.
For async calls, it’s indeed best to do something like we do in the Go client.
Effectively, connect to /1.0/events ahead of time and have a separate handler loop for it. Then perform your async call and use the notifications from the handler to track the process of the operation to conclusion.
This avoids races and reduces the load on LXD itself.
The alternative would be to hit up /1.0/operations/UUID/wait using the UUID from the async call. This effectively turns things into more of a sync API but results in more queries and can be racy for very short lived operations (though LXD will keep the operation endpoint valid for 5s after it completes to minimize the risk of races).
In this case, the Go client knows that CreateInstance is async so it will connect to the events API if it hasn’t already. It then parses the operation response and turns it into an operation object which has a Wait() property. Calling Wait() adds a handler to the event listener filtering for that particular operation and will return when it’s reached a final state.
To be fair, this is rather complex logic that’s pretty easy to get wrong.
If you’re looking for a quick first step, ignore the events API, get the UUID from the operation you’re returned back and hit /1.0/operations/UUID/wait to get a blocking call.
It’s slightly racy but unless your server fails to respond within 5s, you should be fine.