<s> """<STR_LIT>""" <EOL> import six <EOL> from openstackclient . common import command <EOL> from openstackclient . common import utils <EOL> from openstackclient . i18n import _ <EOL> def _format_endpoints ( eps = None ) : <EOL> if not eps : <EOL> return "<STR_LIT>" <EOL> ret = '<STR_LIT>' <EOL> for ep in eps : <EOL> region = ep . get ( '<STR_LIT>' ) or ep . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ret += region + '<STR_LIT:\n>' <EOL> ret += "<STR_LIT>" % ( ep [ '<STR_LIT>' ] , ep [ '<STR_LIT:url>' ] ) <EOL> return ret <EOL> class ListCatalog ( command . Lister ) : <EOL> """<STR_LIT>""" <EOL> def take_action ( self , parsed_args ) : <EOL> sc = self . app . client_manager . session . auth . get_auth_ref ( <EOL> self . app . client_manager . session , <EOL> ) . service_catalog <EOL> data = sc . get_data ( ) <EOL> columns = ( '<STR_LIT:Name>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return ( columns , <EOL> ( utils . get_dict_properties ( <EOL> s , columns , <EOL> formatters = { <EOL> '<STR_LIT>' : _format_endpoints , <EOL> } , <EOL> ) for s in data ) ) <EOL> class ShowCatalog ( command . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShowCatalog , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) , <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> sc = self . app . client_manager . session . auth . get_auth_ref ( <EOL> self . app . client_manager . session , <EOL> ) . service_catalog <EOL> data = None <EOL> for service in sc . get_data ( ) : <EOL> if ( service . get ( '<STR_LIT:name>' ) == parsed_args . service or <EOL> service . get ( '<STR_LIT:type>' ) == parsed_args . service ) : <EOL> data = dict ( service ) <EOL> data [ '<STR_LIT>' ] = _format_endpoints ( data [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in data : <EOL> data . pop ( '<STR_LIT>' ) <EOL> break <EOL> if not data : <EOL> self . app . log . error ( '<STR_LIT>' % <EOL> parsed_args . service ) <EOL> return ( [ ] , [ ] ) <EOL> return zip ( * sorted ( six . iteritems ( data ) ) ) </s>
