Skip to content

Commit

Permalink
Rename base_url,auth_base to endpoint_url,astakos
Browse files Browse the repository at this point in the history
Refs: grnet#9

This change affects both the kamaki.cli and kamaki.clients hierarchies
It is of semantic significance only
Backwards compatibility is preserved in kamaki.clients, so that
old code using base_url instead of endpoint_url will still work.
  • Loading branch information
saxtouri committed Apr 9, 2014
1 parent 21ec101 commit 5344af0
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 106 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Features:
- Resources can be reassigned to projects
- Update account API commands to reflect changes in synnefo 0.16
- Implement a get_endpoint_url method and use it
- Rename kamaki.clients.Client.base_url --> endpoint_url, keep BW compatibility [#9]

19 changes: 9 additions & 10 deletions kamaki/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,19 @@ def init_cached_authenticator(config_argument, cloud, logger):
_cnf = config_argument.value
url = _cnf.get_cloud(cloud, 'url')
tokens = _cnf.get_cloud(cloud, 'token').split()
auth_base, failed = None, []
astakos, failed = None, []
for token in tokens:
try:
if auth_base:
auth_base.authenticate(token)
if astakos:
astakos.authenticate(token)
else:
tmp_base = CachedAstakosClient(url, token)
from kamaki.cli.cmds import CommandInit
fake_cmd = CommandInit(dict(config=config_argument))
fake_cmd.client = auth_base
fake_cmd.client = astakos
fake_cmd._set_log_params()
tmp_base.authenticate(token)
auth_base = tmp_base
astakos = tmp_base
except ClientError as ce:
if ce.status in (401, ):
logger.warning(
Expand All @@ -324,7 +324,7 @@ def init_cached_authenticator(config_argument, cloud, logger):
_cnf.set_cloud(cloud, 'token', ' '.join(tokens))
_cnf.write()
if tokens:
return auth_base
return astakos
logger.warning('WARNING: cloud.%s.token is now empty' % cloud)
except AssertionError as ae:
logger.warning('WARNING: Failed to load authenticator [%s]' % ae)
Expand Down Expand Up @@ -548,16 +548,15 @@ def run_shell(exe, parser):
cloud = _init_session(parser.arguments)
global kloger
_cnf = parser.arguments['config']
auth_base = init_cached_authenticator(_cnf, cloud, kloger)
astakos = init_cached_authenticator(_cnf, cloud, kloger)
try:
username, userid = (
auth_base.user_term('name'), auth_base.user_term('id'))
username, userid = (astakos.user_term('name'), astakos.user_term('id'))
except Exception:
username, userid = '', ''
from kamaki.cli.shell import init_shell
shell = init_shell(exe, parser, username, userid)
_load_all_commands(shell.cmd_tree, parser.arguments)
shell.run(auth_base, cloud, parser)
shell.run(astakos, cloud, parser)


@main
Expand Down
10 changes: 5 additions & 5 deletions kamaki/cli/cmds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CommandInit(object):

def __init__(
self,
arguments={}, auth_base=None, cloud=None,
arguments={}, astakos=None, cloud=None,
_in=None, _out=None, _err=None):
self._in, self._out, self._err = (
_in or stdin, _out or stdout, _err or stderr)
Expand All @@ -113,14 +113,14 @@ def __init__(
self.config = self['config']
except KeyError:
pass
self.auth_base = auth_base or getattr(self, 'auth_base', None)
self.astakos = astakos or getattr(self, 'astakos', None)
self.cloud = cloud or getattr(self, 'cloud', None)

def get_client(self, cls, service):
self.cloud = getattr(self, 'cloud', 'default')
URL, TOKEN = self._custom_url(service), self._custom_token(service)
if not all([URL, TOKEN]):
astakos = getattr(self, 'auth_base', None)
astakos = getattr(self, 'astakos', None)
if astakos:
URL = URL or astakos.get_endpoint_url(
self._custom_type(service) or cls.service_type,
Expand Down Expand Up @@ -180,10 +180,10 @@ def _custom_version(self, service):
return self.config.get_cloud(self.cloud, '%s_version' % service)

def _uuids2usernames(self, uuids):
return self.auth_base.post_user_catalogs(uuids)
return self.astakos.post_user_catalogs(uuids)

def _usernames2uuids(self, username):
return self.auth_base.post_user_catalogs(displaynames=username)
return self.astakos.post_user_catalogs(displaynames=username)

def _uuid2username(self, uuid):
return self._uuids2usernames([uuid]).get(uuid, None)
Expand Down
44 changes: 22 additions & 22 deletions kamaki/cli/cmds/astakos.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ class _AstakosInit(CommandInit):
@client_log
def _run(self):
if getattr(self, 'cloud', None):
base_url = self._custom_url('astakos')
if base_url:
endpoint_url = self._custom_url('astakos')
if endpoint_url:
token = self._custom_token(
'astakos') or self.config.get_cloud(
self.cloud, 'token')
token = token.split()[0] if ' ' in token else token
self.client = LoggedAstakosClient(base_url, token)
self.client = LoggedAstakosClient(endpoint_url, token)
return
else:
self.cloud = 'default'
if getattr(self, 'auth_base', None):
self.client = self.auth_base.get_client()
if getattr(self, 'astakos', None):
self.client = self.astakos.get_client()
return
raise CLIBaseUrlError(service='astakos')

Expand Down Expand Up @@ -238,7 +238,7 @@ def _run(self):
uuid = self['uuid'] or (self._username2uuid(self['name']) if (
self['name']) else None)
try:
token = self.auth_base.get_token(uuid) if uuid else None
token = self.astakos.get_token(uuid) if uuid else None
except KeyError:
msg = ('id %s' % self['uuid']) if (
self['uuid']) else 'username %s' % self['name']
Expand All @@ -248,7 +248,7 @@ def _run(self):
' /user list',
'To authenticate and add a new user in the session list',
' /user add <new token>'])
self.print_(self.auth_base.user_info(token), self.print_dict)
self.print_(self.astakos.user_info(token), self.print_dict)


@command(user_cmds)
Expand All @@ -258,16 +258,16 @@ class user_add(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, token=None):
ask = token and token not in self.auth_base._uuids
self.print_(self.auth_base.authenticate(token), self.print_dict)
ask = token and token not in self.astakos._uuids
self.print_(self.astakos.authenticate(token), self.print_dict)
if ask and self.ask_user(
'Token is temporarily stored in memory. If it is stored in'
' kamaki configuration file, it will be available in later'
' sessions. Do you want to permanently store this token?'):
tokens = self.auth_base._uuids.keys()
tokens.remove(self.auth_base.token)
tokens = self.astakos._uuids.keys()
tokens.remove(self.astakos.token)
self['config'].set_cloud(
self.cloud, 'token', ' '.join([self.auth_base.token] + tokens))
self.cloud, 'token', ' '.join([self.astakos.token] + tokens))
self['config'].write()

def main(self, new_token=None):
Expand All @@ -287,7 +287,7 @@ class user_list(_AstakosInit, OptionalOutput):
@errors.Astakos.astakosclient
def _run(self):
self.print_([u if self['detail'] else (dict(
id=u['id'], name=u['name'])) for u in self.auth_base.list_users()])
id=u['id'], name=u['name'])) for u in self.astakos.list_users()])

