Revision c825ddc9
b/kamaki/cli/__init__.py | ||
---|---|---|
194 | 194 |
|
195 | 195 |
def _check_config_version(cnf): |
196 | 196 |
guess = cnf.guess_version() |
197 |
if guess < 3.0:
|
|
198 |
print('Config file format version >= 3.0 is required')
|
|
197 |
if guess < 0.9:
|
|
198 |
print('Config file format version >= 9.0 is required')
|
|
199 | 199 |
print('Configuration file "%s" format is not up to date' % ( |
200 | 200 |
cnf.path)) |
201 | 201 |
print('but kamaki can fix this:') |
... | ... | |
247 | 247 |
if _help or is_non_API: |
248 | 248 |
return None, None |
249 | 249 |
|
250 |
cloud = arguments['cloud'].value or 'default' |
|
250 |
cloud = arguments['cloud'].value or _cnf.value.get( |
|
251 |
'global', 'default_cloud') |
|
252 |
if not cloud: |
|
253 |
num_of_clouds = len(_cnf.value.keys('cloud')) |
|
254 |
if num_of_clouds == 1: |
|
255 |
cloud = _cnf.value.keys('cloud')[0] |
|
256 |
else: |
|
257 |
raise CLIError( |
|
258 |
'Found %s clouds but none of them is set as default', |
|
259 |
importance=2, details=[ |
|
260 |
'Please, choose one of the following cloud names:', |
|
261 |
', '.join(_cnf.value.keys('cloud')), |
|
262 |
'To set a default cloud:', |
|
263 |
' kamaki config set default_cloud <cloud name>', |
|
264 |
'To pick a cloud for the current session, use --cloud:', |
|
265 |
' kamaki --cloud=<cloud name> ...']) |
|
251 | 266 |
if not cloud in _cnf.value.keys('cloud'): |
252 | 267 |
raise CLIError( |
253 | 268 |
'No cloud "%s" is configured' % cloud, |
... | ... | |
258 | 273 |
' kamaki config set cloud.%s.token <t0k3n>' % cloud]) |
259 | 274 |
auth_args = dict() |
260 | 275 |
for term in ('url', 'token'): |
261 |
auth_args[term] = _cnf.get_cloud(cloud, term) |
|
276 |
try: |
|
277 |
auth_args[term] = _cnf.get_cloud(cloud, term) |
|
278 |
except KeyError: |
|
279 |
auth_args[term] = '' |
|
262 | 280 |
if not auth_args[term]: |
263 | 281 |
raise CLIError( |
264 |
'No authentication %s provided for %s cloud' % (term, cloud),
|
|
282 |
'No authentication %s provided for cloud "%s"' % (term, cloud),
|
|
265 | 283 |
importance=3, details=[ |
266 |
'Get and set a %s for %s cloud:' % (term, cloud), |
|
267 |
' kamaki config set cloud.%s.%s <t0k3n>' % (term, cloud) |
|
268 |
]) |
|
284 |
'Set a %s for cloud %s:' % (term, cloud), |
|
285 |
' kamaki config set cloud.%s.%s <t0k3n>' % (cloud, term)]) |
|
269 | 286 |
|
270 | 287 |
from kamaki.clients.astakos import AstakosClient as AuthCachedClient |
271 | 288 |
try: |
b/kamaki/cli/config.py | ||
---|---|---|
61 | 61 |
if c not in '0.123456789': |
62 | 62 |
break |
63 | 63 |
version += c |
64 |
HEADER = '# Kamaki configuration file v%s' % version |
|
64 |
HEADER = '# Kamaki configuration file v%s\n' % version
|
|
65 | 65 |
|
66 | 66 |
DEFAULTS = { |
67 | 67 |
'global': { |
... | ... | |
156 | 156 |
self.remove_option(s, term) |
157 | 157 |
continue |
158 | 158 |
gval = self.get(s, term) |
159 |
cval = self.get_cloud('default', term) |
|
159 |
try: |
|
160 |
cval = self.get_cloud('default', term) |
|
161 |
except KeyError: |
|
162 |
cval = '' |
|
160 | 163 |
if gval and cval and ( |
161 | 164 |
gval.lower().strip('/') != cval.lower().strip('/')): |
162 | 165 |
raise CLISyntaxError( |
... | ... | |
225 | 228 |
if 'global' in sections: |
226 | 229 |
if checker.get('global', 'url') or checker.get('global', 'token'): |
227 | 230 |
log.warning('..... config file has an old global section') |
228 |
return 8.0
|
|
231 |
return 0.8
|
|
229 | 232 |
log.warning('........ nope') |
230 | 233 |
log.warning('Config file heuristic 2: missing all cloud sections ?') |
231 | 234 |
if 'cloud' in sections: |
232 | 235 |
for r in self.keys('cloud'): |
233 | 236 |
log.warning('... found cloud "%s"' % r) |
234 |
return 9.0
|
|
237 |
return 0.9
|
|
235 | 238 |
log.warning('........ yep') |
236 | 239 |
log.warning('All heuristics failed, cannot decide') |
237 | 240 |
return 0.0 |
b/kamaki/cli/errors.py | ||
---|---|---|
76 | 76 |
message = message or 'No url for %s' % service.lower() |
77 | 77 |
details = details or [ |
78 | 78 |
'Two options to resolve this:', |
79 |
'(Use the correct cloud name, instead of "default")', |
|
79 | 80 |
'A. (recommended) Let kamaki discover the endpoint URLs for all', |
80 | 81 |
'services by setting a single Authentication URL and token:', |
81 | 82 |
' /config set cloud.default.url <AUTH_URL>', |
Also available in: Unified diff