<s> """<STR_LIT>""" <EOL> import datetime <EOL> from cloudferry . lib . base import exception <EOL> from cloudferry . lib . utils import filters <EOL> def _tenant_filtering_enabled ( filtered_tenant_id ) : <EOL> return filtered_tenant_id is not None <EOL> def _tenant_filtering_disabled ( filtered_tenant_id ) : <EOL> return not _tenant_filtering_enabled ( filtered_tenant_id ) <EOL> def _image_filtering_enabled ( filtered_images ) : <EOL> return filtered_images is not None and len ( filtered_images ) > <NUM_LIT:0> <EOL> def _image_filtering_disabled ( filtered_images ) : <EOL> return not _image_filtering_enabled ( filtered_images ) <EOL> def public_filter ( ) : <EOL> return lambda i : i . is_public <EOL> def active_filter ( ) : <EOL> return lambda i : i . status == '<STR_LIT>' <EOL> def tenant_filter ( filtered_tenant_id ) : <EOL> """<STR_LIT>""" <EOL> return lambda i : ( _tenant_filtering_disabled ( filtered_tenant_id ) or <EOL> i . owner == filtered_tenant_id ) <EOL> def image_id_filter ( filtered_images ) : <EOL> """<STR_LIT>""" <EOL> return lambda i : ( _image_filtering_disabled ( filtered_images ) or <EOL> i . id in filtered_images ) <EOL> def image_id_exclude_filter ( filtered_images ) : <EOL> """<STR_LIT>""" <EOL> return lambda i : ( _image_filtering_disabled ( filtered_images ) or <EOL> i . id not in filtered_images ) <EOL> def member_filter ( glance_client , filtered_tenant_id ) : <EOL> """<STR_LIT>""" <EOL> members_present = glance_client . image_members . list ( <EOL> member = filtered_tenant_id ) <EOL> ids = [ member . image_id for member in members_present ] <EOL> return lambda i : i . id in ids <EOL> def extract_date ( i ) : <EOL> return datetime . datetime . strptime ( i . updated_at , "<STR_LIT>" ) <EOL> def datetime_filter ( date ) : <EOL> """<STR_LIT>""" <EOL> return lambda i : date is None or date <= extract_date ( i ) <EOL> class GlanceFilters ( filters . CFFilters ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , glance_client , filter_yaml ) : <EOL> super ( GlanceFilters , self ) . __init__ ( filter_yaml ) <EOL> self . glance_client = glance_client <EOL> def get_filters ( self ) : <EOL> is_public = public_filter ( ) <EOL> is_active = active_filter ( ) <EOL> is_datetime = datetime_filter ( self . filter_yaml . get_image_date ( ) ) <EOL> is_tenant = tenant_filter ( self . filter_yaml . get_tenant ( ) ) <EOL> images_list = self . filter_yaml . get_image_ids ( ) <EOL> excluded_images_list = self . filter_yaml . get_excluded_image_ids ( ) <EOL> if images_list and excluded_images_list : <EOL> raise exception . AbortMigrationError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if excluded_images_list : <EOL> is_image_id = image_id_exclude_filter ( excluded_images_list ) <EOL> else : <EOL> is_image_id = image_id_filter ( images_list ) <EOL> is_member = member_filter ( self . glance_client , <EOL> self . filter_yaml . get_tenant ( ) ) <EOL> if self . filter_yaml . is_public_and_member_images_filtered ( ) : <EOL> return [ lambda i : ( is_active ( i ) and <EOL> is_tenant ( i ) and <EOL> is_image_id ( i ) and <EOL> is_datetime ( i ) ) ] <EOL> else : <EOL> return [ <EOL> lambda i : ( is_active ( i ) and is_public ( i ) or <EOL> is_active ( i ) and is_member ( i ) or <EOL> is_active ( i ) and is_tenant ( i ) and is_image_id ( i ) and <EOL> is_datetime ( i ) ) ] </s>
