Example #1
0
    def create_port_pair(self, context, port_pair):
        """Create a port pair."""
        pp = port_pair['port_pair']
        tenant_id = pp['tenant_id']
        with context.session.begin(subtransactions=True):
            query = self._model_query(context, PortPair)
            pp_in_use = query.filter_by(ingress=pp['ingress'],
                                        egress=pp['egress']).first()
            if pp_in_use:
                raise ext_sfc.PortPairIngressEgressInUse(ingress=pp['ingress'],
                                                         egress=pp['egress'],
                                                         id=pp_in_use['id'])

            service_function_parameters = {
                key: ServiceFunctionParam(keyword=key, value=val)
                for key, val in six.iteritems(
                    pp['service_function_parameters'])
            }
            ingress = self._get_port(context, pp['ingress'])
            egress = self._get_port(context, pp['egress'])
            self._validate_port_pair_ingress_egress(ingress, egress)
            port_pair_db = PortPair(
                id=uuidutils.generate_uuid(),
                name=pp['name'],
                description=pp['description'],
                tenant_id=tenant_id,
                ingress=pp['ingress'],
                egress=pp['egress'],
                service_function_parameters=service_function_parameters)
            context.session.add(port_pair_db)
            return self._make_port_pair_dict(port_pair_db)
    def create_port_pair(self, context, port_pair):
        """Create a port pair."""
        pp = port_pair['port_pair']
        project_id = pp['project_id']
        with db_api.context_manager.writer.using(context):
            query = self._model_query(context, PortPair)
            pp_in_use = query.filter_by(ingress=pp['ingress'],
                                        egress=pp['egress']).first()
            if pp_in_use:
                raise ext_sfc.PortPairIngressEgressInUse(ingress=pp['ingress'],
                                                         egress=pp['egress'],
                                                         id=pp_in_use['id'])

            service_function_parameters = {
                key: ServiceFunctionParam(keyword=key,
                                          value=jsonutils.dumps(val))
                for key, val in pp['service_function_parameters'].items()
            }
            ingress = self._get_port(context, pp['ingress'])
            egress = self._get_port(context, pp['egress'])
            self._validate_port_pair_ingress_egress(ingress, egress)
            port_pair_db = PortPair(
                id=uuidutils.generate_uuid(),
                name=pp['name'],
                description=pp['description'],
                project_id=project_id,
                ingress=pp['ingress'],
                egress=pp['egress'],
                service_function_parameters=service_function_parameters)
            context.session.add(port_pair_db)
            return self._make_port_pair_dict(port_pair_db)