#NEWLINE# def _set_ess_for_l3p( self , context , l3p_db , es_dict ) : #NEWLINE# #INDENT# if ( es_dict is attr . ATTR_NOT_SPECIFIED ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( not es_dict ) : #NEWLINE# #INDENT# l3p_db . external_segments = [ ] #NEWLINE# return #NEWLINE# #UNINDENT# with context . session . begin ( subtransactions = True ) : #NEWLINE# #INDENT# es_set = set ( es_dict . keys ( ) ) #NEWLINE# filters = { #NEWLINE# #INDENT# 'id' : es_set , #NEWLINE# #UNINDENT# } #NEWLINE# es_in_db = self . _get_collection_query ( context , ExternalSegment , filters = filters ) #NEWLINE# not_found = ( es_set - set ( ( es [ 'id' ] for es in es_in_db ) ) ) #NEWLINE# if not_found : #NEWLINE# #INDENT# raise gpolicy . ExternalSegmentNotFound ( id = not_found . pop ( ) ) #NEWLINE# #UNINDENT# l3p_db . external_segments = [ ] #NEWLINE# for es in es_in_db : #NEWLINE# #INDENT# ips = [ x for x in es_dict [ es [ 'id' ] ] if x ] #NEWLINE# if ( not es_dict ) : #NEWLINE# #INDENT# assoc = ESToL3PAssociation ( external_segment_id = es [ 'id' ] , l3_policy_id = l3p_db [ 'id' ] , allocated_address = ADDRESS_NOT_SPECIFIED ) #NEWLINE# l3p_db . external_segments . append ( assoc ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# existing = context . session . query ( ESToL3PAssociation ) . filter_by ( external_segment_id = es [ 'id' ] ) . filter ( ESToL3PAssociation . allocated_address . in_ ( ips ) ) . all ( ) #NEWLINE# if existing : #NEWLINE# #INDENT# raise gpolicy . IpAddressOverlappingInExternalSegment ( es_id = es [ 'id' ] ) #NEWLINE# #UNINDENT# for ip in es_dict [ es [ 'id' ] ] : #NEWLINE# #INDENT# assoc = ESToL3PAssociation ( external_segment_id = es [ 'id' ] , l3_policy_id = l3p_db [ 'id' ] , allocated_address = ip ) #NEWLINE# l3p_db . external_segments . append ( assoc )