def find_bgpvpns_for_router(self, context, router_id): try: lr_obj = self._vnc_api.logical_router_read(id=router_id, fields=['bgpvpn_refs']) except vnc_exc.NoIdError: raise neutron_l3_ext.RouterNotFound(router_id=router_id) bgpvpn_ids = [ bgpvpn_ref['uuid'] for bgpvpn_ref in lr_obj.get_bgpvpn_refs() or [] ] bgpvpns = [] for bgpvpn_obj in self._vnc_api.bgpvpns_list(obj_uuids=bgpvpn_ids, detail=True): bgpvpns.append(self._bgpvpn_to_neutron_dict(bgpvpn_obj)) return bgpvpns
def _create_ha_port_binding(self, context, router_id, port_id): try: with context.session.begin(): portbinding = L3HARouterAgentPortBinding(port_id=port_id, router_id=router_id) context.session.add(portbinding) return portbinding except db_exc.DBReferenceError as e: with excutils.save_and_reraise_exception() as ctxt: if isinstance(e.inner_exception, sql_exc.IntegrityError): ctxt.reraise = False LOG.debug( 'Failed to create HA router agent PortBinding, ' 'Router %s has already been removed ' 'by concurrent operation', router_id) raise l3.RouterNotFound(router_id=router_id)
def delete_router_assoc(self, context, assoc_id, bgpvpn_id): try: bgpvpn_obj = self._vnc_api.bgpvpn_read(id=bgpvpn_id) except vnc_exc.NoIdError: raise bgpvpn_ext.BGPVPNNotFound(id=bgpvpn_id) try: lr_obj = self._vnc_api.logical_router_read(id=assoc_id) except vnc_exc.NoIdError: raise neutron_l3_ext.RouterNotFound(router_id=assoc_id) lr_obj.del_bgpvpn(bgpvpn_obj) try: self._vnc_api.logical_router_update(lr_obj) except vnc_exc.BadRequest as exc: raise neutron_exc.BadRequest(resource='router_association', msg=str(exc)) return bgpvpn_utils.make_router_assoc_dict( assoc_id, bgpvpn_obj.parent_uuid.replace('-', ''), bgpvpn_id, assoc_id, )
def create_router_assoc(self, context, bgpvpn_id, router_association): try: bgpvpn_obj = self._vnc_api.bgpvpn_read(id=bgpvpn_id) except vnc_exc.NoIdError: raise bgpvpn_ext.BGPVPNNotFound(id=bgpvpn_id) router_id = router_association['router_id'] try: lr_obj = self._vnc_api.logical_router_read(id=router_id) except vnc_exc.NoIdError: raise neutron_l3_ext.RouterNotFound(router_id=router_id) lr_obj.add_bgpvpn(bgpvpn_obj) try: self._vnc_api.logical_router_update(lr_obj) except vnc_exc.BadRequest as exc: raise neutron_exc.BadRequest(resource='router_association', msg=str(exc)) # Use the router ID as association id router_association['id'] = router_id router_association['bgpvpn_id'] = bgpvpn_id router_association.pop('project_id', None) return bgpvpn_utils.make_router_assoc_dict(**router_association)
def _get_router(self, context, id): try: router = self._get_by_id(context, Router, id) except exc.NoResultFound: raise l3.RouterNotFound(router_id=id) return router