Oslo is used for the various subsystems to communicate between each other. Details for the notifier and listener are given on the OpenStack website.
A sample listener can be written as:
and a sample notifier can be written as:
Running the notifier, we verify that the message is received by the listener:
Creating an instance from Horizon, we can also verify that the corresponding notification is received:
A sample listener can be written as:
import json from oslo_config import cfg import oslo_messaging class NotificationEndpoint(object): def info(self, ctxt, publisher_id, event_type, payload, metadata): print 'recv notification:' print json.dumps(payload, indent=4) def warn(self, ctxt, publisher_id, event_type, payload, metadata): None def error(self, ctxt, publisher_id, event_type, payload, metadata): None transport = oslo_messaging.get_transport(cfg.CONF) targets = [ oslo_messaging.Target(topic='notifications') ] endpoints = [ NotificationEndpoint() ] server = oslo_messaging.get_notification_listener(transport, targets, endpoints) server.start() server.wait()
and a sample notifier can be written as:
from oslo_config import cfg import oslo_messaging transport = oslo_messaging.get_transport(cfg.CONF) notifier = oslo_messaging.Notifier(transport, driver='messaging', publisher_id='testing', topic='notifications') notifier.info({'some': 'context'}, 'just.testing', {'heavy': 'payload'})
Running the notifier, we verify that the message is received by the listener:
{"heavy": "payload" }
Creating an instance from Horizon, we can also verify that the corresponding notification is received:
{"state_description": "","availability_zone": "nova","terminated_at": "","ephemeral_gb": 0,"instance_type_id": 6,"message": "Success","deleted_at": "","reservation_id": "r-wubyebqp","memory_mb": 64,"display_name": "test3","fixed_ips": [ {"version": 4,"vif_mac": "fa:16:3e:34:a8:42","floating_ips": [],"label": "private","meta": {},"address": "10.0.0.4","type": "fixed" } ],"hostname": "test3","state": "active","progress": "","launched_at": "2015-05-11T12:51:06.311068","metadata": {},"node": "herschel","ramdisk_id": "61aecaeb-3678-4194-882e-8a6c31f08d14","access_ip_v6": null,"disk_gb": 0,"access_ip_v4": null,"kernel_id": "7373a789-744d-4334-b4cf-91369724a1ea","host": "herschel","user_id": "d93941d832cd40aca0ed01795d9418cb","image_ref_url": "http://10.80.226.74:9292/images/63bb35dd-1203-4221-be18-1da850dbaf5a","cell_name": "","root_gb": 0,"tenant_id": "140d9f9ff9674c7fa93bd02ac9e9fda8","created_at": "2015-05-11 12:51:03+00:00","instance_id": "8415760e-1ce1-405f-96e8-4180c08112d0","instance_type": "m1.nano","vcpus": 1,"image_meta": {"kernel_id": "7373a789-744d-4334-b4cf-91369724a1ea","container_format": "ami","min_ram": "0","ramdisk_id": "61aecaeb-3678-4194-882e-8a6c31f08d14","disk_format": "ami","min_disk": "0","base_image_ref": "63bb35dd-1203-4221-be18-1da850dbaf5a" },"architecture": null,"os_type": null,"instance_flavor_id": "42" }