标签:
及时知道vm状态的变化
Dashboard中也是通过定时使用ajax调用API来获取虚拟机的状态信息的
定时轮训的方式过于被动
共用rabbitmq
vi /etc/nova/nova.conf notification_driver = nova.openstack.common.notifier.rpc_notifier notify_on_state_change=vm_and_task_state
routing_key:notification.info exchange:nova
#!/usr/bin/env python import pika import json credentials = pika.PlainCredentials(‘xxx‘, ‘xxx‘) params = pika.ConnectionParameters(host=‘xxx‘,credentials=credentials) connection = pika.BlockingConnection(params) channel = connection.channel() exchange_name = ‘nova‘ queue_name = channel.queue_declare(exclusive=True).method.queue binding_key = ‘notifications.info‘ channel.exchange_declare(exchange=exchange_name,type=‘topic‘) channel.queue_bind(exchange=exchange_name, queue=queue_name, routing_key=binding_key) print ‘ [*] Waiting for logs. To exit press CTRL+C‘ def callback(ch, method, properties, body): b= json.loads(body) print b[‘event_type‘],b[‘payload‘][‘state‘], b[‘payload‘][‘old_state‘] # for key,value in b.iteritems(): # print key,‘:‘,value channel.basic_consume(callback,queue=queue_name,no_ack=True) channel.start_consuming()
https://prosuncsedu.wordpress.com/2014/01/08/notification-of-actions-in-openstack-nova/
标签:
原文地址:http://www.cnblogs.com/smallcoderhujin/p/4316456.html