Commit 31618e2a authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Parse publicURL to fix astakos init, pretty quotas

Refs: #3632
parent 556e6916
...@@ -38,7 +38,7 @@ from kamaki.cli.errors import CLIBaseUrlError ...@@ -38,7 +38,7 @@ from kamaki.cli.errors import CLIBaseUrlError
from kamaki.cli.commands import ( from kamaki.cli.commands import (
_command_init, errors, _optional_json, addLogSettings) _command_init, errors, _optional_json, addLogSettings)
from kamaki.cli.command_tree import CommandTree from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import print_dict from kamaki.cli.utils import print_dict, format_size
from kamaki.cli.argument import FlagArgument, ValueArgument from kamaki.cli.argument import FlagArgument, ValueArgument
from kamaki.cli.logger import get_logger from kamaki.cli.logger import get_logger
...@@ -63,7 +63,8 @@ class _astakos_init(_command_init): ...@@ -63,7 +63,8 @@ class _astakos_init(_command_init):
astakos_endpoints = self.auth_base.get_service_endpoints( astakos_endpoints = self.auth_base.get_service_endpoints(
self._custom_type('astakos') or 'identity', self._custom_type('astakos') or 'identity',
self._custom_version('astakos') or '') self._custom_version('astakos') or '')
base_url = astakos_endpoints['publicURL'] base_url = astakos_endpoints['SNF:uiURL']
base_url = ''.join(base_url.split('/ui'))
else: else:
base_url = self._custom_url('astakos') base_url = self._custom_url('astakos')
if not base_url: if not base_url:
...@@ -142,8 +143,22 @@ class astakos_uuid(_astakos_init, _optional_json): ...@@ -142,8 +143,22 @@ class astakos_uuid(_astakos_init, _optional_json):
class astakos_quotas(_astakos_init, _optional_json): class astakos_quotas(_astakos_init, _optional_json):
"""Get user (or service) quotas""" """Get user (or service) quotas"""
@staticmethod
def _print_with_format(d):
""" Print d with size formating when needed
:param d: (dict) {system: {<service>: {usage: ..., limit: ..., }, ...}}
"""
newd = dict()
for k, service in d['system'].items():
newd[k] = dict(service)
for term in ('usage', 'limit'):
if term in service:
newd[k][term] = format_size(service[term])
print_dict(newd)
def _run(self): def _run(self):
self._print(self.client.get_quotas(self.token), print_dict) self._print(
self.client.get_quotas(self.token), self._print_with_format)
def main(self): def main(self):
super(self.__class__, self)._run() super(self.__class__, self)._run()
......
...@@ -262,6 +262,12 @@ def print_items( ...@@ -262,6 +262,12 @@ def print_items(
""" """
if not items: if not items:
return return
elif not (
isinstance(items, dict) or isinstance(
items, list) or isinstance(items, dict)):
print '%s' % items
return
try: try:
page_size = int(page_size) if int(page_size) > 0 else len(items) page_size = int(page_size) if int(page_size) > 0 else len(items)
except: except:
......
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