<s> import dnsclient . exceptions <EOL> class ServiceCatalog ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , resource_dict ) : <EOL> self . catalog = resource_dict <EOL> def get_token ( self ) : <EOL> return self . catalog [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] <EOL> def url_for ( self , attr = None , filter_value = None , <EOL> service_type = None , endpoint_type = '<STR_LIT>' , <EOL> service_name = None , volume_service_name = None ) : <EOL> """<STR_LIT>""" <EOL> matching_endpoints = [ ] <EOL> if '<STR_LIT>' in self . catalog : <EOL> for endpoint in self . catalog [ '<STR_LIT>' ] : <EOL> if not filter_value or endpoint [ attr ] == filter_value : <EOL> if endpoint . get ( "<STR_LIT:type>" ) == '<STR_LIT>' and endpoint . get ( '<STR_LIT>' ) in ( None , '<STR_LIT>' , '<STR_LIT:2>' ) : <EOL> matching_endpoints . append ( endpoint ) <EOL> if not matching_endpoints : <EOL> raise dnsclient . exceptions . EndpointNotFound ( ) <EOL> if not '<STR_LIT>' in self . catalog [ '<STR_LIT>' ] : <EOL> return None <EOL> catalog = self . catalog [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> for service in catalog : <EOL> if service . get ( "<STR_LIT:type>" ) != service_type : <EOL> continue <EOL> if ( service_name and service_type == '<STR_LIT>' and <EOL> service . get ( '<STR_LIT:name>' ) != service_name ) : <EOL> continue <EOL> if ( volume_service_name and service_type == '<STR_LIT>' and <EOL> service . get ( '<STR_LIT:name>' ) != volume_service_name ) : <EOL> continue <EOL> endpoints = service [ '<STR_LIT>' ] <EOL> for endpoint in endpoints : <EOL> if service . get ( "<STR_LIT:type>" ) == '<STR_LIT>' and endpoint . get ( '<STR_LIT>' , '<STR_LIT:2>' ) not in ( '<STR_LIT>' , '<STR_LIT:2>' ) : <EOL> continue <EOL> if not filter_value or endpoint . get ( attr ) . lower ( ) == filter_value . lower ( ) : <EOL> endpoint [ "<STR_LIT>" ] = service . get ( "<STR_LIT:name>" ) <EOL> matching_endpoints . append ( endpoint ) <EOL> if not matching_endpoints : <EOL> raise dnsclient . exceptions . EndpointNotFound ( ) <EOL> elif len ( matching_endpoints ) > <NUM_LIT:1> : <EOL> raise dnsclient . exceptions . AmbiguousEndpoints ( <EOL> endpoints = matching_endpoints ) <EOL> else : <EOL> return matching_endpoints [ <NUM_LIT:0> ] [ endpoint_type ] </s>
