<s> from oslo_utils import strutils <EOL> from oslo_utils import uuidutils <EOL> from oslo_versionedobjects import base as object_base <EOL> from ironic . common import exception <EOL> from ironic . db import api as dbapi <EOL> from ironic . objects import base <EOL> from ironic . objects import fields as object_fields <EOL> @ base . IronicObjectRegistry . register <EOL> class Chassis ( base . IronicObject , object_base . VersionedObjectDictCompat ) : <EOL> VERSION = '<STR_LIT>' <EOL> dbapi = dbapi . get_instance ( ) <EOL> fields = { <EOL> '<STR_LIT:id>' : object_fields . IntegerField ( ) , <EOL> '<STR_LIT>' : object_fields . UUIDField ( nullable = True ) , <EOL> '<STR_LIT>' : object_fields . FlexibleDictField ( nullable = True ) , <EOL> '<STR_LIT:description>' : object_fields . StringField ( nullable = True ) , <EOL> } <EOL> @ classmethod <EOL> def get ( cls , context , chassis_id ) : <EOL> """<STR_LIT>""" <EOL> if strutils . is_int_like ( chassis_id ) : <EOL> return cls . get_by_id ( context , chassis_id ) <EOL> elif uuidutils . is_uuid_like ( chassis_id ) : <EOL> return cls . get_by_uuid ( context , chassis_id ) <EOL> else : <EOL> raise exception . InvalidIdentity ( identity = chassis_id ) <EOL> @ classmethod <EOL> def get_by_id ( cls , context , chassis_id ) : <EOL> """<STR_LIT>""" <EOL> db_chassis = cls . dbapi . get_chassis_by_id ( chassis_id ) <EOL> chassis = Chassis . _from_db_object ( cls ( context ) , db_chassis ) <EOL> return chassis <EOL> @ classmethod <EOL> def get_by_uuid ( cls , context , uuid ) : <EOL> """<STR_LIT>""" <EOL> db_chassis = cls . dbapi . get_chassis_by_uuid ( uuid ) <EOL> chassis = Chassis . _from_db_object ( cls ( context ) , db_chassis ) <EOL> return chassis <EOL> @ classmethod <EOL> def list ( cls , context , limit = None , marker = None , <EOL> sort_key = None , sort_dir = None ) : <EOL> """<STR_LIT>""" <EOL> db_chassis = cls . dbapi . get_chassis_list ( limit = limit , <EOL> marker = marker , <EOL> sort_key = sort_key , <EOL> sort_dir = sort_dir ) <EOL> return [ Chassis . _from_db_object ( cls ( context ) , obj ) <EOL> for obj in db_chassis ] <EOL> def create ( self , context = None ) : <EOL> """<STR_LIT>""" <EOL> values = self . obj_get_changes ( ) <EOL> db_chassis = self . dbapi . create_chassis ( values ) <EOL> self . _from_db_object ( self , db_chassis ) <EOL> def destroy ( self , context = None ) : <EOL> """<STR_LIT>""" <EOL> self . dbapi . destroy_chassis ( self . uuid ) <EOL> self . obj_reset_changes ( ) <EOL> def save ( self , context = None ) : <EOL> """<STR_LIT>""" <EOL> updates = self . obj_get_changes ( ) <EOL> updated_chassis = self . dbapi . update_chassis ( self . uuid , updates ) <EOL> self . _from_db_object ( self , updated_chassis ) <EOL> def refresh ( self , context = None ) : <EOL> """<STR_LIT>""" <EOL> current = self . __class__ . get_by_uuid ( self . _context , uuid = self . uuid ) <EOL> self . obj_refresh ( current ) </s>
