Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. ########################################
  2. # Required changes to nova.conf #
  3. ########################################
  4. # notification_driver=nova.openstack.common.notifier.rpc_notifier
  5. # notification_topics = notifications
  6. # notify_on_state_change = vm_and_task_state
  7. # instance_usage_audit_period = hour
  8. # instance_usage_audit = True
  9. # default_notification_level = INFO
  10. # notify_api_faults = true
  11. ###### Restart Nova services after making the above changes #######
  12.  
  13. # Environment Variables: $AMQP_USER, $AMQP_PASSWORD, $AMQP_HOST
  14. import os
  15. from kombu import Connection, Exchange, Queue
  16. from pprint import pprint
  17.  
  18. nova_x = Exchange('nova', type='topic', durable=False)
  19. info_q = Queue('notifications.info', exchange=nova_x, durable=False,
  20. routing_key='notifications.info')
  21.  
  22. def process_msg(body, message):
  23. print '='*80
  24. pprint(body)
  25. message.ack()
  26.  
  27. # Maybe wrap these in try/except: will raise KeyError if not found
  28. AMQP_USER = os.environ['AMQP_USER']
  29. AMQP_PASSWORD = os.environ['AMQP_PASSWORD']
  30. AMQP_HOST = os.environ['AMQP_HOST']
  31.  
  32.  
  33. # Maybe wrap this in a try/except: will raise socket.error if connection refused
  34. with Connection('amqp://{0}:{1}@{2}//'.format(AMQP_USER, AMQP_PASSWORD, AMQP_HOST)) as conn:
  35. with conn.Consumer(info_q, callbacks=[process_msg]):
  36. try:
  37. while True:
  38. conn.drain_events()
  39. except KeyboardInterrupt:
  40. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement