Exemple #1
0
 def create_flow_classifier(self, context, flow_classifier):
     fc = flow_classifier['flow_classifier']
     project_id = fc['project_id']
     l7_parameters = {
         key: L7Parameter(key, val)
         for key, val in fc['l7_parameters'].items()}
     ethertype = fc['ethertype']
     protocol = fc['protocol']
     source_port_range_min = fc['source_port_range_min']
     source_port_range_max = fc['source_port_range_max']
     self._check_port_range_valid(source_port_range_min,
                                  source_port_range_max,
                                  protocol)
     destination_port_range_min = fc['destination_port_range_min']
     destination_port_range_max = fc['destination_port_range_max']
     self._check_port_range_valid(destination_port_range_min,
                                  destination_port_range_max,
                                  protocol)
     source_ip_prefix = fc['source_ip_prefix']
     self._check_ip_prefix_valid(source_ip_prefix, ethertype)
     destination_ip_prefix = fc['destination_ip_prefix']
     self._check_ip_prefix_valid(destination_ip_prefix, ethertype)
     logical_source_port = fc['logical_source_port']
     logical_destination_port = fc['logical_destination_port']
     with context.session.begin(subtransactions=True):
         if logical_source_port is not None:
             self._get_port(context, logical_source_port)
         if logical_destination_port is not None:
             self._get_port(context, logical_destination_port)
         query = self._model_query(context, FlowClassifier)
         for flow_classifier_db in query.all():
             if self.flowclassifier_conflict(
                 fc,
                 flow_classifier_db
             ):
                 raise fc_ext.FlowClassifierInConflict(
                     id=flow_classifier_db['id']
                 )
         flow_classifier_db = FlowClassifier(
             id=uuidutils.generate_uuid(),
             project_id=project_id,
             name=fc['name'],
             description=fc['description'],
             ethertype=ethertype,
             protocol=protocol,
             source_port_range_min=source_port_range_min,
             source_port_range_max=source_port_range_max,
             destination_port_range_min=destination_port_range_min,
             destination_port_range_max=destination_port_range_max,
             source_ip_prefix=source_ip_prefix,
             destination_ip_prefix=destination_ip_prefix,
             logical_source_port=logical_source_port,
             logical_destination_port=logical_destination_port,
             l7_parameters=l7_parameters
         )
         context.session.add(flow_classifier_db)
         return self._make_flow_classifier_dict(flow_classifier_db)
Exemple #2
0
 def create_flow_classifier(self, context, flow_classifier):
     fc = flow_classifier['flow_classifier']
     project_id = fc['project_id']
     l7_parameters = {
         # Overriding the method due to change of below line only
         key: flowclassifier_db.L7Parameter(keyword=key, value=val)
         for key, val in six.iteritems(fc['l7_parameters'])
     }
     ethertype = fc['ethertype']
     protocol = fc['protocol']
     source_port_range_min = fc['source_port_range_min']
     source_port_range_max = fc['source_port_range_max']
     self._check_port_range_valid(source_port_range_min,
                                  source_port_range_max, protocol)
     destination_port_range_min = fc['destination_port_range_min']
     destination_port_range_max = fc['destination_port_range_max']
     self._check_port_range_valid(destination_port_range_min,
                                  destination_port_range_max, protocol)
     source_ip_prefix = fc['source_ip_prefix']
     self._check_ip_prefix_valid(source_ip_prefix, ethertype)
     destination_ip_prefix = fc['destination_ip_prefix']
     self._check_ip_prefix_valid(destination_ip_prefix, ethertype)
     logical_source_port = fc['logical_source_port']
     logical_destination_port = fc['logical_destination_port']
     with db_api.CONTEXT_WRITER.using(context):
         if logical_source_port is not None:
             self._get_port(context, logical_source_port)
         if logical_destination_port is not None:
             self._get_port(context, logical_destination_port)
         query = flowclassifier_db.model_query.query_with_hooks(
             context, flowclassifier_db.FlowClassifier)
         for flow_classifier_db in query.all():
             if self.flowclassifier_conflict(fc, flow_classifier_db):
                 raise fc_ext.FlowClassifierInConflict(
                     id=flow_classifier_db['id'])
         flow_classifier_db = flowclassifier_db.FlowClassifier(
             id=uuidutils.generate_uuid(),
             project_id=project_id,
             name=fc['name'],
             description=fc['description'],
             ethertype=ethertype,
             protocol=protocol,
             source_port_range_min=source_port_range_min,
             source_port_range_max=source_port_range_max,
             destination_port_range_min=destination_port_range_min,
             destination_port_range_max=destination_port_range_max,
             source_ip_prefix=source_ip_prefix,
             destination_ip_prefix=destination_ip_prefix,
             logical_source_port=logical_source_port,
             logical_destination_port=logical_destination_port,
             l7_parameters=l7_parameters)
         context.session.add(flow_classifier_db)
         return self._make_flow_classifier_dict(flow_classifier_db)