Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
c825ddc9
Commit
c825ddc9
authored
Jun 12, 2013
by
Stavros Sachtouris
Browse files
Use the default_cloud global option
Refs: #3934 #3979
parent
bb759047
Changes
3
Hide whitespace changes
Inline
Side-by-side
kamaki/cli/__init__.py
View file @
c825ddc9
...
...
@@ -194,8 +194,8 @@ def _setup_logging(silent=False, debug=False, verbose=False, include=False):
def
_check_config_version
(
cnf
):
guess
=
cnf
.
guess_version
()
if
guess
<
3.0
:
print
(
'Config file format version >=
3
.0 is required'
)
if
guess
<
0.9
:
print
(
'Config file format version >=
9
.0 is required'
)
print
(
'Configuration file "%s" format is not up to date'
%
(
cnf
.
path
))
print
(
'but kamaki can fix this:'
)
...
...
@@ -247,7 +247,22 @@ def _init_session(arguments, is_non_API=False):
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
]
else
:
raise
CLIError
(
'Found %s clouds but none of them is set as default'
,
importance
=
2
,
details
=
[
'Please, choose one of the following cloud names:'
,
', '
.
join
(
_cnf
.
value
.
keys
(
'cloud'
)),
'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
,
...
...
@@ -258,14 +273,16 @@ def _init_session(arguments, is_non_API=False):
' kamaki config set cloud.%s.token <t0k3n>'
%
cloud
])
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 <t0k3n>'
%
(
cloud
,
term
)])
from
kamaki.clients.astakos
import
AstakosClient
as
AuthCachedClient
try
:
...
...
kamaki/cli/config.py
View file @
c825ddc9
...
...
@@ -61,7 +61,7 @@ for c in '%s' % __version__:
if
c
not
in
'0.123456789'
:
break
version
+=
c
HEADER
=
'# Kamaki configuration file v%s'
%
version
HEADER
=
'# Kamaki configuration file v%s
\n
'
%
version
DEFAULTS
=
{
'global'
:
{
...
...
@@ -156,7 +156,10 @@ class Config(RawConfigParser):
self
.
remove_option
(
s
,
term
)
continue
gval
=
self
.
get
(
s
,
term
)
cval
=
self
.
get_cloud
(
'default'
,
term
)
try
:
cval
=
self
.
get_cloud
(
'default'
,
term
)
except
KeyError
:
cval
=
''
if
gval
and
cval
and
(
gval
.
lower
().
strip
(
'/'
)
!=
cval
.
lower
().
strip
(
'/'
)):
raise
CLISyntaxError
(
...
...
@@ -225,13 +228,13 @@ class Config(RawConfigParser):
if
'global'
in
sections
:
if
checker
.
get
(
'global'
,
'url'
)
or
checker
.
get
(
'global'
,
'token'
):
log
.
warning
(
'..... config file has an old global section'
)
return
8.0
return
0.8
log
.
warning
(
'........ nope'
)
log
.
warning
(
'Config file heuristic 2: missing all cloud sections ?'
)
if
'cloud'
in
sections
:
for
r
in
self
.
keys
(
'cloud'
):
log
.
warning
(
'... found cloud "%s"'
%
r
)
return
9.0
return
0.9
log
.
warning
(
'........ yep'
)
log
.
warning
(
'All heuristics failed, cannot decide'
)
return
0.0
...
...
kamaki/cli/errors.py
View file @
c825ddc9
...
...
@@ -76,6 +76,7 @@ class CLIBaseUrlError(CLIError):
message
=
message
or
'No url for %s'
%
service
.
lower
()
details
=
details
or
[
'Two options to resolve this:'
,
'(Use the correct cloud name, instead of "default")'
,
'A. (recommended) Let kamaki discover the endpoint URLs for all'
,
'services by setting a single Authentication URL and token:'
,
' /config set cloud.default.url <AUTH_URL>'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment