import logging
from sys import argv, exit, stdout
-from os.path import basename
+from os.path import basename, exists
from inspect import getargspec
from kamaki.cli.argument import ArgumentParseManager
def _check_config_version(cnf):
guess = cnf.guess_version()
- if guess < 3.0:
- print('Config file format version >= 3.0 is required')
- print('Configuration file "%s" format is not up to date' % (
- cnf.path))
+ if exists(cnf.path) and guess < 0.9:
+ print('Config file format version >= 9.0 is required')
+ print('Configuration file: %s' % cnf.path)
print('but kamaki can fix this:')
print('Calculating changes while preserving information')
lost_terms = cnf.rescue_old_file()
global _verbose
_verbose = arguments['verbose'].value
_cnf = arguments['config']
+
+ if _help or is_non_API:
+ return None, None
+
_check_config_version(_cnf.value)
global _colors
_silent = arguments['silent'].value
_setup_logging(_silent, _debug, _verbose, _include)
- if _help or is_non_API:
- return None, None
-
- cloud = arguments['cloud'].value or 'default'
+ cloud = arguments['cloud'].value or _cnf.value.get(
+ 'global', 'default_cloud')
+ if not cloud:
+ num_of_clouds = len(_cnf.value.keys('cloud'))
+ if num_of_clouds == 1:
+ cloud = _cnf.value.keys('cloud')[0]
+ elif num_of_clouds > 1:
+ raise CLIError(
+ 'Found %s clouds but none of them is set as default' % (
+ num_of_clouds),
+ importance=2, details=[
+ 'Please, choose one of the following cloud names:',
+ ', '.join(_cnf.value.keys('cloud')),
+ 'To see all cloud settings:',
+ ' kamaki config get cloud.<cloud name>',
+ 'To set a default cloud:',
+ ' kamaki config set default_cloud <cloud name>',
+ 'To pick a cloud for the current session, use --cloud:',
+ ' kamaki --cloud=<cloud name> ...'])
if not cloud in _cnf.value.keys('cloud'):
raise CLIError(
- 'No cloud "%s" is configured' % cloud,
+ 'No cloud%s is configured' % ((' "%s"' % cloud) if cloud else ''),
importance=3, details=[
- 'To configure a new cloud, find and set the',
+ 'To configure a new cloud "%s", find and set the' % (
+ cloud or '<cloud name>'),
'single authentication URL and token:',
- ' kamaki config set cloud.%s.url <URL>' % cloud,
- ' kamaki config set cloud.%s.token <t0k3n>' % cloud])
+ ' kamaki config set cloud.%s.url <URL>' % (
+ cloud or '<cloud name>'),
+ ' kamaki config set cloud.%s.token <t0k3n>' % (
+ cloud or '<cloud name>')])
auth_args = dict()
for term in ('url', 'token'):
- auth_args[term] = _cnf.get_cloud(cloud, term)
+ try:
+ auth_args[term] = _cnf.get_cloud(cloud, term)
+ except KeyError:
+ auth_args[term] = ''
if not auth_args[term]:
raise CLIError(
- 'No authentication %s provided for %s cloud' % (term, cloud),
+ 'No authentication %s provided for cloud "%s"' % (term, cloud),
importance=3, details=[
- 'Get and set a %s for %s cloud:' % (term, cloud),
- ' kamaki config set cloud.%s.%s <t0k3n>' % (term, cloud)
- ])
+ 'Set a %s for cloud %s:' % (term, cloud),
+ ' kamaki config set cloud.%s.%s <%s>' % (
+ cloud, term, term)])
from kamaki.clients.astakos import AstakosClient as AuthCachedClient
try:
auth_base, cloud = _init_session(parser.arguments, is_non_API(parser))
from kamaki.cli.utils import suggest_missing
- suggest_missing()
+ global _colors
+ exclude = ['ansicolors'] if not _colors == 'on' else []
+ suggest_missing(exclude=exclude)
if parser.unparsed:
run_one_cmd(exe, parser, auth_base, cloud)