Skip to content

Commit

Permalink
BGPaaS - vmi primary ip address is used as BGPaaS object if not confi…
Browse files Browse the repository at this point in the history
…gured.

Read and initalize Bgpaas objects when ST is reinited.

Change-Id: I3f0a4da86d708464de7d0b4ba41ae6e7a5faabb8
Closes-Bug: #1538322
Closes-Bug: #1538318
Closes-Bug: #1536339
Closes-Bug: #1540540
  • Loading branch information
sbalineni committed Feb 2, 2016
1 parent 6caa96c commit d239035
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
37 changes: 32 additions & 5 deletions src/config/schema-transformer/config_db.py
Expand Up @@ -2745,8 +2745,11 @@ def evaluate(self):
self._vnc_lib.bgp_as_a_service_update(bgpaas.obj)
except NoIdError:
pass
self._vnc_lib.bgp_router_delete(id=self.obj.uuid)
self.delete(self.name)
try:
self._vnc_lib.bgp_router_delete(id=self.obj.uuid)
self.delete(self.name)
except RefsExistError:
pass
elif ret:
self._vnc_lib.bgp_router_update(self.obj)
elif self.router_type != 'bgpaas-server':
Expand Down Expand Up @@ -2775,7 +2778,7 @@ def update_bgpaas_client(self, bgpaas):
update = False
params = self.obj.get_bgp_router_parameters()
if self.asn != bgpaas.asn:
params.autonomous_system = bgpaas.asn
params.autonomous_system = int(bgpaas.asn)
self.asn = bgpaas.asn
update = True
if params.address != bgpaas.ip_address:
Expand All @@ -2784,6 +2787,8 @@ def update_bgpaas_client(self, bgpaas):
if params.identifier != bgpaas.ip_address:
params.identifier = bgpaas.ip_address
update = True
if update:
self.obj.set_bgp_router_parameters(params)
router_refs = self.obj.get_bgp_router_refs()
peering_attribs = router_refs[0]['attr']
if peering_attribs != bgpaas.peering_attribs:
Expand All @@ -2796,6 +2801,8 @@ def update_bgpaas_client(self, bgpaas):
def update_peering(self):
if not GlobalSystemConfigST.get_ibgp_auto_mesh():
return
if self.router_type in ('bgpaas-server', 'bgpaas-client'):
return
global_asn = int(GlobalSystemConfigST.get_autonomous_system())
if self.asn != global_asn:
return
Expand All @@ -2810,6 +2817,9 @@ def update_peering(self):
for router in self._dict.values():
if router.name == self.name:
continue
if not self.router_type:
if router.router_type in ('bgpaas-server', 'bgpaas-client'):
continue
if router.asn != global_asn:
continue
router_fq_name = router.name.split(':')
Expand Down Expand Up @@ -2906,10 +2916,11 @@ def create_bgp_router(self, name):
else:
server_router = server_router.obj
bgp_router = BgpRouter(vmi.obj.name, parent_obj=ri.obj)
ip = self.ip_address or vmi.get_primary_instance_ip_address()
params = BgpRouterParams(
autonomous_system=int(self.asn) if self.asn else None,
address=self.ip_address,
identifier=self.ip_address,
address=ip,
identifier=ip,
source_port=self._cassandra.alloc_bgpaas_port(router_fq_name),
router_type='bgpaas-client')
bgp_router.set_bgp_router_parameters(params)
Expand Down Expand Up @@ -3006,6 +3017,16 @@ def get_any_instance_ip_address(self, ip_version=0):
return None
# end get_any_instance_ip_address

def get_primary_instance_ip_address(self):
for ip_name in self.instance_ips:
ip = InstanceIpST.get(ip_name)
if ip.address is None:
continue
if ip.is_primary():
return ip.address
return None
# end get_primary_instance_ip_address

def set_properties(self):
props = self.obj.get_virtual_machine_interface_properties()
if props:
Expand Down Expand Up @@ -3223,6 +3244,7 @@ class InstanceIpST(DBBaseST):

def __init__(self, name, obj=None):
self.name = name
self.is_secondary = False
self.virtual_machine_interfaces = set()
self.update(obj)
# end __init
Expand All @@ -3231,9 +3253,14 @@ def update(self, obj=None):
self.obj = obj or self.read_vnc_obj(fq_name=self.name)
self.address = self.obj.get_instance_ip_address()
self.service_instance_ip = self.obj.get_service_instance_ip()
self.is_secondary = self.obj.get_instance_ip_secondary() or False
self.update_multiple_refs('virtual_machine_interface', self.obj)
# end update

def is_primary(self):
return not self.is_secondary
#end

def delete_obj(self):
self.update_multiple_refs('virtual_machine_interface', {})

Expand Down
4 changes: 3 additions & 1 deletion src/config/schema-transformer/to_bgp.py
Expand Up @@ -70,7 +70,7 @@ class SchemaTransformer(object):
'virtual_network': ['virtual_machine', 'port_tuple',
'bgp_as_a_service'],
'logical_router': ['virtual_network'],
'instance_ip': ['virtual_machine', 'port_tuple'],
'instance_ip': ['virtual_machine', 'port_tuple', 'bgp_as_a_service'],
'floating_ip': ['virtual_machine', 'port_tuple'],
'virtual_machine': [],
'port_tuple': [],
Expand Down Expand Up @@ -465,6 +465,8 @@ def reinit(self):
gevent.sleep(0.001)
for pt in PortTupleST.list_vnc_obj():
PortTupleST.locate(pt.get_fq_name_str(), pt)
for bgpass in BgpAsAServiceST.list_vnc_obj():
BgpAsAServiceST.locate(bgpass.get_fq_name_str(), bgpass)
for cls in DBBaseST.get_obj_type_map().values():
for obj in cls.values():
obj.evaluate()
Expand Down

0 comments on commit d239035

Please sign in to comment.