def main(self):
super(self.__class__, self)._run()
Expand All @@ -302,7 +302,7 @@ class user_select(_AstakosInit):
@errors.Astakos.astakosclient
def _run(self, uuid):
try:
first_token = self.auth_base.get_token(uuid)
first_token = self.astakos.get_token(uuid)
except KeyError:
raise CLIError(
'No user with uuid %s in the cached session list' % uuid,
Expand All @@ -311,14 +311,14 @@ def _run(self, uuid):
' /user list',
'To authenticate and add a new user in the session list',
' /user add <new token>'])
if self.auth_base.token != first_token:
self.auth_base.token = first_token
if self.astakos.token != first_token:
self.astakos.token = first_token
msg = 'User with id %s is now the current session user.\n' % uuid
msg += 'Do you want future sessions to also start with this user?'
if self.ask_user(msg):
tokens = self.auth_base._uuids.keys()
tokens.remove(self.auth_base.token)
tokens.insert(0, self.auth_base.token)
tokens = self.astakos._uuids.keys()
tokens.remove(self.astakos.token)
tokens.insert(0, self.astakos.token)
self['config'].set_cloud(
self.cloud, 'token', ' '.join(tokens))
self['config'].write()
Expand All @@ -340,7 +340,7 @@ class user_delete(_AstakosInit):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, uuid):
if uuid == self.auth_base.user_term('id'):
if uuid == self.astakos.user_term('id'):
raise CLIError('Cannot remove current session user', details=[
'To see all cached session users',
' /user list',
Expand All @@ -349,7 +349,7 @@ def _run(self, uuid):
'To select a different session user',
' /user select <user uuid>'])
try:
self.auth_base.remove_user(uuid)
self.astakos.remove_user(uuid)
except KeyError:
raise CLIError('No user with uuid %s in session list' % uuid,
details=[
Expand All @@ -361,7 +361,7 @@ def _run(self, uuid):
'User is removed from current session, but will be restored in'
' the next session. Remove the user from future sessions?'):
self['config'].set_cloud(
self.cloud, 'token', ' '.join(self.auth_base._uuids.keys()))
self.cloud, 'token', ' '.join(self.astakos._uuids.keys()))
self['config'].write()

