@require_admin_context
def network_associate(context, project_id, network_id=None, force=False):
 session = get_session()
 with session.begin():
  def network_query(project_filter, id=None):
   filter_kwargs = {'project_id': project_filter}
   if (id is not None):
    filter_kwargs['id'] = id
   return model_query(context, models.Network, session=session, read_deleted='no').filter_by(**filter_kwargs).with_lockmode('update').first()
  if (not force):
   network_ref = network_query(project_id)
  if (force or (not network_ref)):
   network_ref = network_query(None, network_id)
   if (not network_ref):
    raise db.NoMoreNetworks()
   network_ref['project_id'] = project_id
   session.add(network_ref)
 return network_ref

@ require_admin_context def network_associate ( context , project_id , network_id = None , force = False ) : session = get_session ( ) with session . begin ( ) : def network_query ( project_filter , id = None ) : filter_kwargs = { 'project_id' : project_filter } if ( id is not None ) : filter_kwargs [ 'id' ] = id return model_query ( context , models . Network , session = session , read_deleted = 'no' ) . filter_by ( ** filter_kwargs ) . with_lockmode ( 'update' ) . first ( ) if ( not force ) : network_ref = network_query ( project_id ) if ( force or ( not network_ref ) ) : network_ref = network_query ( None , network_id ) if ( not network_ref ) : raise db . NoMoreNetworks ( ) network_ref [ 'project_id' ] = project_id session . add ( network_ref ) return network_ref
associate a project with a network .