Merge pull request #2 from openstack-charmers/make_bindings_optional
Make publishing of links from bindings charm controlled
This commit is contained in:
commit
1ff8ee74a1
26
provides.py
26
provides.py
@ -57,23 +57,27 @@ class BGPEndpoint(reactive.Endpoint):
|
||||
|
||||
return asn
|
||||
|
||||
def publish_info(self, asn=None, passive=False):
|
||||
def publish_info(self, asn=None, passive=False, bindings=None):
|
||||
"""
|
||||
Publish the AS Number and IP address of any extra-bindings of this
|
||||
BGP Endpoint over the relationship.
|
||||
|
||||
If no AS Number is provided a unique 32-bit Private Use [RFC6996] ASn
|
||||
will be generated.
|
||||
|
||||
:param asn: AS Number to publish. Autogenerated if not provided.
|
||||
:param passive: Advertise that we wish to be configured as passive
|
||||
neighbour.
|
||||
:param bindings: List bindings advertised as links to speak BGP on.
|
||||
"""
|
||||
if asn:
|
||||
myasn = asn
|
||||
else:
|
||||
myasn = self.generate_asn()
|
||||
|
||||
# network_get will return addresses for extra-bindings regardless of
|
||||
# extra-bindings being bound to a network space. detect actual space
|
||||
# bindings by comparing returned addresses to what we have for the
|
||||
# relation itself.
|
||||
# network_get will return addresses for bindings regardless of them
|
||||
# being bound to a network space. detect actual space bindings by
|
||||
# comparing returned addresses to what we have for the relation itself.
|
||||
for relation in self.relations:
|
||||
rel_network = ch_core.hookenv.network_get(
|
||||
self.expand_name('{endpoint_name}'),
|
||||
@ -81,8 +85,8 @@ class BGPEndpoint(reactive.Endpoint):
|
||||
rel_addrs = [a['address']
|
||||
for a in
|
||||
rel_network['bind-addresses'][0]['addresses']]
|
||||
extra_bindings = []
|
||||
for binding in ch_core.hookenv.metadata()['extra-bindings']:
|
||||
actual_bindings = []
|
||||
for binding in bindings:
|
||||
bind_network = ch_core.hookenv.network_get(
|
||||
binding,
|
||||
relation_id=relation.relation_id)
|
||||
@ -90,10 +94,10 @@ class BGPEndpoint(reactive.Endpoint):
|
||||
for a in
|
||||
bind_network['bind-addresses'][0]['addresses']]
|
||||
if not set(bind_addrs).issubset(set(rel_addrs)):
|
||||
extra_bindings.extend(
|
||||
actual_bindings.extend(
|
||||
bind_network['bind-addresses'][0]['addresses'])
|
||||
relation.to_publish['asn'] = myasn
|
||||
relation.to_publish['extra_bindings'] = extra_bindings
|
||||
relation.to_publish['bindings'] = actual_bindings
|
||||
relation.to_publish['passive'] = passive
|
||||
ch_core.hookenv.log("to_publish: '{}'".format(relation.to_publish))
|
||||
|
||||
@ -102,13 +106,13 @@ class BGPEndpoint(reactive.Endpoint):
|
||||
for relation in self.relations:
|
||||
for unit in relation.units:
|
||||
if not ('asn' in unit.received and
|
||||
'extra_bindings' in unit.received):
|
||||
'bindings' in unit.received):
|
||||
ch_core.hookenv.log('Skip get_received_info() '
|
||||
'relation incomplete...',
|
||||
level=ch_core.hookenv.DEBUG)
|
||||
continue
|
||||
links = []
|
||||
for addrinfo in unit.received['extra_bindings']:
|
||||
for addrinfo in unit.received['bindings']:
|
||||
# filter list of networks to those we have interfaces
|
||||
# configured for
|
||||
ip = ch_net_ip.get_address_in_network(addrinfo['cidr'])
|
||||
|
Loading…
Reference in New Issue
Block a user