<s> from oslo_utils import versionutils <EOL> from nova import db <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova . objects import base <EOL> from nova . objects import fields <EOL> def determine_migration_type ( migration ) : <EOL> if migration [ '<STR_LIT>' ] != migration [ '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> @ base . NovaObjectRegistry . register <EOL> class Migration ( base . NovaPersistentObject , base . NovaObject , <EOL> base . NovaObjectDictCompat ) : <EOL> VERSION = '<STR_LIT>' <EOL> fields = { <EOL> '<STR_LIT:id>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT:status>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . EnumField ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> nullable = False ) , <EOL> '<STR_LIT>' : fields . BooleanField ( nullable = False , default = False ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( nullable = True ) , <EOL> } <EOL> @ staticmethod <EOL> def _from_db_object ( context , migration , db_migration ) : <EOL> for key in migration . fields : <EOL> value = db_migration [ key ] <EOL> if key == '<STR_LIT>' and value is None : <EOL> value = determine_migration_type ( db_migration ) <EOL> migration [ key ] = value <EOL> migration . _context = context <EOL> migration . obj_reset_changes ( ) <EOL> return migration <EOL> def obj_make_compatible ( self , primitive , target_version ) : <EOL> super ( Migration , self ) . obj_make_compatible ( primitive , target_version ) <EOL> target_version = versionutils . convert_version_to_tuple ( target_version ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> if '<STR_LIT>' in primitive : <EOL> del primitive [ '<STR_LIT>' ] <EOL> del primitive [ '<STR_LIT>' ] <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:4> ) : <EOL> if '<STR_LIT>' in primitive : <EOL> del primitive [ '<STR_LIT>' ] <EOL> del primitive [ '<STR_LIT>' ] <EOL> del primitive [ '<STR_LIT>' ] <EOL> del primitive [ '<STR_LIT>' ] <EOL> del primitive [ '<STR_LIT>' ] <EOL> del primitive [ '<STR_LIT>' ] <EOL> def obj_load_attr ( self , attrname ) : <EOL> if attrname == '<STR_LIT>' : <EOL> self . migration_type = determine_migration_type ( self ) <EOL> elif attrname == '<STR_LIT>' : <EOL> self . hidden = False <EOL> else : <EOL> super ( Migration , self ) . obj_load_attr ( attrname ) <EOL> @ base . remotable_classmethod <EOL> def get_by_id ( cls , context , migration_id ) : <EOL> db_migration = db . migration_get ( context , migration_id ) <EOL> return cls . _from_db_object ( context , cls ( ) , db_migration ) <EOL> @ base . remotable_classmethod <EOL> def get_by_id_and_instance ( cls , context , migration_id , instance_uuid ) : <EOL> db_migration = db . migration_get_by_id_and_instance ( <EOL> context , migration_id , instance_uuid ) <EOL> return cls . _from_db_object ( context , cls ( ) , db_migration ) <EOL> @ base . remotable_classmethod <EOL> def get_by_instance_and_status ( cls , context , instance_uuid , status ) : <EOL> db_migration = db . migration_get_by_instance_and_status ( <EOL> context , instance_uuid , status ) <EOL> return cls . _from_db_object ( context , cls ( ) , db_migration ) <EOL> @ base . remotable <EOL> def create ( self ) : <EOL> if self . obj_attr_is_set ( '<STR_LIT:id>' ) : <EOL> raise exception . ObjectActionError ( action = '<STR_LIT>' , <EOL> reason = '<STR_LIT>' ) <EOL> updates = self . obj_get_changes ( ) <EOL> if '<STR_LIT>' not in updates : <EOL> raise exception . ObjectActionError ( <EOL> action = "<STR_LIT>" , <EOL> reason = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> db_migration = db . migration_create ( self . _context , updates ) <EOL> self . _from_db_object ( self . _context , self , db_migration ) <EOL> @ base . remotable <EOL> def save ( self ) : <EOL> updates = self . obj_get_changes ( ) <EOL> updates . pop ( '<STR_LIT:id>' , None ) <EOL> db_migration = db . migration_update ( self . _context , self . id , updates ) <EOL> self . _from_db_object ( self . _context , self , db_migration ) <EOL> self . obj_reset_changes ( ) <EOL> @ property <EOL> def instance ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _cached_instance = objects . Instance . get_by_uuid ( <EOL> self . _context , self . instance_uuid ) <EOL> return self . _cached_instance <EOL> @ instance . setter <EOL> def instance ( self , instance ) : <EOL> self . _cached_instance = instance <EOL> @ base . NovaObjectRegistry . register <EOL> class MigrationList ( base . ObjectListBase , base . NovaObject ) : <EOL> VERSION = '<STR_LIT>' <EOL> fields = { <EOL> '<STR_LIT>' : fields . ListOfObjectsField ( '<STR_LIT>' ) , <EOL> } <EOL> @ staticmethod <EOL> @ db . select_db_reader_mode <EOL> def _db_migration_get_unconfirmed_by_dest_compute ( <EOL> context , confirm_window , dest_compute , use_slave = False ) : <EOL> return db . migration_get_unconfirmed_by_dest_compute ( <EOL> context , confirm_window , dest_compute ) <EOL> @ base . remotable_classmethod <EOL> def get_unconfirmed_by_dest_compute ( cls , context , confirm_window , <EOL> dest_compute , use_slave = False ) : <EOL> db_migrations = cls . _db_migration_get_unconfirmed_by_dest_compute ( <EOL> context , confirm_window , dest_compute , use_slave = use_slave ) <EOL> return base . obj_make_list ( context , cls ( context ) , objects . Migration , <EOL> db_migrations ) <EOL> @ base . remotable_classmethod <EOL> def get_in_progress_by_host_and_node ( cls , context , host , node ) : <EOL> db_migrations = db . migration_get_in_progress_by_host_and_node ( <EOL> context , host , node ) <EOL> return base . obj_make_list ( context , cls ( context ) , objects . Migration , <EOL> db_migrations ) <EOL> @ base . remotable_classmethod <EOL> def get_by_filters ( cls , context , filters ) : <EOL> db_migrations = db . migration_get_all_by_filters ( context , filters ) <EOL> return base . obj_make_list ( context , cls ( context ) , objects . Migration , <EOL> db_migrations ) <EOL> @ base . remotable_classmethod <EOL> def get_in_progress_by_instance ( cls , context , instance_uuid , <EOL> migration_type = None ) : <EOL> db_migrations = db . migration_get_in_progress_by_instance ( <EOL> context , instance_uuid , migration_type ) <EOL> return base . obj_make_list ( context , cls ( context ) , objects . Migration , <EOL> db_migrations ) </s>
