Merge pull request #2 from openstack-charmers/make_bindings_optional

Make publishing of links from bindings charm controlled
This commit is contained in:
David Ames 2018-02-12 16:12:53 -08:00 committed by GitHub
commit 1ff8ee74a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,23 +57,27 @@ class BGPEndpoint(reactive.Endpoint):
return asn 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 Publish the AS Number and IP address of any extra-bindings of this
BGP Endpoint over the relationship. BGP Endpoint over the relationship.
If no AS Number is provided a unique 32-bit Private Use [RFC6996] ASn If no AS Number is provided a unique 32-bit Private Use [RFC6996] ASn
will be generated. 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: if asn:
myasn = asn myasn = asn
else: else:
myasn = self.generate_asn() myasn = self.generate_asn()
# network_get will return addresses for extra-bindings regardless of # network_get will return addresses for bindings regardless of them
# extra-bindings being bound to a network space. detect actual space # being bound to a network space. detect actual space bindings by
# bindings by comparing returned addresses to what we have for the # comparing returned addresses to what we have for the relation itself.
# relation itself.
for relation in self.relations: for relation in self.relations:
rel_network = ch_core.hookenv.network_get( rel_network = ch_core.hookenv.network_get(
self.expand_name('{endpoint_name}'), self.expand_name('{endpoint_name}'),
@ -81,8 +85,8 @@ class BGPEndpoint(reactive.Endpoint):
rel_addrs = [a['address'] rel_addrs = [a['address']
for a in for a in
rel_network['bind-addresses'][0]['addresses']] rel_network['bind-addresses'][0]['addresses']]
extra_bindings = [] actual_bindings = []
for binding in ch_core.hookenv.metadata()['extra-bindings']: for binding in bindings:
bind_network = ch_core.hookenv.network_get( bind_network = ch_core.hookenv.network_get(
binding, binding,
relation_id=relation.relation_id) relation_id=relation.relation_id)
@ -90,10 +94,10 @@ class BGPEndpoint(reactive.Endpoint):
for a in for a in
bind_network['bind-addresses'][0]['addresses']] bind_network['bind-addresses'][0]['addresses']]
if not set(bind_addrs).issubset(set(rel_addrs)): if not set(bind_addrs).issubset(set(rel_addrs)):
extra_bindings.extend( actual_bindings.extend(
bind_network['bind-addresses'][0]['addresses']) bind_network['bind-addresses'][0]['addresses'])
relation.to_publish['asn'] = myasn relation.to_publish['asn'] = myasn
relation.to_publish['extra_bindings'] = extra_bindings relation.to_publish['bindings'] = actual_bindings
relation.to_publish['passive'] = passive relation.to_publish['passive'] = passive
ch_core.hookenv.log("to_publish: '{}'".format(relation.to_publish)) ch_core.hookenv.log("to_publish: '{}'".format(relation.to_publish))
@ -102,13 +106,13 @@ class BGPEndpoint(reactive.Endpoint):
for relation in self.relations: for relation in self.relations:
for unit in relation.units: for unit in relation.units:
if not ('asn' in unit.received and if not ('asn' in unit.received and
'extra_bindings' in unit.received): 'bindings' in unit.received):
ch_core.hookenv.log('Skip get_received_info() ' ch_core.hookenv.log('Skip get_received_info() '
'relation incomplete...', 'relation incomplete...',
level=ch_core.hookenv.DEBUG) level=ch_core.hookenv.DEBUG)
continue continue
links = [] links = []
for addrinfo in unit.received['extra_bindings']: for addrinfo in unit.received['bindings']:
# filter list of networks to those we have interfaces # filter list of networks to those we have interfaces
# configured for # configured for
ip = ch_net_ip.get_address_in_network(addrinfo['cidr']) ip = ch_net_ip.get_address_in_network(addrinfo['cidr'])