Commit f5c28bfa authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Backwards compatibility for configuraiton file

Compatible with kamaki config files v2

user.url, file.url, compute.url and image.url
are now valid and of higher priority to
astakos.url, pithos.url, cyclades.url, plankton.url
which are also valid

All these are ignored iff [global].auth_url is given
parent 9d8737a2
......@@ -36,6 +36,7 @@ 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
from kamaki.cli.utils import print_dict
user_cmds = CommandTree('user', 'Astakos API commands')
_commands = [user_cmds]
......@@ -46,16 +47,14 @@ class _user_init(_command_init):
def _run(self):
#token = self.config.get('user', 'token')\
# or self.config.get('global', 'token')
#base_url = self.config.get('global', 'url')
#self.client = AstakosClient(base_url=base_url, token=token)
if getattr(self, 'auth_base', False):
self.client = self.auth_base
token = self.config.get('astakos', 'token')\
token = self.config.get('user', 'token')\
or self.config.get('astakos', 'token')\
or self.config.get('global', 'token')
base_url = self.config.get('astakos', 'url')
base_url = self.config.get('user', 'url')\
or self.config.get('astakos', 'url')
if not base_url:
raise CLIBaseUrlError(service='astakos')
self.client = AstakosClient(base_url=base_url, token=token)
......@@ -77,12 +76,16 @@ class user_authenticate(_user_init, _optional_json):
Token can also be provided as a parameter
def _print_access(r):
def _run(self, custom_token=None):
super(self.__class__, self)._run()
r = self.client.authenticate(custom_token)
self._print([r], title=('uuid', 'name',), with_redundancy=True)
self._print(r, self._print_access)
def main(self, custom_token=None):
......@@ -77,7 +77,8 @@ class _init_cyclades(_command_init):
self.config.get('cyclades', 'version'))
base_url = cyclades_endpoints['publicURL']
base_url = self.config.get('cyclades', 'url')
base_url = self.config.get('compute', 'url')\
or self.config.get('cyclades', 'url')
if not base_url:
raise CLIBaseUrlError(service='cyclades')
......@@ -75,15 +75,17 @@ class _init_image(_command_init):
def _run(self):
token = self.config.get('image', 'token')\
or self.config.get('plankton', 'token')\
or self.config.get('global', 'token')
if getattr(self, 'auth_base', False):
plankton_endpoints = self.auth_base.get_service_endpoints(
self.config.get('plankton', 'type'),
self.config.get('plankton', 'version'))
self.config.get('image', 'type'),
self.config.get('image', 'version'))
base_url = plankton_endpoints['publicURL']
base_url = self.config.get('plankton', 'url')
base_url = self.config.get('image', 'url')\
or self.config.get('plankton', 'url')
if not base_url:
raise CLIBaseUrlError(service='plankton')
......@@ -304,14 +306,13 @@ class image_register(_init_image, _optional_json):
def _get_uuid(self):
def _get_user_id(self):
atoken = self.client.token
#user = AstakosClient(self.config.get('user', 'url'), atoken)
#return user.term('uuid')
if getattr(self, 'auth_base', False):
return self.auth_base.term('id', atoken)
astakos_url = self.config.get('astakos', 'url')
astakos_url = self.config.get('user', 'url')\
or self.config.get('astakos', 'url')
if not astakos_url:
raise CLIBaseUrlError(service='astakos')
user = AstakosClient(astakos_url, atoken)
......@@ -327,10 +328,11 @@ class image_register(_init_image, _optional_json):
self.config.get('pithos', 'version'))
purl = pithos_endpoints['publicURL']
purl = self.config.get('pithos', 'url')
purl = self.config.get('file', 'url')\
or self.config.get('pithos', 'url')
if not purl:
raise CLIBaseUrlError(service='pithos')
return PithosClient(purl, ptoken, self._get_uuid(), container)
return PithosClient(purl, ptoken, self._get_user_id(), container)
def _store_remote_metafile(self, pclient, remote_path, metadata):
return pclient.upload_from_string(
......@@ -160,12 +160,16 @@ class _pithos_init(_command_init):
self.config.get('pithos', 'version'))
self.base_url = pithos_endpoints['publicURL']
self.base_url = self.config.get('pithos', 'url')
self.base_url = self.config.get('file', 'url')\
or self.config.get('store', 'url')\
or self.config.get('pithos', 'url')
if not self.base_url:
raise CLIBaseUrlError(service='pithos')
self.container = self.config.get('file', 'container')\
or self.config.get('store', 'container')\
or self.config.get('pithos', 'container')\
or self.config.get('global', 'container')
self.client = PithosClient(
......@@ -179,10 +183,11 @@ class _pithos_init(_command_init):
def _set_account(self):
if getattr(self, 'base_url', False):
if getattr(self, 'auth_base', False):
self.account = self.auth_base.user_term('id', self.token)
astakos_url = self.config('astakos', 'get')
astakos_url = self.config.get('user', 'url')\
or self.config.get('astakos', 'url')
if not astakos_url:
raise CLIBaseUrlError(service='astakos')
astakos = AstakosClient(astakos_url, self.token)
......@@ -50,7 +50,7 @@ HISTORY_PATH = os.path.expanduser('~/.kamaki.history')
HEADER = """
# Kamaki configuration file v3
# Kamaki configuration file v3 (kamaki >= v0.9)
......@@ -72,6 +72,9 @@ DEFAULTS = {
'image': 'image',
'config': 'config',
'history': 'history'
# Optional command specs:
# 'livetest': 'livetest',
# 'astakos': 'snf-astakos'
'history': {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment