zoukankan      html  css  js  c++  java
  • OpenStack-RabbitMQ-获取vm、磁盘、网络设备的状态变化

    需求

    及时知道vm,硬盘,镜像,网络设备、负载均衡器状态变化

    分析

    Dashboard中也是通过定时使用ajax调用API来获取虚拟机的状态信息的
    定时轮训的方式过于被动

    解决方案

    共用rabbitmq

    实现方法

    Nova

    • 配置nova.conf
      vi /etc/nova/nova.conf
      notification_driver = nova.openstack.common.notifier.rpc_notifier
      notify_on_state_change=vm_state
    • 重启nova服务
      systemctl restart openstack-nova-compute.service
    • 监听rabbitmq
      routing_key:notification.info
      exchange:nova
    • 查看event_type为:compute.instance.update的消息,同时判断payload中state和old_state的值
    • 当两个值不一致的时候做相应的操作(更新数据库等)

    Neutron

    • 监听rabbitmq
      routing_key:notification.info
      exchange:neutron
    • 查看event_type为:参考excel给定名称
    • 当操作开始的时候有start消息,成功结束后由end消息,但是如果操作失败则没有end消息

    Glance

    • 修改glance-registry.conf、glance-api.conf
      notification_driver = messaging
      rpc_backend = rabbit
      rabbit_host = controller
      rabbit_password = RABBIT_PASS
    • 重启服务
      systemctl restart openstack-glance-api.service openstack-glance-registry.service
    • 监听rabbitmq
      routing_key:notification.info
      exchange:openstack
    • 查看event_type为:参考excel给定名称
    • 当操作开始的时候有start消息,成功结束后由end消息,但是如果操作失败则没有end消息

    Cinder

    • 修改cinder.conf
      control_exchange = cinder
      notification_driver = cinder.openstack.common.notifier.rpc_notifier
    • 重启服务
      控制节点
      systemctl restart openstack-cinder-api.service openstack-cinder-scheduler.service
      存储节点
      systemctl restart openstack-cinder-volume.service
    • 监听rabbitmq
      routing_key:notification.info
      exchange:cinder
    • 查看event_type为:参考excel给定名称
    • 当操作开始的时候有start消息,成功结束后由end消息,但是如果操作失败则没有end消息

    负载均衡

    暂时没有这个机制,需要添加

    ps

    监听rabbitmq的时候不能直接监听notification.info队列,这样会造成消息被接收后,其他监听这个队列的消费者就获取不到消息了
    所以只要监听routing_key是notification.info就可以了,即使用订阅模式

    测试脚本

    #!/usr/bin/env python
    import pika
    import json
     
    credentials = pika.PlainCredentials('guest', 'RABBIT_PASS')
    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/

  • 相关阅读:
    async简单使用
    node调用phantomjs-node爬取复杂页面
    mongodb3 ubuntu离线安装(非apt-get)及用户管理
    2040-亲和数(java)
    JavaScript闭包简单理解
    nodejs构建多房间简易聊天室
    linux下安装nodejs及npm
    EventBus轻松使用
    mysql用户创建及授权
    python中json的基本使用
  • 原文地址:https://www.cnblogs.com/smallcoderhujin/p/4316456.html
Copyright © 2011-2022 走看看