global_url = _cnf.get('global', 'auth_url')
global_token = _cnf.get('global', 'token')
from kamaki.clients.astakos import AstakosClient as AuthCachedClient
- return AuthCachedClient(global_url, global_token)
+ try:
+ return AuthCachedClient(global_url, global_token)
+ except AssertionError as ae:
+ kloger.warning('WARNING: Failed to load auth_url %s [ %s ]' % (
+ global_url, ae))
+ return None
def _load_spec_module(spec, arguments, module):
def _create_help_method(cmd_name, args, descr, syntax):
tmp_args = dict(args)
tmp_args.pop('options', None)
+ tmp_args.pop('cloud', None)
tmp_args.pop('debug', None)
tmp_args.pop('verbose', None)
tmp_args.pop('include', None)
# or implied, of GRNET S.A.command
from kamaki.cli import command
-#from kamaki.clients.astakos import AstakosClient
+from kamaki.clients.astakos import AstakosClient
from kamaki.cli.commands import _command_init, errors, _optional_json
from kamaki.cli.command_tree import CommandTree
+from kamaki.cli.errors import CLIBaseUrlError
user_cmds = CommandTree('user', 'Astakos API commands')
_commands = [user_cmds]
# or self.config.get('global', 'token')
#base_url = self.config.get('global', 'url')
#self.client = AstakosClient(base_url=base_url, token=token)
- self.client = self.auth_base
+ if getattr(self, 'auth_base', False):
+ self.client = self.auth_base
+ else:
+ token = self.config.get('astakos', 'token')\
+ or self.config.get('global', 'token')
+ base_url = self.config.get('astakos', 'url')
+ if not base_url:
+ raise CLIBaseUrlError(service='astakos')
+ self.client = AstakosClient(base_url=base_url, token=token)
+
self._set_log_params()
self._update_max_threads()
@errors.user.authenticate
def _run(self, custom_token=None):
super(self.__class__, self)._run()
- r = self.auth_base.authenticate(custom_token)
+ r = self.client.authenticate(custom_token)
self._print([r], title=('uuid', 'name',), with_redundancy=True)
def main(self, custom_token=None):
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import print_dict
-from kamaki.cli.errors import raiseCLIError, CLISyntaxError
+from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
from kamaki.clients.cyclades import CycladesClient, ClientError
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
from kamaki.cli.argument import ProgressBarArgument, DateArgument, IntArgument
def _run(self, service='compute'):
token = self.config.get(service, 'token')\
or self.config.get('global', 'token')
- cyclades_endpoints = self.auth_base.get_service_endpoints(
- self.config.get('cyclades', 'type'),
- self.config.get('cyclades', 'version'))
- base_url = cyclades_endpoints['publicURL']
+
+ if getattr(self, 'auth_base', False):
+ cyclades_endpoints = self.auth_base.get_service_endpoints(
+ self.config.get('cyclades', 'type'),
+ self.config.get('cyclades', 'version'))
+ base_url = cyclades_endpoints['publicURL']
+ else:
+ base_url = self.config.get('cyclades', 'url')
+ if not base_url:
+ raise CLIBaseUrlError(service='cyclades')
+
self.client = CycladesClient(base_url=base_url, token=token)
self._set_log_params()
self._update_max_threads()
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
from kamaki.cli.argument import IntArgument
from kamaki.cli.commands.cyclades import _init_cyclades
-from kamaki.cli.errors import raiseCLIError
+from kamaki.cli.errors import raiseCLIError, CLIBaseUrlError
from kamaki.cli.commands import _command_init, errors
from kamaki.cli.commands import _optional_output_cmd, _optional_json
@errors.generic.all
def _run(self):
token = self.config.get('image', 'token')\
- or self.config.get('compute', 'token')\
or self.config.get('global', 'token')
- plankton_endpoints = self.auth_base.get_service_endpoints(
- self.config.get('plankton', 'type'),
- self.config.get('plankton', 'version'))
- base_url = plankton_endpoints['publicURL']
- #base_url = self.config.get('image', 'url')\
- # or self.config.get('compute', 'url')\
- # or self.config.get('global', 'url')
+
+ if getattr(self, 'auth_base', False):
+ plankton_endpoints = self.auth_base.get_service_endpoints(
+ self.config.get('plankton', 'type'),
+ self.config.get('plankton', 'version'))
+ base_url = plankton_endpoints['publicURL']
+ else:
+ base_url = self.config.get('plankton', 'url')
+ if not base_url:
+ raise CLIBaseUrlError(service='plankton')
+
self.client = ImageClient(base_url=base_url, token=token)
self._set_log_params()
self._update_max_threads()
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
-from kamaki.cli.errors import raiseCLIError, CLISyntaxError
+from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
from kamaki.cli.utils import (
format_size, to_bytes, print_dict, print_items, pretty_keys, pretty_dict,
page_hold, bold, ask_user, get_path_size, print_json)
@staticmethod
def _is_dir(remote_dict):
return 'application/directory' == remote_dict.get(
- 'content_type',
- remote_dict.get('content-type', ''))
+ 'content_type', remote_dict.get('content-type', ''))
@errors.generic.all
def _run(self):
self.token = self.config.get('file', 'token')\
or self.config.get('global', 'token')
- pithos_endpoints = self.auth_base.get_service_endpoints(
- self.config.get('pithos', 'type'),
- self.config.get('pithos', 'version'))
- self.base_url = pithos_endpoints['publicURL']
+
+ if getattr(self, 'auth_base', False):
+ pithos_endpoints = self.auth_base.get_service_endpoints(
+ self.config.get('pithos', 'type'),
+ self.config.get('pithos', 'version'))
+ self.base_url = pithos_endpoints['publicURL']
+ else:
+ self.base_url = self.config.get('pithos', 'url')
+ if not self.base_url:
+ raise CLIBaseUrlError(service='pithos')
+
self._set_account()
self.container = self.config.get('file', 'container')\
or self.config.get('global', 'container')
self.importance = 0
+class CLIBaseUrlError(CLIError):
+ def __init__(self, message='', details=[], importance=2, service=None):
+ message = message or 'No url for %s' % service.lower()
+ details = details or [
+ 'Two options to resolve this:',
+ 'A. (recommended) Let kamaki discover the endpoint URLs for all',
+ 'services by setting a single Authentication URL:',
+ ' /config set auth_url <AUTH_URL>',
+ 'B. (advanced users) Explicitly set a valid %s endpoint URL' % (
+ service.upper()),
+ 'Note: auth_url option has a higher priority, so delete it to',
+ 'make that work',
+ ' /config delete auth_url',
+ ' /config set %s.url <%s_URL>' % (service, service.upper())]
+ super(CLIBaseUrlError, self).__init__(message, details, importance)
+
+
class CLISyntaxError(CLIError):
def __init__(self, message='Syntax Error', details=[], importance=1):
super(CLISyntaxError, self).__init__(message, details, importance)
:returns: (dict) authentication information
"""
self.token = token or self.token
- self._cache[self.token] = self.post('/tokens').json
+ body = dict(auth=dict(token=dict(id=self.token)))
+ self.set_headers('content-type', 'application/json')
+ self._cache[self.token] = self.post('/tokens', data=body).json
return self._cache[self.token]
def get_services(self, token=None):