diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-09-12 13:47:52 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-09-12 13:47:52 +0000 |
| commit | ccaaa26dd3afa62599ea3b476e2a5d1af7e075ef (patch) | |
| tree | 9943bd86980840fff435edb1a2f5c5536248545b /openstack | |
| parent | 95cd3a7fad2d0335c65394379c35a798df9d25b4 (diff) | |
| parent | 16ad97c13fb296125a843d1dda31900994628727 (diff) | |
| download | oslo-ccaaa26dd3afa62599ea3b476e2a5d1af7e075ef.tar.gz oslo-ccaaa26dd3afa62599ea3b476e2a5d1af7e075ef.tar.xz oslo-ccaaa26dd3afa62599ea3b476e2a5d1af7e075ef.zip | |
Merge "Make projects define 'control_exchange'."
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/common/rpc/__init__.py | 11 | ||||
| -rw-r--r-- | openstack/common/rpc/amqp.py | 8 | ||||
| -rw-r--r-- | openstack/common/rpc/impl_kombu.py | 13 | ||||
| -rw-r--r-- | openstack/common/rpc/impl_qpid.py | 17 |
4 files changed, 30 insertions, 19 deletions
diff --git a/openstack/common/rpc/__init__.py b/openstack/common/rpc/__init__.py index 5b1f8d1..da45d5a 100644 --- a/openstack/common/rpc/__init__.py +++ b/openstack/common/rpc/__init__.py @@ -53,12 +53,17 @@ rpc_opts = [ ], help='Modules of exceptions that are permitted to be recreated' 'upon receiving exception data from an rpc call.'), - cfg.StrOpt('control_exchange', - default='nova', - help='AMQP exchange to connect to if using RabbitMQ or Qpid'), cfg.BoolOpt('fake_rabbit', default=False, help='If passed, use a fake RabbitMQ provider'), + # + # The following options are not registered here, but are expected to be + # present. The project using this library must register these options with + # the configuration so that project-specific defaults may be defined. + # + #cfg.StrOpt('control_exchange', + # default='nova', + # help='AMQP exchange to connect to if using RabbitMQ or Qpid'), ] cfg.CONF.register_opts(rpc_opts) diff --git a/openstack/common/rpc/amqp.py b/openstack/common/rpc/amqp.py index 10b3869..79eda39 100644 --- a/openstack/common/rpc/amqp.py +++ b/openstack/common/rpc/amqp.py @@ -34,6 +34,7 @@ from eventlet import greenpool from eventlet import pools from eventlet import semaphore +from openstack.common import cfg from openstack.common import excutils from openstack.common.gettextutils import _ from openstack.common import local @@ -416,3 +417,10 @@ def notify(conf, context, topic, msg, connection_pool): def cleanup(connection_pool): if connection_pool: connection_pool.empty() + + +def get_control_exchange(conf): + try: + return conf.control_exchange + except cfg.NoSuchOptError: + return 'openstack' diff --git a/openstack/common/rpc/impl_kombu.py b/openstack/common/rpc/impl_kombu.py index 66cf0a9..294fc0a 100644 --- a/openstack/common/rpc/impl_kombu.py +++ b/openstack/common/rpc/impl_kombu.py @@ -210,10 +210,10 @@ class TopicConsumer(ConsumerBase): 'auto_delete': False, 'exclusive': False} options.update(kwargs) - exchange = kombu.entity.Exchange(name=conf.control_exchange, - type='topic', - durable=options['durable'], - auto_delete=options['auto_delete']) + exchange = kombu.entity.Exchange( + name=rpc_amqp.get_control_exchange(conf), + type='topic', durable=options['durable'], + auto_delete=options['auto_delete']) super(TopicConsumer, self).__init__(channel, callback, tag, @@ -307,8 +307,9 @@ class TopicPublisher(Publisher): 'auto_delete': False, 'exclusive': False} options.update(kwargs) - super(TopicPublisher, self).__init__(channel, conf.control_exchange, - topic, type='topic', **options) + super(TopicPublisher, self).__init__(channel, + rpc_amqp.get_control_exchange(conf), topic, + type='topic', **options) class FanoutPublisher(Publisher): diff --git a/openstack/common/rpc/impl_qpid.py b/openstack/common/rpc/impl_qpid.py index 992790a..93d771c 100644 --- a/openstack/common/rpc/impl_qpid.py +++ b/openstack/common/rpc/impl_qpid.py @@ -181,9 +181,8 @@ class TopicConsumer(ConsumerBase): """ super(TopicConsumer, self).__init__(session, callback, - "%s/%s" % (conf.control_exchange, - topic), - {}, name or topic, {}) + "%s/%s" % (rpc_amqp.get_control_exchange(conf), topic), + {}, name or topic, {}) class FanoutConsumer(ConsumerBase): @@ -256,9 +255,8 @@ class TopicPublisher(Publisher): def __init__(self, conf, session, topic): """init a 'topic' publisher. """ - super(TopicPublisher, self).__init__( - session, - "%s/%s" % (conf.control_exchange, topic)) + super(TopicPublisher, self).__init__(session, + "%s/%s" % (rpc_amqp.get_control_exchange(conf), topic)) class FanoutPublisher(Publisher): @@ -276,10 +274,9 @@ class NotifyPublisher(Publisher): def __init__(self, conf, session, topic): """init a 'topic' publisher. """ - super(NotifyPublisher, self).__init__( - session, - "%s/%s" % (conf.control_exchange, topic), - {"durable": True}) + super(NotifyPublisher, self).__init__(session, + "%s/%s" % (rpc_amqp.get_control_exchange(conf), topic), + {"durable": True}) class Connection(object): |
