def _prevent_segment_delete_with_port_bound(resource, event, trigger, context, segment):
 segment_id = segment['id']
 query = context.session.query(models_v2.Port)
 query = query.join(models.PortBindingLevel, (models.PortBindingLevel.port_id == models_v2.Port.id))
 query = query.filter((models.PortBindingLevel.segment_id == segment_id))
 port_ids = [p.id for p in query]
 if port_ids:
  reason = (_('The segment is still bound with port(s) %s') % ', '.join(port_ids))
  raise seg_exc.SegmentInUse(segment_id=segment_id, reason=reason)

def _prevent_segment_delete_with_port_bound ( resource , event , trigger , context , segment ) : segment_id = segment [ 'id' ] query = context . session . query ( models_v2 . Port ) query = query . join ( models . PortBindingLevel , ( models . PortBindingLevel . port_id == models_v2 . Port . id ) ) query = query . filter ( ( models . PortBindingLevel . segment_id == segment_id ) ) port_ids = [ p . id for p in query ] if port_ids : reason = ( _ ( 'The segment is still bound with port(s) %s' ) % ', ' . join ( port_ids ) ) raise seg_exc . SegmentInUse ( segment_id = segment_id , reason = reason )
raise exception if there are any ports bound with segment_id .