Revision 8cec3671

b/kamaki/cli/__init__.py
226 226
        global_url = _cnf.get('global', 'auth_url')
227 227
    global_token = _cnf.get('global', 'token')
228 228
    from kamaki.clients.astakos import AstakosClient as AuthCachedClient
229
    return AuthCachedClient(global_url, global_token)
229
    try:
230
        return AuthCachedClient(global_url, global_token)
231
    except AssertionError as ae:
232
        kloger.warning('WARNING: Failed to load auth_url %s [ %s ]' % (
233
            global_url, ae))
234
        return None
230 235

  
231 236

  
232 237
def _load_spec_module(spec, arguments, module):
b/kamaki/cli/command_shell.py
164 164
    def _create_help_method(cmd_name, args, descr, syntax):
165 165
        tmp_args = dict(args)
166 166
        tmp_args.pop('options', None)
167
        tmp_args.pop('cloud', None)
167 168
        tmp_args.pop('debug', None)
168 169
        tmp_args.pop('verbose', None)
169 170
        tmp_args.pop('include', None)
b/kamaki/cli/commands/astakos.py
32 32
# or implied, of GRNET S.A.command
33 33

  
34 34
from kamaki.cli import command
35
#from kamaki.clients.astakos import AstakosClient
35
from kamaki.clients.astakos import AstakosClient
36 36
from kamaki.cli.commands import _command_init, errors, _optional_json
37 37
from kamaki.cli.command_tree import CommandTree
38
from kamaki.cli.errors import CLIBaseUrlError
38 39

  
39 40
user_cmds = CommandTree('user', 'Astakos API commands')
40 41
_commands = [user_cmds]
......
49 50
        #    or self.config.get('global', 'token')
50 51
        #base_url = self.config.get('global', 'url')
51 52
        #self.client = AstakosClient(base_url=base_url, token=token)
52
        self.client = self.auth_base
53
        if getattr(self, 'auth_base', False):
54
            self.client = self.auth_base
55
        else:
56
            token = self.config.get('astakos', 'token')\
57
                or self.config.get('global', 'token')
58
            base_url = self.config.get('astakos', 'url')
59
            if not base_url:
60
                raise CLIBaseUrlError(service='astakos')
61
            self.client = AstakosClient(base_url=base_url, token=token)
62

  
53 63
        self._set_log_params()
54 64
        self._update_max_threads()
55 65

  
......
71 81
    @errors.user.authenticate
72 82
    def _run(self, custom_token=None):
73 83
        super(self.__class__, self)._run()
74
        r = self.auth_base.authenticate(custom_token)
84
        r = self.client.authenticate(custom_token)
75 85
        self._print([r], title=('uuid', 'name',), with_redundancy=True)
76 86

  
77 87
    def main(self, custom_token=None):
b/kamaki/cli/commands/cyclades.py
34 34
from kamaki.cli import command
35 35
from kamaki.cli.command_tree import CommandTree
36 36
from kamaki.cli.utils import print_dict
37
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
37
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
38 38
from kamaki.clients.cyclades import CycladesClient, ClientError
39 39
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
40 40
from kamaki.cli.argument import ProgressBarArgument, DateArgument, IntArgument
......
70 70
    def _run(self, service='compute'):
71 71
        token = self.config.get(service, 'token')\
72 72
            or self.config.get('global', 'token')
73
        cyclades_endpoints = self.auth_base.get_service_endpoints(
74
            self.config.get('cyclades', 'type'),
75
            self.config.get('cyclades', 'version'))
76
        base_url = cyclades_endpoints['publicURL']
73

  
74
        if getattr(self, 'auth_base', False):
75
            cyclades_endpoints = self.auth_base.get_service_endpoints(
76
                self.config.get('cyclades', 'type'),
77
                self.config.get('cyclades', 'version'))
78
            base_url = cyclades_endpoints['publicURL']
79
        else:
80
            base_url = self.config.get('cyclades', 'url')
81
        if not base_url:
82
            raise CLIBaseUrlError(service='cyclades')
83

  
77 84
        self.client = CycladesClient(base_url=base_url, token=token)
78 85
        self._set_log_params()
79 86
        self._update_max_threads()
b/kamaki/cli/commands/image.py
45 45
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
46 46
from kamaki.cli.argument import IntArgument
47 47
from kamaki.cli.commands.cyclades import _init_cyclades
48
from kamaki.cli.errors import raiseCLIError
48
from kamaki.cli.errors import raiseCLIError, CLIBaseUrlError
49 49
from kamaki.cli.commands import _command_init, errors
50 50
from kamaki.cli.commands import _optional_output_cmd, _optional_json
51 51

  
......
75 75
    @errors.generic.all
