Revision 844a6bdb kamaki/cli/__init__.py

b/kamaki/cli/__init__.py
222 222

  
223 223

  
224 224
def _init_session(arguments, is_non_API=False):
225
    """
226
    :returns: (AuthCachedClient, str) authenticator and cloud remote name
227
    """
225 228
    global _help
226 229
    _help = arguments['help'].value
227 230
    global _debug
......
242 245
    _setup_logging(_silent, _debug, _verbose, _include)
243 246

  
244 247
    if _help or is_non_API:
245
        return None
248
        return None, None
246 249

  
247 250
    cloud = arguments['cloud'].value or 'default'
248 251
    if not cloud in _cnf.value.keys('remote'):
......
253 256
                'single authentication URL and token:',
254 257
                '  kamaki config set remote.%s.url <URL>' % cloud,
255 258
                '  kamaki config set remote.%s.token <t0k3n>' % cloud])
256
    url = _cnf.get_remote(cloud, 'url')
257
    if not url:
258
        kloger.warning(
259
            'WARNING: No remote.%s.url, use service urls instead' % cloud)
260
        return cloud
261
    token = _cnf.get_remote(cloud, 'token')
262
    if not token:
263
        raise CLIError(
264
            'No authentication token provided for %s cloud' % cloud,
265
            importance=3, details=[
266
                'Get and set a token for %s cloud:' % cloud,
267
                '  kamaki config set remote.%s.token <t0k3n>' % cloud])
259
    auth_args = dict()
260
    for term in ('url', 'token'):
261
        auth_args[term] = _cnf.get_remote(cloud, term)
262
        if not auth_args[term]:
263
            raise CLIError(
264
                'No authentication %s provided for %s cloud' % (term, cloud),
265
                importance=3, details=[
266
                    'Get and set a %s for %s cloud:' % (term, cloud),
267
                    '  kamaki config set remote.%s.%s <t0k3n>' % (term, cloud)
268
                ])
268 269

  
269 270
    from kamaki.clients.astakos import AstakosClient as AuthCachedClient
270 271
    try:
271
        return AuthCachedClient(url, token)
272
        return AuthCachedClient(auth_args['url'], auth_args['token']), cloud
272 273
    except AssertionError as ae:
273
        kloger.warning(
274
            'WARNING: Failed to load auth_url %s [ %s ]' % (url, ae))
275
        return None
274
        kloger.warning('WARNING: Failed to load authenticator [%s]' % ae)
275
        return None, cloud
276 276

  
277 277

  
278 278
def _load_spec_module(spec, arguments, module):
......
417 417

  
418 418
#  CLI Choice:
419 419

  
420
def run_one_cmd(exe_string, parser, auth_base):
420
def run_one_cmd(exe_string, parser, auth_base, cloud):
421 421
    global _history
422 422
    _history = History(
423 423
        parser.arguments['config'].get_global('history_file'))
424 424
    _history.add(' '.join([exe_string] + argv[1:]))
425 425
    from kamaki.cli import one_command
426
    one_command.run(auth_base, parser, _help)
426
    one_command.run(auth_base, cloud, parser, _help)
427 427

  
428 428

  
429
def run_shell(exe_string, parser, auth_base):
429
def run_shell(exe_string, parser, auth_base, cloud):
430 430
    from command_shell import _init_shell
431 431
    shell = _init_shell(exe_string, parser)
432 432
    _load_all_commands(shell.cmd_tree, parser.arguments)
433
    shell.run(auth_base, parser)
433
    shell.run(auth_base, cloud, parser)
434 434

  
435 435

  
436 436
def is_non_API(parser):
......
458 458
        filelog = logger.add_file_logger(__name__.split('.')[0])
459 459
        filelog.info('* Initial Call *\n%s\n- - -' % ' '.join(argv))
460 460

  
461
        remote_base = _init_session(parser.arguments, is_non_API(parser))
461
        auth_base, cloud = _init_session(parser.arguments, is_non_API(parser))
462 462

  
463 463
        from kamaki.cli.utils import suggest_missing
464 464
        suggest_missing()
465 465

  
466 466
        if parser.unparsed:
467
            run_one_cmd(exe, parser, remote_base)
467
            run_one_cmd(exe, parser, auth_base, cloud)
468 468
        elif _help:
469 469
            parser.parser.print_help()
470 470
            _groups_help(parser.arguments)
471 471
        else:
472
            run_shell(exe, parser, remote_base)
472
            run_shell(exe, parser, auth_base, cloud)
473 473
    except CLIError as err:
474 474
        print_error_message(err)
475 475
        if _debug:

Also available in: Unified diff