<s> import copy <EOL> from oslo_utils import versionutils <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova . objects import base <EOL> from nova . objects import fields <EOL> from nova import utils <EOL> from nova . virt import hardware <EOL> NULLABLE_STRING_FIELDS = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> NULLABLE_INTEGER_FIELDS = [ '<STR_LIT:size>' , '<STR_LIT>' ] <EOL> @ base . NovaObjectRegistry . register <EOL> class ImageMeta ( base . NovaObject ) : <EOL> VERSION = '<STR_LIT>' <EOL> fields = { <EOL> '<STR_LIT:id>' : fields . UUIDField ( ) , <EOL> '<STR_LIT:name>' : fields . StringField ( ) , <EOL> '<STR_LIT:status>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT:size>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . DateTimeField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . DateTimeField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . ListOfStringsField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . ObjectField ( '<STR_LIT>' ) , <EOL> } <EOL> @ classmethod <EOL> def from_dict ( cls , image_meta ) : <EOL> """<STR_LIT>""" <EOL> if image_meta is None : <EOL> image_meta = { } <EOL> image_meta = copy . deepcopy ( image_meta ) <EOL> image_meta [ "<STR_LIT>" ] = objects . ImageMetaProps . from_dict ( <EOL> image_meta . get ( "<STR_LIT>" , { } ) ) <EOL> for fld in NULLABLE_STRING_FIELDS : <EOL> if fld in image_meta and image_meta [ fld ] is None : <EOL> image_meta [ fld ] = '<STR_LIT>' <EOL> for fld in NULLABLE_INTEGER_FIELDS : <EOL> if fld in image_meta and image_meta [ fld ] is None : <EOL> image_meta [ fld ] = <NUM_LIT:0> <EOL> return cls ( ** image_meta ) <EOL> @ classmethod <EOL> def from_instance ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> sysmeta = utils . instance_sys_meta ( instance ) <EOL> image_meta = utils . get_image_from_system_metadata ( sysmeta ) <EOL> return cls . from_dict ( image_meta ) <EOL> @ classmethod <EOL> def from_image_ref ( cls , context , image_api , image_ref ) : <EOL> """<STR_LIT>""" <EOL> image_meta = image_api . get ( context , image_ref ) <EOL> image = cls . from_dict ( image_meta ) <EOL> setattr ( image , "<STR_LIT:id>" , image_ref ) <EOL> return image <EOL> @ base . NovaObjectRegistry . register <EOL> class ImageMetaProps ( base . NovaObject ) : <EOL> VERSION = '<STR_LIT>' <EOL> def obj_make_compatible ( self , primitive , target_version ) : <EOL> super ( ImageMetaProps , self ) . obj_make_compatible ( primitive , <EOL> target_version ) <EOL> target_version = versionutils . convert_version_to_tuple ( target_version ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:11> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:7> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:5> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:4> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:1> ) : <EOL> primitive . pop ( '<STR_LIT>' , None ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:6> ) : <EOL> bus = primitive . get ( '<STR_LIT>' , None ) <EOL> if bus in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise exception . ObjectActionError ( <EOL> action = '<STR_LIT>' , <EOL> reason = '<STR_LIT>' % ( <EOL> bus , target_version ) ) <EOL> NUMA_NODES_MAX = <NUM_LIT> <EOL> fields = { <EOL> '<STR_LIT>' : fields . ArchitectureField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . DiskBusField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . CPUAllocationPolicyField ( ) , <EOL> '<STR_LIT>' : fields . CPUThreadAllocationPolicyField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . DiskBusField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . DiskBusField ( ) , <EOL> '<STR_LIT>' : fields . FirmwareTypeField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . ListOfSetsOfIntegersField ( ) , <EOL> '<STR_LIT>' : fields . ListOfIntegersField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . RNGModelField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . SCSIModelField ( ) , <EOL> '<STR_LIT>' : fields . VideoModelField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . VIFModelField ( ) , <EOL> '<STR_LIT>' : fields . VMModeField ( ) , <EOL> '<STR_LIT>' : fields . WatchdogActionField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : <EOL> fields . ListOfDictOfNullableStringsField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . VersionPredicateField ( ) , <EOL> '<STR_LIT>' : fields . HVTypeField ( ) , <EOL> '<STR_LIT>' : fields . ConfigDrivePolicyField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . ListOfDictOfNullableStringsField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . ImageSignatureHashTypeField ( ) , <EOL> '<STR_LIT>' : fields . UUIDField ( ) , <EOL> '<STR_LIT>' : fields . ImageSignatureKeyTypeField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . FlexibleBooleanField ( ) , <EOL> '<STR_LIT>' : fields . OSTypeField ( ) , <EOL> } <EOL> _legacy_property_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def _set_attr_from_legacy_names ( self , image_props ) : <EOL> for legacy_key in self . _legacy_property_map : <EOL> new_key = self . _legacy_property_map [ legacy_key ] <EOL> if legacy_key not in image_props : <EOL> continue <EOL> setattr ( self , new_key , image_props [ legacy_key ] ) <EOL> vmware_adaptertype = image_props . get ( "<STR_LIT>" ) <EOL> if vmware_adaptertype == "<STR_LIT>" : <EOL> setattr ( self , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif vmware_adaptertype : <EOL> setattr ( self , "<STR_LIT>" , "<STR_LIT>" ) <EOL> setattr ( self , "<STR_LIT>" , vmware_adaptertype ) <EOL> def _set_numa_mem ( self , image_props ) : <EOL> hw_numa_mem = [ ] <EOL> hw_numa_mem_set = False <EOL> for cellid in range ( ImageMetaProps . NUMA_NODES_MAX ) : <EOL> memprop = "<STR_LIT>" % cellid <EOL> if memprop not in image_props : <EOL> break <EOL> hw_numa_mem . append ( int ( image_props [ memprop ] ) ) <EOL> hw_numa_mem_set = True <EOL> del image_props [ memprop ] <EOL> if hw_numa_mem_set : <EOL> self . hw_numa_mem = hw_numa_mem <EOL> def _set_numa_cpus ( self , image_props ) : <EOL> hw_numa_cpus = [ ] <EOL> hw_numa_cpus_set = False <EOL> for cellid in range ( ImageMetaProps . NUMA_NODES_MAX ) : <EOL> cpuprop = "<STR_LIT>" % cellid <EOL> if cpuprop not in image_props : <EOL> break <EOL> hw_numa_cpus . append ( <EOL> hardware . parse_cpu_spec ( image_props [ cpuprop ] ) ) <EOL> hw_numa_cpus_set = True <EOL> del image_props [ cpuprop ] <EOL> if hw_numa_cpus_set : <EOL> self . hw_numa_cpus = hw_numa_cpus <EOL> def _set_attr_from_current_names ( self , image_props ) : <EOL> for key in self . fields : <EOL> if key == "<STR_LIT>" : <EOL> self . _set_numa_mem ( image_props ) <EOL> elif key == "<STR_LIT>" : <EOL> self . _set_numa_cpus ( image_props ) <EOL> else : <EOL> if key not in image_props : <EOL> continue <EOL> setattr ( self , key , image_props [ key ] ) <EOL> @ classmethod <EOL> def from_dict ( cls , image_props ) : <EOL> """<STR_LIT>""" <EOL> obj = cls ( ) <EOL> obj . _set_attr_from_legacy_names ( image_props ) <EOL> obj . _set_attr_from_current_names ( image_props ) <EOL> return obj <EOL> def get ( self , name , defvalue = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . obj_attr_is_set ( name ) : <EOL> return defvalue <EOL> return getattr ( self , name ) </s>
