From ace0c46cafeaa9313b3a44cad6e7f53e120babc0 Mon Sep 17 00:00:00 2001 From: James Page Date: Wed, 25 Jan 2017 15:09:00 +0000 Subject: [PATCH] Add support for network spaces Automatically set the private-address relation key to the network space binding for the relation the interface is supporting for Juju >= 2.0; for older Juju versions continue to use "unit-get private-address". This change also adds the ability for the consuming charm to override the hostname provided on the relation using the option hostname parameter. Change-Id: Iee0d1ac7168fe0c32deaf03add5cb261da6c2a79 --- requires.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/requires.py b/requires.py index b1a2c6d..fa9f9c7 100644 --- a/requires.py +++ b/requires.py @@ -84,13 +84,22 @@ class RabbitMQRequires(RelationBase): return True return False - def request_access(self, username, vhost): + def request_access(self, username, vhost, hostname=None): """ Request access to vhost for the supplied username. """ + if not hostname: + try: + hostname = hookenv.network_get_primary_address( + self.conversation().relation_name + ) + except NotImplementedError: + hostname = hookenv.unit_private_ip() + relation_info = { 'username': username, 'vhost': vhost, + 'private-address': hostname, } self.set_local(**relation_info) self.set_remote(**relation_info)