<s> from nova . compute import task_states <EOL> from nova . compute import vm_states <EOL> import nova . conf <EOL> from nova import objects <EOL> from nova . virt import block_device as driver_block_device <EOL> CONF = nova . conf . CONF <EOL> CONF . import_opt ( '<STR_LIT:host>' , '<STR_LIT>' ) <EOL> class ImageCacheManager ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . remove_unused_base_images = CONF . remove_unused_base_images <EOL> self . resize_states = [ task_states . RESIZE_PREP , <EOL> task_states . RESIZE_MIGRATING , <EOL> task_states . RESIZE_MIGRATED , <EOL> task_states . RESIZE_FINISH ] <EOL> def _get_base ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def _list_running_instances ( self , context , all_instances ) : <EOL> """<STR_LIT>""" <EOL> used_images = { } <EOL> image_popularity = { } <EOL> instance_names = set ( ) <EOL> used_swap_images = set ( ) <EOL> instance_bdms = objects . BlockDeviceMappingList . bdms_by_instance_uuid ( <EOL> context , [ instance . uuid for instance in all_instances ] ) <EOL> for instance in all_instances : <EOL> instance_names . add ( instance . name ) <EOL> instance_names . add ( instance . uuid ) <EOL> if ( instance . task_state in self . resize_states or <EOL> instance . vm_state == vm_states . RESIZED ) : <EOL> instance_names . add ( instance . name + '<STR_LIT>' ) <EOL> instance_names . add ( instance . uuid + '<STR_LIT>' ) <EOL> for image_key in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> image_ref_str = getattr ( instance , image_key ) <EOL> if image_ref_str is None : <EOL> continue <EOL> local , remote , insts = used_images . get ( image_ref_str , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> , [ ] ) ) <EOL> if instance . host == CONF . host : <EOL> local += <NUM_LIT:1> <EOL> else : <EOL> remote += <NUM_LIT:1> <EOL> insts . append ( instance . name ) <EOL> used_images [ image_ref_str ] = ( local , remote , insts ) <EOL> image_popularity . setdefault ( image_ref_str , <NUM_LIT:0> ) <EOL> image_popularity [ image_ref_str ] += <NUM_LIT:1> <EOL> bdms = instance_bdms . get ( instance . uuid ) <EOL> if bdms : <EOL> swap = driver_block_device . convert_swap ( bdms ) <EOL> if swap : <EOL> swap_image = '<STR_LIT>' + str ( swap [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> used_swap_images . add ( swap_image ) <EOL> return { '<STR_LIT>' : used_images , <EOL> '<STR_LIT>' : image_popularity , <EOL> '<STR_LIT>' : instance_names , <EOL> '<STR_LIT>' : used_swap_images } <EOL> def _list_base_images ( self , base_dir ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } <EOL> def _age_and_verify_cached_images ( self , context , all_instances , base_dir ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def update ( self , context , all_instances ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