76 76
    def _run(self):
77 77
        token = self.config.get('image', 'token')\
78
            or self.config.get('compute', 'token')\
79 78
            or self.config.get('global', 'token')
80
        plankton_endpoints = self.auth_base.get_service_endpoints(
81
            self.config.get('plankton', 'type'),
82
            self.config.get('plankton', 'version'))
83
        base_url = plankton_endpoints['publicURL']
84
        #base_url = self.config.get('image', 'url')\
85
        #    or self.config.get('compute', 'url')\
86
        #    or self.config.get('global', 'url')
79

  
80
        if getattr(self, 'auth_base', False):
81
            plankton_endpoints = self.auth_base.get_service_endpoints(
82
                self.config.get('plankton', 'type'),
83
                self.config.get('plankton', 'version'))
84
            base_url = plankton_endpoints['publicURL']
85
        else:
86
            base_url = self.config.get('plankton', 'url')
87
        if not base_url:
88
            raise CLIBaseUrlError(service='plankton')
89

  
87 90
        self.client = ImageClient(base_url=base_url, token=token)
88 91
        self._set_log_params()
89 92
        self._update_max_threads()
b/kamaki/cli/commands/pithos.py
37 37

  
38 38
from kamaki.cli import command
39 39
from kamaki.cli.command_tree import CommandTree
40
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
40
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
41 41
from kamaki.cli.utils import (
42 42
    format_size, to_bytes, print_dict, print_items, pretty_keys, pretty_dict,
43 43
    page_hold, bold, ask_user, get_path_size, print_json)
......
147 147
    @staticmethod
148 148
    def _is_dir(remote_dict):
149 149
        return 'application/directory' == remote_dict.get(
150
            'content_type',
151
            remote_dict.get('content-type', ''))
150
            'content_type', remote_dict.get('content-type', ''))
152 151

  
153 152
    @errors.generic.all
154 153
    def _run(self):
155 154
        self.token = self.config.get('file', 'token')\
156 155
            or self.config.get('global', 'token')
157
        pithos_endpoints = self.auth_base.get_service_endpoints(
158
            self.config.get('pithos', 'type'),
159
            self.config.get('pithos', 'version'))
160
        self.base_url = pithos_endpoints['publicURL']
156

  
157
        if getattr(self, 'auth_base', False):
158
            pithos_endpoints = self.auth_base.get_service_endpoints(
159
                self.config.get('pithos', 'type'),
160
                self.config.get('pithos', 'version'))
161
            self.base_url = pithos_endpoints['publicURL']
162
        else:
163
            self.base_url = self.config.get('pithos', 'url')
164
        if not self.base_url:
165
            raise CLIBaseUrlError(service='pithos')
166

  
161 167
        self._set_account()
162 168
        self.container = self.config.get('file', 'container')\
163 169
            or self.config.get('global', 'container')
b/kamaki/cli/errors.py
55 55
            self.importance = 0
56 56

  
57 57

  
58
class CLIBaseUrlError(CLIError):
59
    def __init__(self, message='', details=[], importance=2, service=None):
60
        message = message or 'No url for %s' % service.lower()
61
        details = details or [
62
            'Two options to resolve this:',
63
            'A. (recommended) Let kamaki discover the endpoint URLs for all',
64
            'services by setting a single Authentication URL:',
65
            '  /config set auth_url <AUTH_URL>',
66
            'B. (advanced users) Explicitly set a valid %s endpoint URL' % (
67
                service.upper()),
68
            'Note: auth_url option has a higher priority, so delete it to',
69
            'make that work',
70
            '  /config delete auth_url',
71
            '  /config set %s.url <%s_URL>' % (service, service.upper())]
72
        super(CLIBaseUrlError, self).__init__(message, details, importance)
73

  
74

  
58 75
class CLISyntaxError(CLIError):
59 76
    def __init__(self, message='Syntax Error', details=[], importance=1):
60 77
        super(CLISyntaxError, self).__init__(message, details, importance)
b/kamaki/clients/astakos/__init__.py
53 53
        :returns: (dict) authentication information
54 54
        """
55 55
        self.token = token or self.token
56
        self._cache[self.token] = self.post('/tokens').json
56
        body = dict(auth=dict(token=dict(id=self.token)))
57
        self.set_headers('content-type', 'application/json')
58
        self._cache[self.token] = self.post('/tokens', data=body).json
57 59
        return self._cache[self.token]
58 60

  
59 61
    def get_services(self, token=None):

Also available in: Unified diff