From 8bfd5c8b1336f86830c59319893dbca554d92f54 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 14 Jan 2016 15:25:37 +0000 Subject: [PATCH] Ad function to get uris when a prefix is being used --- lib/charm/openstack/adapters.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/charm/openstack/adapters.py b/lib/charm/openstack/adapters.py index 2ad31b3..4054348 100644 --- a/lib/charm/openstack/adapters.py +++ b/lib/charm/openstack/adapters.py @@ -78,7 +78,7 @@ class RabbitMQRelationAdapter(OpenStackRelationAdapter): class DatabaseRelationAdapter(OpenStackRelationAdapter): """ - Adapter for the RabbitMQRequires relation interface. + Adapter for the Database relation interface. """ interface_type = "database" @@ -98,14 +98,21 @@ class DatabaseRelationAdapter(OpenStackRelationAdapter): def type(self): return 'mysql' - @property - def uri(self): - uri = 'mysql://{}:{}@{}/{}'.format( - self.username, - self.password, - self.host, - self.database, - ) + def get_uri(self, prefix=None): + if prefix: + uri = 'mysql://{}:{}@{}/{}'.format( + self.relation.username(prefix=prefix), + self.relation.password(prefix=prefix), + self.host, + self.relation.database(prefix=prefix), + ) + else: + uri = 'mysql://{}:{}@{}/{}'.format( + self.username, + self.password, + self.host, + self.database, + ) if self.ssl_ca: uri = '{}?ssl_ca={}'.format(uri, self.ssl_ca) if self.ssl_cert: @@ -114,6 +121,12 @@ class DatabaseRelationAdapter(OpenStackRelationAdapter): return uri + @property + def uri(self): + return self.get_uri() + + + class ConfigurationAdapter(object): """ Configuration Adapter which provides python based access