예제 #1
0
    def _validate_flow_classifiers(self, context, fc_ids, pc_id=None):
        with db_api.context_manager.reader.using(context):
            fcs = [
                self._get_flow_classifier(context, fc_id)
                for fc_id in fc_ids
            ]
            for fc in fcs:
                fc_assoc = fc.chain_classifier_association
                if fc_assoc and fc_assoc['portchain_id'] != pc_id:
                    raise ext_fc.FlowClassifierInUse(id=fc.id)

            query = self._model_query(context, PortChain)
            for port_chain_db in query.all():
                if port_chain_db['id'] == pc_id:
                    continue
                pc_fc_ids = [
                    assoc['flowclassifier_id']
                    for assoc in port_chain_db.chain_classifier_associations
                ]
                pc_fcs = [
                    self._get_flow_classifier(context, pc_fc_id)
                    for pc_fc_id in pc_fc_ids
                ]
                for pc_fc in pc_fcs:
                    for fc in fcs:
                        fc_cls = fc_db.FlowClassifierDbPlugin
                        if fc_cls.flowclassifier_basic_conflict(
                            pc_fc, fc
                        ):
                            raise ext_sfc.PortChainFlowClassifierInConflict(
                                fc_id=fc['id'], pc_id=port_chain_db['id'],
                                pc_fc_id=pc_fc['id']
                            )
예제 #2
0
    def create_port_chain(self, context, port_chain):
        """Create a port chain."""
        pc = port_chain['port_chain']
        tenant_id = self._get_tenant_id_for_create(context, pc)
        with context.session.begin(subtransactions=True):
            chain_parameters = {
                key: ChainParameter(keyword=key, value=val)
                for key, val in six.iteritems(pc['chain_parameters'])
            }

            pg_ids = pc['port_pair_groups']
            for pg_id in pg_ids:
                self._get_port_pair_group(context, pg_id)
            fc_ids = pc['flow_classifiers']
            fcs = [
                self._get_flow_classifier(context, fc_id) for fc_id in fc_ids
            ]
            for fc in fcs:
                if fc.chain_classifier_associations:
                    raise ext_fc.FlowClassifierInUse(id=fc.id)

            self._validate_port_pair_groups(context, pg_ids)
            self._validate_flow_classifiers(context, fc_ids)
            port_chain_db = PortChain(id=uuidutils.generate_uuid(),
                                      tenant_id=tenant_id,
                                      description=pc['description'],
                                      name=pc['name'],
                                      chain_parameters=chain_parameters)
            self._setup_chain_group_associations(context, port_chain_db,
                                                 pg_ids)
            self._setup_chain_classifier_associations(context, port_chain_db,
                                                      fc_ids)
            context.session.add(port_chain_db)

            return self._make_port_chain_dict(port_chain_db)
예제 #3
0
 def delete_flow_classifier(self, context, id):
     try:
         with context.session.begin(subtransactions=True):
             fc = self._get_flow_classifier(context, id)
             context.session.delete(fc)
     except AssertionError:
         raise fc_ext.FlowClassifierInUse(id=id)
     except fc_ext.FlowClassifierNotFound:
         LOG.info(_LI("Deleting a non-existing flow classifier."))
예제 #4
0
 def delete_flow_classifier(self, context, id):
     try:
         with db_api.context_manager.writer.using(context):
             fc = self._get_flow_classifier(context, id)
             context.session.delete(fc)
     except AssertionError:
         raise fc_ext.FlowClassifierInUse(id=id)
     except fc_ext.FlowClassifierNotFound:
         LOG.info("Deleting a non-existing flow classifier.")