def main(self, user_uuid):
Expand Down
4 changes: 2 additions & 2 deletions kamaki/cli/cmds/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _raise(self, *args, **kwargs):
client = getattr(self, 'client', None)
if not client:
raise
url = getattr(client, 'base_url', '<empty>')
url = getattr(client, 'endpoint_url', '<empty>')
raise CLIError('Invalid service URL %s' % url, details=[
'%s' % ce,
'Check if authentication URL is correct',
Expand Down Expand Up @@ -136,7 +136,7 @@ def _raise(self, *args, **kwargs):
log.warning(
'No permanent token (try:'
' kamaki config set cloud.default.token <tkn>)')
if not getattr(client, 'astakos_base_url', False):
if not getattr(client, 'astakos_endpoint_url', False):
msg = 'Missing synnefo authentication URL'
raise CLIError(msg, importance=3, details=[
'Check if authentication URL is correct',
Expand Down
4 changes: 2 additions & 2 deletions kamaki/cli/cmds/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def _run(self, name, locator):
def main(self):
super(self.__class__, self)._run()
locator, pithos = self.arguments['pithos_location'], None
locator.setdefault('uuid', self.auth_base.user_term('id'))
locator.setdefault('uuid', self.astakos.user_term('id'))
locator.path = locator.path or path.basename(
self['local_image_path'] or '')
if not locator.path:
Expand All @@ -561,7 +561,7 @@ def main(self):
self.arguments['local_image_path'].lvalue)
])
self.arguments['pithos_location'].setdefault(
'uuid', self.auth_base.user_term('id'))
'uuid', self.astakos.user_term('id'))
self._run(self['name'], locator)


Expand Down
25 changes: 13 additions & 12 deletions kamaki/cli/cmds/pithos.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _set_account(self):
self.account = self._custom_uuid()
if self.account:
return
astakos = getattr(self, 'auth_base', None)
astakos = getattr(self, 'astakos', None)
if astakos:
self.account = astakos.user_term('id', self.token)
else:
Expand All @@ -87,7 +87,8 @@ def _set_account(self):
@client_log
def _run(self):
self.client = self.get_client(PithosClient, 'pithos')
self.base_url, self.token = self.client.base_url, self.client.token
self.endpoint_url = self.client.endpoint_url
self.token = self.client.token
self._set_account()
self.client.account = self.account
self.container = self._custom_container() or 'pithos'
Expand All @@ -100,11 +101,11 @@ def main(self):
class _PithosAccount(_PithosInit):
"""Setup account"""

def __init__(self, arguments={}, auth_base=None, cloud=None):
super(_PithosAccount, self).__init__(arguments, auth_base, cloud)
def __init__(self, arguments={}, astakos=None, cloud=None):
super(_PithosAccount, self).__init__(arguments, astakos, cloud)
self['account'] = UserAccountArgument(
'A user UUID or name', ('-A', '--account'))
self.arguments['account'].account_client = auth_base
self.arguments['account'].account_client = astakos

