def update_bgpvpn(self, context, id, new_bgpvpn):
        LOG.debug("update_bgpvpn called with %s for %s" % (new_bgpvpn, id))

        fields = None
        oc_client = self._get_opencontrail_api_client(context)
        new_bgpvpn = new_bgpvpn["bgpvpn"]

        old_bgpvpn = self.get_bgpvpn(context, id)
        bgpvpn = old_bgpvpn.copy()
        bgpvpn.update(new_bgpvpn)

        (added_keys, removed_keys, changed_keys) = utils.get_bgpvpn_differences(bgpvpn, old_bgpvpn)
        if not (added_keys or removed_keys or changed_keys):
            return utils.make_bgpvpn_dict(bgpvpn, fields)

        rt_keys = set(["route_targets", "import_targets", "export_targets"])

        if "networks" in changed_keys:
            removed_networks = list(set(old_bgpvpn.get("networks", [])) - set(bgpvpn.get("networks", [])))
            added_networks = list(set(bgpvpn.get("networks", [])) - set(old_bgpvpn.get("networks", [])))

            for network_id in removed_networks:
                self._set_bgpvpn_association(oc_client, "DELETE", old_bgpvpn, network_id)
            for network_id in added_networks:
                self._set_bgpvpn_association(oc_client, "ADD", bgpvpn, network_id)
        elif rt_keys & added_keys or rt_keys & changed_keys or rt_keys & removed_keys:
            self._set_bgpvpn_association(oc_client, "DELETE", old_bgpvpn)
            self._set_bgpvpn_association(oc_client, "ADD", bgpvpn)

        oc_client.kv_store("STORE", key=id, value={"bgpvpn": bgpvpn})
        return utils.make_bgpvpn_dict(bgpvpn, fields)
Exemplo n.º 2
0
    def update_bgpvpn(self, context, id, new_bgpvpn):
        LOG.debug("update_bgpvpn called with %s for %s" % (new_bgpvpn, id))

        oc_client = self._get_opencontrail_api_client(context)

        old_bgpvpn = self.get_bgpvpn(context, id)
        networks = old_bgpvpn.get('networks', [])
        bgpvpn = old_bgpvpn.copy()
        bgpvpn.update(new_bgpvpn)

        (added_keys, removed_keys, changed_keys) = \
            utils.get_bgpvpn_differences(bgpvpn, old_bgpvpn)
        if not (added_keys or removed_keys or changed_keys):
            return utils.make_bgpvpn_dict(bgpvpn)

        # Does not support to update route distinguisher
        if 'route_distinguishers' in added_keys | removed_keys | changed_keys:
            raise bgpvpn_ext.BGPVPNRDNotSupported(
                driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME)

        rt_keys = set(['route_targets',
                       'import_targets',
                       'export_targets'])

        if (rt_keys & added_keys or
                rt_keys & changed_keys or
                rt_keys & removed_keys):
            self._set_bgpvpn_association(oc_client, 'DELETE', old_bgpvpn,
                                         networks)
            self._set_bgpvpn_association(oc_client, 'ADD', bgpvpn, networks)

        oc_client.kv_store('STORE', key=id, value={'bgpvpn': bgpvpn})
        return utils.make_bgpvpn_dict(bgpvpn)
Exemplo n.º 3
0
    def update_bgpvpn(self, context, id, new_bgpvpn):
        LOG.debug("update_bgpvpn called with %s for %s" % (new_bgpvpn, id))

        oc_client = self._get_opencontrail_api_client(context)

        old_bgpvpn = self.get_bgpvpn(context, id)
        networks = old_bgpvpn.get('networks', [])
        bgpvpn = old_bgpvpn.copy()
        bgpvpn.update(new_bgpvpn)

        (added_keys, removed_keys, changed_keys) = \
            utils.get_bgpvpn_differences(bgpvpn, old_bgpvpn)
        if not (added_keys or removed_keys or changed_keys):
            return utils.make_bgpvpn_dict(bgpvpn)

        # Does not support to update route distinguisher
        if 'route_distinguishers' in added_keys | removed_keys | changed_keys:
            raise bgpvpn_ext.BGPVPNRDNotSupported(
                driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME)

        rt_keys = set(['route_targets', 'import_targets', 'export_targets'])

        if (rt_keys & added_keys or rt_keys & changed_keys
                or rt_keys & removed_keys):
            self._set_bgpvpn_association(oc_client, 'DELETE', old_bgpvpn,
                                         networks)
            self._set_bgpvpn_association(oc_client, 'ADD', bgpvpn, networks)

        oc_client.kv_store('STORE', key=id, value={'bgpvpn': bgpvpn})
        return utils.make_bgpvpn_dict(bgpvpn)
    def create_bgpvpn(self, context, bgpvpn):
        bgpvpn = bgpvpn["bgpvpn"]

        LOG.debug("create_bgpvpn_ called with %s" % bgpvpn)

        # Check that route_targets is not empty
        if not bgpvpn["route_targets"]:
            raise bgpvpn_ext.BGPVPNMissingRouteTarget

        # Only support l3 technique
        if not bgpvpn["type"]:
            bgpvpn["type"] = constants.BGPVPN_L3
        elif bgpvpn["type"] != constants.BGPVPN_L3:
            raise bgpvpn_ext.BGPVPNTypeNotSupported(driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME, type=bgpvpn["type"])

        # Does not support to set route distinguisher
        if "route_distinguishers" in bgpvpn and bgpvpn["route_distinguishers"]:
            raise bgpvpn_ext.BGPVPNRDNotSupported(driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME)

        oc_client = self._get_opencontrail_api_client(context)

        tenant_id = self._get_tenant_id_for_create(context, bgpvpn)
        bgpvpn["tenant_id"] = tenant_id
        bgpvpn["id"] = uuidutils.generate_uuid()
        bgpvpn["networks"] = []

        oc_client.kv_store("STORE", key=bgpvpn["id"], value={"bgpvpn": bgpvpn})

        return utils.make_bgpvpn_dict(bgpvpn)
