OpenStack components generate notifications that can provide useful insight into what is going on in OpenStack. Let’s create a simple subcriber that dumps incoming notifications from OpenStack Nova to standard output.
Configure Nova to generate notifications
First let’s make sure that Nova is configured to send out notifications. You should find the following lines in your /etc/nova/nova.conf
file:
|
|
Property notification_topics
determines the base name of the topic (routing key) where the notification messages are sent to. The full name of the topic where the info-level notifications are published is notifications.info
.
The possible choices of notification driver are briefly described in
oslo.messaging FAQ. The messagingv2
option instructs Nova to send notifications using the 2.0 message format that wraps the messages into an oslo.messaging envelope. The notify_on_state_change
property determines the kind of notifications Nova should send out. You can set its value to vm_and_task_state
if you want to receive additional notifications. After you modified your /etc/nova/nova.conf
restart the Nova components for changes to take effect:
|
|
Implement Nova notifications subscriber
Internally, Nova uses Kombu messaging library to connect to the RabbitMQ message broker. Let’s use this Python library in our notifications subscriber to avoid the need to install additional libraries.
Nova sends out notification messages to a topic exchange called nova
with the routing key notifications.info
. In order to receive notification messages our client application needs to create a queue and bind it to the nova
exchange. The binding key used to bind the queue to the nova
exchange must match the routing key used by Nova to send out notification messages. Whenever there’s a new message in the queue the Kombu library will invoke the on_message
callback on our client to handle the message. The complete code of our notifications subscriber looks as follows:
|
|
After you run the notifications subscriber and if everything went fine you should see the output similar to:
|
|
Whenever you create/delete an instance in OpenStack a host of notification messages should be rolling on your screen.
Troubleshooting
RabbitMQ comes with a rabbitmqctl
command which can be used to inspect the state of the exchanges, queues and bindings in the running RabbitMQ instance. First let’s check that the nova
topic exchange exists:
|
|
Next let’s make sure that our consumer queue was successfully created:
|
|
As a last thing we want to double-check that our nova_dump_queue
was bound with the nova
exchange using the binding key notifications.info
:
|
|
References
You can find more detailed information on topic exchanges in the great RabbitMQ tutorial here. A version of the Nova notifications subscriber implemented with Python Pika library is described in this blogpost.