This commit is contained in:
Liam Young 2015-12-11 10:45:04 +00:00
parent 48383f6c18
commit 909bd71fb5
7 changed files with 61 additions and 34 deletions

View File

@ -13,8 +13,12 @@ class OpenStackRelationAdapter(object):
The generic type of the interface the adapter is wrapping.
"""
def __init__(self, relation):
def __init__(self, relation, accessors=None):
self.relation = relation
if accessors:
self.accessors = accessors
else:
self.accessors = []
self._setup_properties()
@property
@ -29,7 +33,8 @@ class OpenStackRelationAdapter(object):
Setup property based accessors for an interfaces
auto accessors
"""
for field in self.relation.auto_accessors:
self.accessors.extend(self.relation.auto_accessors)
for field in self.accessors:
meth_name = field.replace('-', '_')
# TODO: see if we can make this dynamic, rather
# than making all calls on setup.
@ -44,6 +49,10 @@ class RabbitMQRelationAdapter(OpenStackRelationAdapter):
interface_type = "messaging"
def __init__(self, relation):
add_accessors = ['vhost', 'username']
super(RabbitMQRelationAdapter,self).__init__(relation, add_accessors)
@property
def host(self):
"""
@ -66,13 +75,29 @@ class RabbitMQRelationAdapter(OpenStackRelationAdapter):
else:
return None
@property
def vhost(self):
return self.relation.vhost()
class DatabaseRelationAdapter(OpenStackRelationAdapter):
"""
Adapter for the RabbitMQRequires relation interface.
"""
interface_type = "database"
def __init__(self, relation):
add_accessors = ['password', 'username', 'database']
super(DatabaseRelationAdapter,self).__init__(relation, add_accessors)
@property
def username(self):
return self.relation.username()
def host(self):
"""
Hostname that should be used to access RabbitMQ.
"""
return self.relation.db_host()
@property
def type(self):
return 'mysql'
class ConfigurationAdapter(object):
"""
@ -109,6 +134,7 @@ class OpenStackRelationAdapters(object):
_adapters = {
'amqp': RabbitMQRelationAdapter,
'shared_db': DatabaseRelationAdapter,
}
"""
Default adapter mappings; may be overridden by relation adapters
@ -119,7 +145,7 @@ class OpenStackRelationAdapters(object):
self._adapters.update(self.relation_adapters)
self._relations = []
for relation in relations:
relation_name = relation.relation_name
relation_name = relation.relation_name.replace('-', '_')
if relation_name in self._adapters:
self.__dict__[relation_name] = (
self._adapters[relation_name](relation)

View File

@ -0,0 +1,5 @@
{% if shared_db.host -%}
[database]
connection = {{ shared_db.type }}://{{ shared_db.username }}:{{ shared_db.password }}@{{ shared_db.host }}/{{ shared_db.database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %}
{% endif -%}

View File

@ -0,0 +1,22 @@
{% if amqp.host or amqp.hosts -%}
[oslo_messaging_rabbit]
rabbit_userid = {{ amqp.username }}
rabbit_virtual_host = {{ amqp.vhost }}
rabbit_password = {{ amqp.password }}
{% if amqp.hosts -%}
rabbit_hosts = {{ amqp.hosts }}
{% if amqp.ha_queues -%}
rabbit_ha_queues = True
rabbit_durable_queues = False
{% endif -%}
{% else -%}
rabbit_host = {{ amqp.host }}
{% endif -%}
{% if amqp.ssl_data_complete == True -%}
rabbit_use_ssl = True
rabbit_port = {{ amqp.ssl_port }}
{% if amqp.ssl_ca -%}
kombu_ssl_ca_certs = {{ amqp.ssl_ca }}
{% endif -%}
{% endif -%}
{% endif -%}

View File

@ -1,4 +0,0 @@
{% if database_host -%}
[database]
connection = {{ database_type }}://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %}
{% endif -%}

View File

@ -1,22 +0,0 @@
{% if rabbitmq_host or rabbitmq_hosts -%}
[oslo_messaging_rabbit]
rabbit_userid = {{ rabbitmq_user }}
rabbit_virtual_host = {{ rabbitmq_virtual_host }}
rabbit_password = {{ rabbitmq_password }}
{% if rabbitmq_hosts -%}
rabbit_hosts = {{ rabbitmq_hosts }}
{% if rabbitmq_ha_queues -%}
rabbit_ha_queues = True
rabbit_durable_queues = False
{% endif -%}
{% else -%}
rabbit_host = {{ rabbitmq_host }}
{% endif -%}
{% if rabbit_ssl_port -%}
rabbit_use_ssl = True
rabbit_port = {{ rabbit_ssl_port }}
{% if rabbit_ssl_ca -%}
kombu_ssl_ca_certs = {{ rabbit_ssl_ca }}
{% endif -%}
{% endif -%}
{% endif -%}