Exemplo n.º 5
0
    def create_bgpvpn(self, context, bgpvpn):
        LOG.debug("create_bgpvpn_ called with %s" % bgpvpn)

        # Only support l3 technique
        if not bgpvpn['type']:
            bgpvpn['type'] = constants.BGPVPN_L3
        elif bgpvpn['type'] != constants.BGPVPN_L3:
            raise bgpvpn_ext.BGPVPNTypeNotSupported(
                driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME, type=bgpvpn['type'])

        # Does not support to set route distinguisher
        if 'route_distinguishers' in bgpvpn and bgpvpn['route_distinguishers']:
            raise bgpvpn_ext.BGPVPNRDNotSupported(
                driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME)

        oc_client = self._get_opencontrail_api_client(context)

        # Check if tenant ID exists;
        # if not, it sends an exception
        self._check_tenant_id(oc_client, bgpvpn['tenant_id'])

        bgpvpn['id'] = uuidutils.generate_uuid()

        oc_client.kv_store('STORE', key=bgpvpn['id'], value={'bgpvpn': bgpvpn})

        return utils.make_bgpvpn_dict(bgpvpn)
Exemplo n.º 6
0
 def _bgpvpn_to_neutron_dict(self, bgpvpn_obj, fields=None):
     bgpvpn_dict = {
         'id':
         bgpvpn_obj.uuid,
         'tenant_id':
         self._project_id_vnc_to_neutron(bgpvpn_obj.parent_uuid),
         'name':
         bgpvpn_obj.display_name,
         'type':
         bgpvpn_obj.bgpvpn_type,
         'route_targets':
         self._get_route_target_list(bgpvpn_obj.get_route_target_list()),
         'import_targets':
         self._get_route_target_list(
             bgpvpn_obj.get_import_route_target_list()),
         'export_targets':
         self._get_route_target_list(
             bgpvpn_obj.get_export_route_target_list()),
         'route_distinguishers': [],
         'networks':
         self._get_refs(bgpvpn_obj.get_virtual_network_back_refs()),
         'routers':
         self._get_refs(bgpvpn_obj.get_logical_router_back_refs()),
     }
     return bgpvpn_utils.make_bgpvpn_dict(bgpvpn_dict, fields=fields)
    def create_bgpvpn(self, context, bgpvpn):
        LOG.debug("create_bgpvpn_ called with %s" % bgpvpn)

        # Only support l3 technique
        if not bgpvpn['type']:
            bgpvpn['type'] = constants.BGPVPN_L3
        elif bgpvpn['type'] != constants.BGPVPN_L3:
            raise bgpvpn_ext.BGPVPNTypeNotSupported(
                driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME, type=bgpvpn['type'])

        # Does not support to set route distinguisher
        if 'route_distinguishers' in bgpvpn and bgpvpn['route_distinguishers']:
            raise bgpvpn_ext.BGPVPNRDNotSupported(
                driver=OPENCONTRAIL_BGPVPN_DRIVER_NAME)

        oc_client = self._get_opencontrail_api_client(context)

        # Check if tenant ID exists;
        # if not, it sends an exception
        self._check_tenant_id(oc_client, bgpvpn['tenant_id'])

        bgpvpn['id'] = uuidutils.generate_uuid()

        oc_client.kv_store('STORE', key=bgpvpn['id'], value={'bgpvpn': bgpvpn})

        return utils.make_bgpvpn_dict(bgpvpn)
    def get_bgpvpns(self, context, filters=None, fields=None):
        LOG.debug("get_bgpvpns called, fields = %s, filters = %s" % (fields, filters))

        oc_client = self._get_opencontrail_api_client(context)

        bgpvpns = []
        for kv_dict in oc_client.kv_store("RETRIEVE"):
            try:
                value = json.loads(kv_dict["value"])
            except ValueError:
                continue
            if isinstance(value, dict) and "bgpvpn" in value and utils.filter_resource(value["bgpvpn"], filters):
                bgpvpns.append(utils.make_bgpvpn_dict(value["bgpvpn"], fields))

        if not context.is_admin:
            return [bgpvpn for bgpvpn in bgpvpns if bgpvpn["tenant_id"] == context.tenant_id]

        return bgpvpns
