Пример #1
0
    def create_port_pair_group(self, context, port_pair_group):
        """Create a port pair group."""
        pg = port_pair_group['port_pair_group']
        project_id = pg['project_id']

        with db_api.context_manager.writer.using(context):
            portpairs_list = [self._get_port_pair(context, pp_id)
                              for pp_id in pg['port_pairs']]
            self._validate_pps_in_ppg(portpairs_list)
            if pg['tap_enabled'] and len(portpairs_list) > 1:
                raise ext_tap.MultiplePortPairsInTapPPGNotSupported()
            port_pair_group_parameters = {
                key: PortPairGroupParam(
                    keyword=key, value=jsonutils.dumps(val))
                for key, val in
                pg['port_pair_group_parameters'].items()
            }
            assigned_group_ids = {}
            query = context.session.query(PortPairGroup)
            for port_pair_group_db in query.all():
                assigned_group_ids[port_pair_group_db['group_id']] = (
                    port_pair_group_db['id']
                )
            group_id = 0
            available_group_id = 1
            while True:
                if available_group_id not in assigned_group_ids:
                    group_id = available_group_id
                    break
                available_group_id += 1
            port_pair_group_db = PortPairGroup(
                id=uuidutils.generate_uuid(),
                name=pg['name'],
                description=pg['description'],
                project_id=project_id,
                port_pairs=portpairs_list,
                port_pair_group_parameters=port_pair_group_parameters,
                group_id=group_id,
                tap_enabled=pg['tap_enabled']
            )
            context.session.add(port_pair_group_db)
            return self._make_port_pair_group_dict(port_pair_group_db)
Пример #2
0
    def update_port_pair_group(self, context, id, port_pair_group):
        new_pg = port_pair_group['port_pair_group']

        with db_api.context_manager.writer.using(context):
            portpairs_list = [self._get_port_pair(context, pp_id)
                              for pp_id in new_pg.get('port_pairs', [])]
            self._validate_pps_in_ppg(portpairs_list, id)
            old_pg = self._get_port_pair_group(context, id)
            if old_pg['tap_enabled'] and len(portpairs_list) > 1:
                raise ext_tap.MultiplePortPairsInTapPPGNotSupported()
            for k, v in new_pg.items():
                if k == 'port_pairs':
                    port_pairs = [
                        self._get_port_pair(context, pp_id)
                        for pp_id in v
                    ]
                    old_pg.port_pairs = port_pairs
                else:
                    old_pg[k] = v

            return self._make_port_pair_group_dict(old_pg)