def update_port_pair_group(self, context, id, port_pair_group): new_pg = port_pair_group['port_pair_group'] with context.session.begin(subtransactions=True): portpairs_list = [self._get_port_pair(context, pp_id) for pp_id in new_pg.get('port_pairs', [])] for portpair in portpairs_list: if ( portpair.portpairgroup_id and portpair.portpairgroup_id != id ): raise ext_sfc.PortPairInUse(id=portpair.id) old_pg = self._get_port_pair_group(context, id) for k, v in six.iteritems(new_pg): 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)
def delete_port_pair(self, context, id): try: with db_api.context_manager.writer.using(context): pp = self._get_port_pair(context, id) if pp.portpairgroup_id: raise ext_sfc.PortPairInUse(id=id) context.session.delete(pp) except ext_sfc.PortPairNotFound: LOG.info("Deleting a non-existing port pair.")
def delete_port_pair(self, context, id): try: with context.session.begin(subtransactions=True): pp = self._get_port_pair(context, id) if pp.portpairgroup_id: raise ext_sfc.PortPairInUse(id=id) context.session.delete(pp) except ext_sfc.PortPairNotFound: LOG.info(_LI("Deleting a non-existing port pair."))
def _validate_pps_in_ppg(self, portpairs_list, id=None): first_check = True correlation = None for portpair in portpairs_list: sfparams = portpair.service_function_parameters pp_corr = sfparams['correlation'] if first_check: first_check = False correlation = pp_corr.value if pp_corr.value != correlation: # don't include PPs of different correlations raise ext_sfc.InconsistentCorrelations() if (portpair.portpairgroup_id and portpair.portpairgroup_id != id): # don't include PPs included by other PPGs raise ext_sfc.PortPairInUse(id=portpair.id)
def create_port_pair_group(self, context, port_pair_group): """Create a port pair group.""" pg = port_pair_group['port_pair_group'] tenant_id = self._get_tenant_id_for_create(context, pg) with context.session.begin(subtransactions=True): portpairs_list = [ self._get_port_pair(context, pp_id) for pp_id in pg['port_pairs'] ] for portpair in portpairs_list: if portpair.portpairgroup_id: raise ext_sfc.PortPairInUse(id=portpair.id) port_pair_group_db = PortPairGroup(id=uuidutils.generate_uuid(), name=pg['name'], description=pg['description'], tenant_id=tenant_id, port_pairs=portpairs_list) context.session.add(port_pair_group_db) return self._make_port_pair_group_dict(port_pair_group_db)
def create_port_pair_group(self, context, port_pair_group): """Create a port pair group.""" pg = port_pair_group['port_pair_group'] tenant_id = pg['tenant_id'] with context.session.begin(subtransactions=True): portpairs_list = [self._get_port_pair(context, pp_id) for pp_id in pg['port_pairs']] for portpair in portpairs_list: if portpair.portpairgroup_id: raise ext_sfc.PortPairInUse(id=portpair.id) port_pair_group_parameters = { key: PortPairGroupParam( keyword=key, value=jsonutils.dumps(val)) for key, val in six.iteritems( pg['port_pair_group_parameters'] ) } assigned_group_ids = {} query = self._model_query(context, 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'], tenant_id=tenant_id, port_pairs=portpairs_list, port_pair_group_parameters=port_pair_group_parameters, group_id=group_id) context.session.add(port_pair_group_db) return self._make_port_pair_group_dict(port_pair_group_db)