Exemplo n.º 9
0
    def get_bgpvpn(self, context, id, fields=None):
        LOG.debug("get_bgpvpn called for id %s with fields = %s"
                  % (id, fields))

        oc_client = self._get_opencontrail_api_client(context)

        try:
            bgpvpn = json.loads(oc_client.kv_store('RETRIEVE', key=id))
        except (oc_exc.OpenContrailAPINotFound, ValueError):
            raise bgpvpn.BGPVPNNotFound(id=id)

        if (not isinstance(bgpvpn, dict) or 'bgpvpn' not in bgpvpn):
            raise bgpvpn.BGPVPNNotFound(id=id)

        bgpvpn = bgpvpn['bgpvpn']
        if not fields or 'networks' in fields:
            bgpvpn['networks'] = [net_assoc['network_id'] for net_assoc in
                                  self.get_net_assocs(context, id)]
        return utils.make_bgpvpn_dict(bgpvpn, fields)
    def get_bgpvpn(self, context, id, fields=None):
        LOG.debug("get_bgpvpn called for id %s with fields = %s" % (id, fields))

        oc_client = self._get_opencontrail_api_client(context)

        try:
            bgpvpn = json.loads(oc_client.kv_store("RETRIEVE", key=id))
        except (oc_exc.OpenContrailAPINotFound, ValueError):
            raise bgpvpn.BGPVPNNotFound(id=id)

        if not isinstance(bgpvpn, dict) or "bgpvpn" not in bgpvpn:
            raise bgpvpn.BGPVPNNotFound(id=id)

        bgpvpn = bgpvpn["bgpvpn"]
        if not context.is_admin:
            if bgpvpn["tenant_id"] != context.tenant_id:
                raise bgpvpn_ext.BGPVPNNotFound(id=id)

        return utils.make_bgpvpn_dict(bgpvpn, fields)
Exemplo n.º 11
0
    def get_bgpvpn(self, context, id, fields=None):
        LOG.debug("get_bgpvpn called for id %s with fields = %s"
                  % (id, fields))

        oc_client = self._get_opencontrail_api_client(context)

        try:
            bgpvpn = json.loads(oc_client.kv_store('RETRIEVE', key=id))
        except (oc_exc.OpenContrailAPINotFound, ValueError):
            raise bgpvpn.BGPVPNNotFound(id=id)

        if (not isinstance(bgpvpn, dict) or 'bgpvpn' not in bgpvpn):
            raise bgpvpn.BGPVPNNotFound(id=id)

        bgpvpn = bgpvpn['bgpvpn']
        if not fields or 'networks' in fields:
            bgpvpn['networks'] = [net_assoc['network_id'] for net_assoc in
                                  self.get_net_assocs(context, id)]
        return utils.make_bgpvpn_dict(bgpvpn, fields)
Exemplo n.º 12
0
    def get_bgpvpns(self, context, filters=None, fields=None):
        LOG.debug("get_bgpvpns called, fields = %s, filters = %s" %
                  (fields, filters))

        oc_client = self._get_opencontrail_api_client(context)

        bgpvpns = []
        for kv_dict in oc_client.kv_store('RETRIEVE'):
            try:
                value = json.loads(kv_dict['value'])
            except ValueError:
                continue
            if (isinstance(value, dict) and 'bgpvpn' in value
                    and utils.filter_resource(value['bgpvpn'], filters)):
                bgpvpn = value['bgpvpn']
                if not fields or 'networks' in fields:
                    bgpvpn['networks'] = \
                        [net_assoc['network_id'] for net_assoc in
                         self.get_net_assocs(context, bgpvpn['id'])]
                bgpvpns.append(utils.make_bgpvpn_dict(bgpvpn, fields))

        return bgpvpns
Exemplo n.º 13
0
    def get_bgpvpns(self, context, filters=None, fields=None):
        LOG.debug("get_bgpvpns called, fields = %s, filters = %s"
                  % (fields, filters))

        oc_client = self._get_opencontrail_api_client(context)

        bgpvpns = []
        for kv_dict in oc_client.kv_store('RETRIEVE'):
            try:
                value = json.loads(kv_dict['value'])
            except ValueError:
                continue
            if (isinstance(value, dict) and
                    'bgpvpn' in value and
                    utils.filter_resource(value['bgpvpn'], filters)):
                bgpvpn = value['bgpvpn']
                if not fields or 'networks' in fields:
                    bgpvpn['networks'] = \
                        [net_assoc['network_id'] for net_assoc in
                         self.get_net_assocs(context, bgpvpn['id'])]
                bgpvpns.append(utils.make_bgpvpn_dict(bgpvpn, fields))

        return bgpvpns