Permalink
Browse files

Replaced options rabbit_host,rabbit_port with rabbit_addresses

  • Loading branch information...
1 parent 24c14d5 commit 987b60771143e5b71d8f1bba10ffa60725c49d1e @jkff jkff committed Feb 20, 2012
Showing with 18 additions and 21 deletions.
  1. +3 −9 doc/source/configuring.rst
  2. +1 −2 etc/glance-api.conf
  3. +14 −10 glance/notifier/notify_kombu.py
View
12 doc/source/configuring.rst
@@ -645,17 +645,11 @@ Sets the strategy used for notifications. Options are ``logging``,
``rabbit`` and ``noop``.
For more information :doc:`Glance notifications <notifications>`
-* ``rabbit_host``
+* ``rabbit_addresses``
-Optional. Default: ``localhost``
+Optional. Default: ``localhost:5672``
-Host to connect to when using ``rabbit`` strategy.
-
-* ``rabbit_port``
-
-Optional. Default: ``5672``
-
-Port to connect to when using ``rabbit`` strategy.
+Host:port pairs of a RabbitMQ cluster to connect to when using ``rabbit`` strategy.
* ``rabbit_use_ssl``
View
3 etc/glance-api.conf
@@ -91,8 +91,7 @@ notifier_strategy = noop
# Configuration options if sending notifications via rabbitmq (these are
# the defaults)
-rabbit_host = localhost
-rabbit_port = 5672
+rabbit_addresses = localhost:5672
rabbit_use_ssl = false
rabbit_userid = guest
rabbit_password = guest
View
24 glance/notifier/notify_kombu.py
@@ -36,8 +36,7 @@ class RabbitStrategy(strategy.Strategy):
"""A notifier that puts a message on a queue when called."""
opts = [
- cfg.StrOpt('rabbit_host', default='localhost'),
- cfg.IntOpt('rabbit_port', default=5672),
+ cfg.ListOpt('rabbit_addresses', default='localhost:5672'),
cfg.BoolOpt('rabbit_use_ssl', default=False),
cfg.StrOpt('rabbit_userid', default='guest'),
cfg.StrOpt('rabbit_password', default='guest'),
@@ -77,13 +76,14 @@ def _close(self):
pass
self.connection = None
- def _connect(self):
+ def _connect(self, host, port)
"""Connect to rabbit. Exceptions should be handled by the
caller.
"""
+
log_info = {}
- log_info['hostname'] = self._conf.rabbit_host
- log_info['port'] = self._conf.rabbit_port
+ log_info['hostname'] = host
+ log_info['port'] = port
if self.connection:
logger.info(_("Reconnecting to AMQP server on "
"%(hostname)s:%(port)d") % log_info)
@@ -92,8 +92,8 @@ def _connect(self):
logger.info(_("Connecting to AMQP server on "
"%(hostname)s:%(port)d") % log_info)
self.connection = kombu.connection.BrokerConnection(
- hostname=self._conf.rabbit_host,
- port=self._conf.rabbit_port,
+ hostname=host,
+ port=port,
userid=self._conf.rabbit_userid,
password=self._conf.rabbit_password,
virtual_host=self._conf.rabbit_virtual_host,
@@ -124,9 +124,13 @@ def _connect(self):
def reconnect(self):
"""Handles reconnecting and re-establishing queues."""
while True:
+ adr = self._conf.rabbit_addresses
+ host, port = adr[self.retry_attempts % len(adr)].split(':')
+ port = int(port)
+
self.retry_attempts += 1
try:
- self._connect()
+ self._connect(host, port)
return
except self.connection_errors, e:
pass
@@ -143,8 +147,8 @@ def reconnect(self):
log_info = {}
log_info['err_str'] = str(e)
log_info['max_retries'] = self.max_retries
- log_info['hostname'] = self._conf.rabbit_host
- log_info['port'] = self._conf.rabbit_port
+ log_info['hostname'] = host
+ log_info['port'] = port
if self.max_retries and self.retry_attempts >= self.max_retries:
logger.exception(_('Unable to connect to AMQP server on '

0 comments on commit 987b607

Please sign in to comment.