Revision 49c07ce3 image_creator/dialog_menu.py
b/image_creator/dialog_menu.py | ||
---|---|---|
48 | 48 |
from image_creator.help import get_help_file |
49 | 49 |
from image_creator.dialog_util import SMALL_WIDTH, WIDTH, \ |
50 | 50 |
update_background_title, confirm_reset, confirm_exit, Reset, \ |
51 |
extract_image, extract_metadata_string |
|
51 |
extract_image, extract_metadata_string, add_cloud, edit_cloud
|
|
52 | 52 |
|
53 | 53 |
CONFIGURATION_TASKS = [ |
54 | 54 |
("Partition table manipulation", ["FixPartitionTable"], |
... | ... | |
119 | 119 |
size = image.size |
120 | 120 |
|
121 | 121 |
if "account" not in session: |
122 |
d.msgbox("You need to provide your ~okeanos credentials before you "
|
|
123 |
"can upload images to pithos+", width=SMALL_WIDTH)
|
|
122 |
d.msgbox("You need to select a valid cloud before you can upload "
|
|
123 |
"images to pithos+", width=SMALL_WIDTH) |
|
124 | 124 |
return False |
125 | 125 |
|
126 | 126 |
while 1: |
... | ... | |
204 | 204 |
is_public = False |
205 | 205 |
|
206 | 206 |
if "account" not in session: |
207 |
d.msgbox("You need to provide your ~okeanos credentians before you "
|
|
207 |
d.msgbox("You need to select a valid cloud before you "
|
|
208 | 208 |
"can register an images with cyclades", width=SMALL_WIDTH) |
209 | 209 |
return False |
210 | 210 |
|
... | ... | |
277 | 277 |
return True |
278 | 278 |
|
279 | 279 |
|
280 |
def modify_clouds(session): |
|
281 |
"""Modify existing cloud accounts""" |
|
282 |
d = session['dialog'] |
|
283 |
|
|
284 |
while 1: |
|
285 |
clouds = Kamaki.get_clouds() |
|
286 |
if not len(clouds): |
|
287 |
if not add_cloud(session): |
|
288 |
break |
|
289 |
continue |
|
290 |
|
|
291 |
choices = [] |
|
292 |
for (name, cloud) in clouds.items(): |
|
293 |
descr = cloud['description'] if 'description' in cloud else '' |
|
294 |
choices.append((name, descr)) |
|
295 |
|
|
296 |
(code, choice) = d.menu( |
|
297 |
"In this menu you can edit existing cloud accounts or add new " |
|
298 |
" ones. Press <Edit> to edit an existing account or <Add> to add " |
|
299 |
" a new one. Press <Back> or hit <ESC> when done.", height=18, |
|
300 |
width=WIDTH, choices=choices, menu_height=10, ok_label="Edit", |
|
301 |
extra_button=1, extra_label="Add", cancel="Back", help_button=1, |
|
302 |
title="Clouds") |
|
303 |
|
|
304 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
305 |
return True |
|
306 |
elif code == d.DIALOG_OK: # Edit button |
|
307 |
edit_cloud(session, choice) |
|
308 |
elif code == d.DIALOG_EXTRA: # Add button |
|
309 |
add_cloud(session) |
|
310 |
|
|
311 |
|
|
312 |
def delete_clouds(session): |
|
313 |
"""Delete existing cloud accounts""" |
|
314 |
d = session['dialog'] |
|
315 |
|
|
316 |
choices = [] |
|
317 |
for (name, cloud) in Kamaki.get_clouds().items(): |
|
318 |
descr = cloud['description'] if 'description' in cloud else '' |
|
319 |
choices.append((name, descr, 0)) |
|
320 |
|
|
321 |
if len(choices) == 0: |
|
322 |
d.msgbox("No available clouds to delete!", width=SMALL_WIDTH) |
|
323 |
return True |
|
324 |
|
|
325 |
(code, to_delete) = d.checklist("Choose which cloud accounts to delete:", |
|
326 |
choices=choices, width=WIDTH) |
|
327 |
|
|
328 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
329 |
return False |
|
330 |
|
|
331 |
if not len(to_delete): |
|
332 |
d.msgbox("Nothing selected!", width=SMALL_WIDTH) |
|
333 |
return False |
|
334 |
|
|
335 |
if not d.yesno("Are you sure you want to remove the selected cloud " |
|
336 |
"accounts?", width=WIDTH, defaultno=1): |
|
337 |
for i in to_delete: |
|
338 |
Kamaki.remove_cloud(i) |
|
339 |
if 'cloud' in session and session['cloud'] == i: |
|
340 |
del session['cloud'] |
|
341 |
if 'account' in session: |
|
342 |
del session['account'] |
|
343 |
else: |
|
344 |
return False |
|
345 |
|
|
346 |
d.msgbox("%d cloud accounts were deleted." % len(to_delete), |
|
347 |
width=SMALL_WIDTH) |
|
348 |
return True |
|
349 |
|
|
350 |
|
|
280 | 351 |
def kamaki_menu(session): |
281 | 352 |
"""Show kamaki related actions""" |
282 | 353 |
d = session['dialog'] |
283 |
default_item = "Account"
|
|
354 |
default_item = "Cloud"
|
|
284 | 355 |
|
285 |
if 'account' not in session: |
|
286 |
token = Kamaki.get_token() |
|
287 |
if token: |
|
288 |
session['account'] = Kamaki.get_account(token) |
|
356 |
if 'cloud' not in session: |
|
357 |
cloud = Kamaki.get_default_cloud_name() |
|
358 |
if cloud: |
|
359 |
session['cloud'] = cloud |
|
360 |
session['account'] = Kamaki.get_account(cloud) |
|
289 | 361 |
if not session['account']: |
290 | 362 |
del session['account'] |
291 |
Kamaki.save_token('') # The token was not valid. Remove it |
|
363 |
else: |
|
364 |
default_item = "Add/Edit" |
|
292 | 365 |
|
293 | 366 |
while 1: |
294 |
account = session["account"]['username'] if "account" in session else \ |
|
295 |
"<none>" |
|
367 |
cloud = session["cloud"] if "cloud" in session else "<none>" |
|
368 |
if 'account' not in session and 'cloud' in session: |
|
369 |
cloud += " <invalid>" |
|
370 |
|
|
296 | 371 |
upload = session["upload"] if "upload" in session else "<none>" |
297 | 372 |
|
298 |
choices = [("Account", "Change your ~okeanos account: %s" % account), |
|
373 |
choices = [("Add/Edit", "Add/Edit cloud accounts"), |
|
374 |
("Delete", "Delete existing cloud accounts"), |
|
375 |
("Cloud", "Select cloud account to use: %s" % cloud), |
|
299 | 376 |
("Upload", "Upload image to pithos+"), |
300 | 377 |
("Register", "Register the image to cyclades: %s" % upload)] |
301 | 378 |
|
... | ... | |
308 | 385 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
309 | 386 |
return False |
310 | 387 |
|
311 |
if choice == "Account": |
|
312 |
default_item = "Account" |
|
313 |
(code, answer) = d.inputbox( |
|
314 |
"Please provide your ~okeanos authentication token:", |
|
315 |
init=session["account"]['auth_token'] if "account" in session |
|
316 |
else '', width=WIDTH) |
|
388 |
if choice == "Add/Edit": |
|
389 |
if modify_clouds(session): |
|
390 |
default_item = "Cloud" |
|
391 |
elif choice == "Delete": |
|
392 |
if delete_clouds(session): |
|
393 |
if len(Kamaki.get_clouds()): |
|
394 |
default_item = "Cloud" |
|
395 |
else: |
|
396 |
default_time = "Add/Edit" |
|
397 |
else: |
|
398 |
default_time = "Delete" |
|
399 |
elif choice == "Cloud": |
|
400 |
default_item = "Cloud" |
|
401 |
clouds = Kamaki.get_clouds() |
|
402 |
if not len(clouds): |
|
403 |
d.msgbox("No clouds available. Please add a new cloud!", |
|
404 |
width=SMALL_WIDTH) |
|
405 |
default_item = "Add/Edit" |
|
406 |
continue |
|
407 |
|
|
408 |
if 'cloud' not in session: |
|
409 |
session['cloud'] = clouds.keys()[0] |
|
410 |
|
|
411 |
choices = [] |
|
412 |
for name, info in clouds.items(): |
|
413 |
default = 1 if session['cloud'] == name else 0 |
|
414 |
descr = info['description'] if 'description' in info else "" |
|
415 |
choices.append((name, descr, default)) |
|
416 |
|
|
417 |
(code, answer) = d.radiolist("Please select a cloud:", |
|
418 |
width=WIDTH, choices=choices) |
|
317 | 419 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
318 | 420 |
continue |
319 |
if len(answer) == 0 and "account" in session: |
|
320 |
del session["account"] |
|
321 | 421 |
else: |
322 |
token = answer.strip() |
|
323 |
session['account'] = Kamaki.get_account(token) |
|
422 |
session['account'] = Kamaki.get_account(answer) |
|
423 |
|
|
424 |
if session['account'] is None: # invalid account |
|
425 |
if not d.yesno("The cloud %s' is not valid! Would you " |
|
426 |
"like to edit it?" % answer, width=WIDTH): |
|
427 |
if edit_cloud(session, answer): |
|
428 |
session['account'] = Kamaki.get_account(answer) |
|
429 |
Kamaki.set_default_cloud(answer) |
|
430 |
|
|
324 | 431 |
if session['account'] is not None: |
325 |
Kamaki.save_token(token) |
|
432 |
session['cloud'] = answer |
|
433 |
Kamaki.set_default_cloud(answer) |
|
326 | 434 |
default_item = "Upload" |
327 | 435 |
else: |
328 | 436 |
del session['account'] |
329 |
d.msgbox("The token you provided is not valid!", |
|
330 |
width=SMALL_WIDTH) |
|
437 |
del session['cloud'] |
|
331 | 438 |
elif choice == "Upload": |
332 | 439 |
if upload_image(session): |
333 | 440 |
default_item = "Register" |
... | ... | |
668 | 775 |
|
669 | 776 |
update_background_title(session) |
670 | 777 |
|
671 |
choices = [("Customize", "Customize image & ~okeanos deployment options"),
|
|
672 |
("Register", "Register image to ~okeanos"),
|
|
778 |
choices = [("Customize", "Customize image & cloud deployment options"),
|
|
779 |
("Register", "Register image to a cloud"),
|
|
673 | 780 |
("Extract", "Dump image to local file system"), |
674 | 781 |
("Reset", "Reset everything and start over again"), |
675 | 782 |
("Help", "Get help for using snf-image-creator")] |
Also available in: Unified diff