def print_objects(self, object_list):
for index, obj in enumerate(object_list):
Expand Down Expand Up @@ -143,8 +144,8 @@ def _run(self):
class _PithosContainer(_PithosAccount):
"""Setup container"""

def __init__(self, arguments={}, auth_base=None, cloud=None):
super(_PithosContainer, self).__init__(arguments, auth_base, cloud)
def __init__(self, arguments={}, astakos=None, cloud=None):
super(_PithosContainer, self).__init__(arguments, astakos, cloud)
self['container'] = ValueArgument(
'Use this container (default: pithos)', ('-C', '--container'))

Expand Down Expand Up @@ -502,12 +503,12 @@ class _PithosFromTo(_PithosContainer):
'The version of the source object', '--source-version')
)

def __init__(self, arguments={}, auth_base=None, cloud=None):
def __init__(self, arguments={}, astakos=None, cloud=None):
self.arguments.update(arguments)
self.arguments.update(self.sd_arguments)
super(_PithosFromTo, self).__init__(
self.arguments, auth_base, cloud)
self.arguments['destination_user'].account_client = self.auth_base
self.arguments, astakos, cloud)
self.arguments['destination_user'].account_client = self.astakos

def _report_transfer(self, src, dst, transfer_name):
if not dst:
Expand Down Expand Up @@ -637,7 +638,7 @@ def _run(self, source_path_or_url, destination_path_or_url=''):
dst_acc, dst_con, dst_path = self.resolve_pithos_url(
destination_path_or_url)
self.dst_client = PithosClient(
base_url=self.client.base_url, token=self.client.token,
endpoint_url=self.client.endpoint_url, token=self.client.token,
container=self[
'destination_container'] or dst_con or self.client.container,
account=self['destination_user'] or dst_acc or self.account)
Expand Down Expand Up @@ -1667,7 +1668,7 @@ def main(self, account_uuid_or_name=None):
super(self.__class__, self)._run()
if account_uuid_or_name:
arg = UserAccountArgument('Check', ' ')
arg.account_client = self.auth_base
arg.account_client = self.astakos
arg.value = account_uuid_or_name
self.client.account, self.account = arg.value, arg.value
self._run()
Expand Down
4 changes: 2 additions & 2 deletions kamaki/cli/one_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def run(cloud, parser):
exit(0)

cls = cmd.cmd_class
auth_base = init_cached_authenticator(_cnf, cloud, kloger) if (
astakos = init_cached_authenticator(_cnf, cloud, kloger) if (
cloud) else None
executable = cls(parser.arguments, auth_base, cloud)
executable = cls(parser.arguments, astakos, cloud)
parser.required = getattr(cls, 'required', None)
parser.update_arguments(executable.arguments)
for term in _best_match:
Expand Down
10 changes: 5 additions & 5 deletions kamaki/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Shell(Cmd):
_context_stack = []
_prompt_stack = []
_parser = None
auth_base = None
astakos = None
cloud = None

undoc_header = 'interactive shell commands:'
Expand Down Expand Up @@ -204,12 +204,12 @@ def do_method(new_context, line):
ldescr = getattr(cls, 'long_description', '')
if subcmd.path == 'history_run':
instance = cls(
dict(cmd_parser.arguments), self.auth_base,
dict(cmd_parser.arguments), self.astakos,
cmd_tree=self.cmd_tree)
else:
instance = cls(
dict(cmd_parser.arguments),
self.auth_base, self.cloud)
self.astakos, self.cloud)
cmd_parser.update_arguments(instance.arguments)
cmd_parser.arguments = instance.arguments
subpath = subcmd.path.split('_')[
Expand Down Expand Up @@ -303,8 +303,8 @@ def doc_header(self):
hdr = tmp_partition[0].strip()
return '%s commands:' % hdr

def run(self, auth_base, cloud, parser, path=''):
self.auth_base = auth_base
def run(self, astakos, cloud, parser, path=''):
self.astakos = astakos
self.cloud = cloud
self._parser = parser
cnf = parser.arguments['config']
Expand Down
Loading

0 comments on commit 5344af0

Please sign in to comment.