<s> import logging <EOL> from keystoneclient import exceptions <EOL> from cloudferry . lib . os import clients <EOL> from cloudferry . lib . os . discovery import model <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ model . type_alias ( '<STR_LIT>' ) <EOL> class Tenant ( model . Model ) : <EOL> class Schema ( model . Schema ) : <EOL> object_id = model . PrimaryKey ( '<STR_LIT:id>' ) <EOL> name = model . String ( required = True ) <EOL> enabled = model . Boolean ( required = True ) <EOL> description = model . String ( allow_none = True ) <EOL> @ classmethod <EOL> def load_missing ( cls , cloud , object_id ) : <EOL> identity_client = clients . identity_client ( cloud ) <EOL> try : <EOL> raw_tenant = identity_client . tenants . get ( object_id . id ) <EOL> return cls . load_from_cloud ( cloud , raw_tenant ) <EOL> except exceptions . NotFound : <EOL> return None <EOL> @ classmethod <EOL> def discover ( cls , cloud ) : <EOL> identity_client = clients . identity_client ( cloud ) <EOL> with model . Session ( ) as session : <EOL> for tenant in identity_client . tenants . list ( ) : <EOL> session . store ( Tenant . load_from_cloud ( cloud , tenant ) ) <EOL> def equals ( self , other ) : <EOL> return self . name . lower ( ) == other . name . lower ( ) </s>
