<s> from nova import db <EOL> from nova import objects <EOL> from nova . objects import base <EOL> from nova . objects import fields <EOL> @ base . NovaObjectRegistry . register <EOL> class SecurityGroup ( base . NovaPersistentObject , base . NovaObject , <EOL> base . NovaObjectDictCompat ) : <EOL> VERSION = '<STR_LIT>' <EOL> fields = { <EOL> '<STR_LIT:id>' : fields . IntegerField ( ) , <EOL> '<STR_LIT:name>' : fields . StringField ( ) , <EOL> '<STR_LIT:description>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> '<STR_LIT>' : fields . StringField ( ) , <EOL> } <EOL> @ staticmethod <EOL> def _from_db_object ( context , secgroup , db_secgroup ) : <EOL> for field in secgroup . fields : <EOL> secgroup [ field ] = db_secgroup [ field ] <EOL> secgroup . _context = context <EOL> secgroup . obj_reset_changes ( ) <EOL> return secgroup <EOL> @ base . remotable_classmethod <EOL> def get ( cls , context , secgroup_id ) : <EOL> db_secgroup = db . security_group_get ( context , secgroup_id ) <EOL> return cls . _from_db_object ( context , cls ( ) , db_secgroup ) <EOL> @ base . remotable_classmethod <EOL> def get_by_name ( cls , context , project_id , group_name ) : <EOL> db_secgroup = db . security_group_get_by_name ( context , <EOL> project_id , <EOL> group_name ) <EOL> return cls . _from_db_object ( context , cls ( ) , db_secgroup ) <EOL> @ base . remotable <EOL> def in_use ( self ) : <EOL> return db . security_group_in_use ( self . _context , self . id ) <EOL> @ base . remotable <EOL> def save ( self ) : <EOL> updates = self . obj_get_changes ( ) <EOL> if updates : <EOL> db_secgroup = db . security_group_update ( self . _context , self . id , <EOL> updates ) <EOL> self . _from_db_object ( self . _context , self , db_secgroup ) <EOL> self . obj_reset_changes ( ) <EOL> @ base . remotable <EOL> def refresh ( self ) : <EOL> self . _from_db_object ( self . _context , self , <EOL> db . security_group_get ( self . _context , self . id ) ) <EOL> @ base . NovaObjectRegistry . register <EOL> class SecurityGroupList ( base . ObjectListBase , base . NovaObject ) : <EOL> VERSION = '<STR_LIT:1.0>' <EOL> fields = { <EOL> '<STR_LIT>' : fields . ListOfObjectsField ( '<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SecurityGroupList , self ) . __init__ ( * args , ** kwargs ) <EOL> self . objects = [ ] <EOL> self . obj_reset_changes ( ) <EOL> @ base . remotable_classmethod <EOL> def get_all ( cls , context ) : <EOL> groups = db . security_group_get_all ( context ) <EOL> return base . obj_make_list ( context , cls ( context ) , <EOL> objects . SecurityGroup , groups ) <EOL> @ base . remotable_classmethod <EOL> def get_by_project ( cls , context , project_id ) : <EOL> groups = db . security_group_get_by_project ( context , project_id ) <EOL> return base . obj_make_list ( context , cls ( context ) , <EOL> objects . SecurityGroup , groups ) <EOL> @ base . remotable_classmethod <EOL> def get_by_instance ( cls , context , instance ) : <EOL> groups = db . security_group_get_by_instance ( context , instance . uuid ) <EOL> return base . obj_make_list ( context , cls ( context ) , <EOL> objects . SecurityGroup , groups ) <EOL> def make_secgroup_list ( security_groups ) : <EOL> """<STR_LIT>""" <EOL> secgroups = objects . SecurityGroupList ( ) <EOL> secgroups . objects = [ ] <EOL> for name in security_groups : <EOL> secgroup = objects . SecurityGroup ( ) <EOL> secgroup . name = name <EOL> secgroups . objects . append ( secgroup ) <EOL> return secgroups </s>
