Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
rdudyala | b086cf3 | 2016-08-11 00:07:45 -0400 | [diff] [blame] | 17 | from kombu.connection import BrokerConnection |
| 18 | from kombu.messaging import Exchange, Queue, Consumer, Producer |
| 19 | import six |
| 20 | import uuid |
| 21 | import datetime |
| 22 | |
| 23 | keystone_tenant_id='3a397e70f64e4e40b69b6266c634d9d0' |
| 24 | keystone_user_id='1e3ce043029547f1a61c1996d1a531a2' |
| 25 | rabbit_user='openstack' |
| 26 | rabbit_password='password' |
| 27 | rabbit_host='localhost' |
| 28 | vcpeservice_rabbit_exchange='vcpeservice' |
| 29 | cpe_publisher_id='vcpe_publisher' |
| 30 | |
| 31 | producer = None |
| 32 | |
| 33 | def setup_rabbit_mq_channel(): |
| 34 | global producer |
| 35 | global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id |
| 36 | vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False) |
| 37 | # connections/channels |
| 38 | connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password) |
| 39 | print 'Connection to RabbitMQ server successful' |
| 40 | channel = connection.channel() |
| 41 | # produce |
| 42 | producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info') |
| 43 | |
| 44 | def publish_cpe_stats(): |
| 45 | global producer |
| 46 | global keystone_tenant_id, keystone_user_id, cpe_publisher_id |
| 47 | |
| 48 | msg = {'event_type': 'vcpe', |
| 49 | 'message_id':six.text_type(uuid.uuid4()), |
| 50 | 'publisher_id': cpe_publisher_id, |
| 51 | 'timestamp':datetime.datetime.now().isoformat(), |
| 52 | 'priority':'INFO', |
| 53 | 'payload': {'vcpe_id':'vcpe-222-432', |
| 54 | 'user_id': keystone_user_id, |
| 55 | 'tenant_id': keystone_tenant_id |
| 56 | } |
| 57 | } |
| 58 | producer.publish(msg) |
| 59 | msg = {'event_type': 'vcpe.dns.cache.size', |
| 60 | 'message_id':six.text_type(uuid.uuid4()), |
| 61 | 'publisher_id': cpe_publisher_id, |
| 62 | 'timestamp':datetime.datetime.now().isoformat(), |
| 63 | 'priority':'INFO', |
| 64 | 'payload': {'vcpe_id':'vcpe-222-432', |
| 65 | 'user_id': keystone_user_id, |
| 66 | 'tenant_id': keystone_tenant_id, |
| 67 | 'cache_size':150 |
| 68 | } |
| 69 | } |
| 70 | producer.publish(msg) |
| 71 | |
| 72 | if __name__ == "__main__": |
| 73 | setup_rabbit_mq_channel() |
| 74 | publish_cpe_stats() |