コード例 #1
0
    def get_net_assoc(self, context, assoc_id, bgpvpn_id, fields=None):
        LOG.debug(
            "get_net_assoc called for %s for BGPVPN %s, with fields = %s" %
            (assoc_id, bgpvpn_id, fields))

        oc_client = self._get_opencontrail_api_client(context)

        try:
            net_assoc = json.loads(oc_client.kv_store('RETRIEVE',
                                                      key=assoc_id))
        except (oc_exc.OpenContrailAPINotFound, ValueError):
            raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                    bgpvpn_id=bgpvpn_id)

        if (not isinstance(net_assoc, dict)
                or 'bgpvpn_net_assoc' not in net_assoc):
            raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                    bgpvpn_id=bgpvpn_id)
        net_assoc = net_assoc['bgpvpn_net_assoc']

        if net_assoc['bgpvpn_id'] != bgpvpn_id:
            raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                    bgpvpn_id=bgpvpn_id)

        # It the bgpvpn was deleted, the 'get_bgpvpn' will clean all related
        # associations and replaces BGPVPNNotFound by a BGPVPNNetAssocNotFound
        try:
            get_fields = [
                'tenant_id', 'route_targets', 'import_targets',
                'export_targets'
            ]
            bgpvpn = self.get_bgpvpn(context,
                                     net_assoc['bgpvpn_id'],
                                     fields=get_fields)
        except bgpvpn_ext.BGPVPNNotFound:
            raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                    bgpvpn_id=bgpvpn_id)

        # If the network was delete all bgpvpn related association should be
        # deleted also
        try:
            oc_client.id_to_fqname(net_assoc['network_id'])
        except oc_exc.OpenContrailAPINotFound:
            self._set_bgpvpn_association(oc_client, 'DELETE', bgpvpn,
                                         [net_assoc['network_id']])
            oc_client.kv_store('DELETE', key=assoc_id)
            raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                    bgpvpn_id=bgpvpn_id)

        net_assoc = utils.make_net_assoc_dict(net_assoc['id'],
                                              net_assoc['tenant_id'],
                                              net_assoc['bgpvpn_id'],
                                              net_assoc['network_id'], fields)
        return net_assoc
コード例 #2
0
 def _get_net_assoc(self, context, assoc_id, bgpvpn_id):
     try:
         query = model_query.query_with_hooks(context, BGPVPNNetAssociation)
         return query.filter(
             BGPVPNNetAssociation.id == assoc_id,
             BGPVPNNetAssociation.bgpvpn_id == bgpvpn_id).one()
     except exc.NoResultFound:
         raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                 bgpvpn_id=bgpvpn_id)
コード例 #3
0
 def get_net_assoc(self, context, assoc_id, bgpvpn_id, fields=None):
     try:
         bgpvpn_obj = self._vnc_api.bgpvpn_read(
             id=bgpvpn_id, fields=['virtual_network_back_refs'])
     except vnc_exc.NoIdError:
         raise bgpvpn_ext.BGPVPNNotFound(id=bgpvpn_id)
     associated_networks = [
         vn_ref['uuid']
         for vn_ref in bgpvpn_obj.get_virtual_network_back_refs() or []
     ]
     if assoc_id not in associated_networks:
         raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
                                                 bgpvpn_id=bgpvpn_id)
     return bgpvpn_utils.make_net_assoc_dict(
         assoc_id, bgpvpn_obj.parent_uuid.replace('-', ''), bgpvpn_id,
         assoc_id)