<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> @ base . NovaObjectRegistry . register <EOL> class VirtualInterface ( base . NovaPersistentObject , base . NovaObject ) : <EOL> VERSION = '<STR_LIT>' <EOL> fields = { <EOL> '<STR_LIT:id>' : fields . IntegerField ( ) , <EOL> '<STR_LIT:address>' : fields . StringField ( nullable = True ) , <EOL> '<STR_LIT>' : fields . IntegerField ( ) , <EOL> '<STR_LIT>' : fields . UUIDField ( ) , <EOL> '<STR_LIT>' : fields . UUIDField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( nullable = True ) , <EOL> } <EOL> def obj_make_compatible ( self , primitive , target_version ) : <EOL> target_version = versionutils . convert_version_to_tuple ( target_version ) <EOL> if target_version < ( <NUM_LIT:1> , <NUM_LIT:1> ) and '<STR_LIT>' in primitive : <EOL> del primitive [ '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def _from_db_object ( context , vif , db_vif ) : <EOL> for field in vif . fields : <EOL> setattr ( vif , field , db_vif [ field ] ) <EOL> vif . _context = context <EOL> vif . obj_reset_changes ( ) <EOL> return vif <EOL> @ base . remotable_classmethod <EOL> def get_by_id ( cls , context , vif_id ) : <EOL> db_vif = db . virtual_interface_get ( context , vif_id ) <EOL> if db_vif : <EOL> return cls . _from_db_object ( context , cls ( ) , db_vif ) <EOL> @ base . remotable_classmethod <EOL> def get_by_uuid ( cls , context , vif_uuid ) : <EOL> db_vif = db . virtual_interface_get_by_uuid ( context , vif_uuid ) <EOL> if db_vif : <EOL> return cls . _from_db_object ( context , cls ( ) , db_vif ) <EOL> @ base . remotable_classmethod <EOL> def get_by_address ( cls , context , address ) : <EOL> db_vif = db . virtual_interface_get_by_address ( context , address ) <EOL> if db_vif : <EOL> return cls . _from_db_object ( context , cls ( ) , db_vif ) <EOL> @ base . remotable_classmethod <EOL> def get_by_instance_and_network ( cls , context , instance_uuid , network_id ) : <EOL> db_vif = db . virtual_interface_get_by_instance_and_network ( context , <EOL> instance_uuid , network_id ) <EOL> if db_vif : <EOL> return cls . _from_db_object ( context , cls ( ) , db_vif ) <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> db_vif = db . virtual_interface_create ( self . _context , updates ) <EOL> self . _from_db_object ( self . _context , self , db_vif ) <EOL> @ base . remotable_classmethod <EOL> def delete_by_instance_uuid ( cls , context , instance_uuid ) : <EOL> db . virtual_interface_delete_by_instance ( context , instance_uuid ) <EOL> @ base . NovaObjectRegistry . register <EOL> class VirtualInterfaceList ( base . ObjectListBase , base . NovaObject ) : <EOL> VERSION = '<STR_LIT:1.0>' <EOL> fields = { <EOL> '<STR_LIT>' : fields . ListOfObjectsField ( '<STR_LIT>' ) , <EOL> } <EOL> @ base . remotable_classmethod <EOL> def get_all ( cls , context ) : <EOL> db_vifs = db . virtual_interface_get_all ( context ) <EOL> return base . obj_make_list ( context , cls ( context ) , <EOL> objects . VirtualInterface , db_vifs ) <EOL> @ staticmethod <EOL> @ db . select_db_reader_mode <EOL> def _db_virtual_interface_get_by_instance ( context , instance_uuid , <EOL> use_slave = False ) : <EOL> return db . virtual_interface_get_by_instance ( context , instance_uuid ) <EOL> @ base . remotable_classmethod <EOL> def get_by_instance_uuid ( cls , context , instance_uuid , use_slave = False ) : <EOL> db_vifs = cls . _db_virtual_interface_get_by_instance ( <EOL> context , instance_uuid , use_slave = use_slave ) <EOL> return base . obj_make_list ( context , cls ( context ) , <EOL> objects . VirtualInterface , db_vifs ) </s>
