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
This commit is contained in:
James Page 2017-01-25 15:09:00 +00:00
parent adc61d2ff9
commit ace0c46caf
1 changed files with 10 additions and 1 deletions

View File

@ -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)