def get_router_assoc(self, context, assoc_id, bgpvpn_id, fields=None): try: bgpvpn_obj = self._vnc_api.bgpvpn_read( id=bgpvpn_id, fields=['logical_router_back_refs']) except vnc_exc.NoIdError: raise bgpvpn_ext.BGPVPNNotFound(id=bgpvpn_id) associated_routers = [ lr_ref['uuid'] for lr_ref in bgpvpn_obj.get_logical_router_back_refs() or [] ] if assoc_id not in associated_routers: raise bgpvpn_ext.BGPVPNRouterAssocNotFound(id=assoc_id, bgpvpn_id=bgpvpn_id) return bgpvpn_utils.make_router_assoc_dict( assoc_id, bgpvpn_obj.parent_uuid.replace('-', ''), bgpvpn_id, assoc_id)
def get_router_assocs(self, context, bgpvpn_id, filters=None, fields=None): try: bgpvpn_obj = self._vnc_api.bgpvpn_read( id=bgpvpn_id, fields=['logical_router_back_refs']) except vnc_exc.NoIdError: raise bgpvpn_ext.BGPVPNNotFound(id=bgpvpn_id) bgpvpn_router_assocs = [] for lr_ref in bgpvpn_obj.get_logical_router_back_refs() or []: bgpvpn_router_assoc = bgpvpn_utils.make_router_assoc_dict( lr_ref['uuid'], bgpvpn_obj.parent_uuid.replace('-', ''), bgpvpn_id, lr_ref['uuid'], fields, ) if bgpvpn_utils.filter_resource(bgpvpn_router_assoc, filters): bgpvpn_router_assocs.append(bgpvpn_router_assoc) return bgpvpn_router_assocs
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)