Revision f9d8c3d9 image_creator/dialog_main.py
b/image_creator/dialog_main.py | ||
---|---|---|
50 | 50 |
MSGBOX_WIDTH = 60 |
51 | 51 |
YESNO_WIDTH = 50 |
52 | 52 |
MENU_WIDTH = 70 |
53 |
INPUTBOX_WIDTH=70 |
|
53 |
INPUTBOX_WIDTH = 70 |
|
54 |
|
|
55 |
CONFIGURATION_TASKS = { |
|
56 |
"FixPartitionTable": |
|
57 |
"Enlarge last partition to use all the available space", |
|
58 |
"FilesystemResizeUnmounted": |
|
59 |
"Resize file system to use all the available space", |
|
60 |
"AddSwap": "Set up the swap partition and add an entry in fstab", |
|
61 |
"DeleteSSHKeys": "Remove ssh keys and in some cases recreate them", |
|
62 |
"DisableRemoteDesktopConnections": |
|
63 |
"Temporary Disable Remote Desktop Connections", |
|
64 |
"40SELinuxAutorelabel": "Force the system to relabel at next boot", |
|
65 |
"AssignHostname": "Assign Hostname/Computer Name to the instance", |
|
66 |
"ChangePassword": "Changes Password for specified users", |
|
67 |
"EnforcePersonality": "Inject files to the instance", |
|
68 |
"FilesystemResizeMounted": |
|
69 |
"Resize filesystem to use all the available space"} |
|
54 | 70 |
|
55 | 71 |
|
56 | 72 |
class Reset(Exception): |
... | ... | |
66 | 82 |
"Are you sure you want to reset everything?", |
67 | 83 |
width=YESNO_WIDTH) |
68 | 84 |
|
85 |
|
|
69 | 86 |
def extract_image(session): |
70 | 87 |
d = session['dialog'] |
71 | 88 |
dir = os.getcwd() |
... | ... | |
78 | 95 |
return False |
79 | 96 |
|
80 | 97 |
if os.path.isdir(path): |
81 |
dir=path
|
|
98 |
dir = path
|
|
82 | 99 |
continue |
83 | 100 |
|
84 | 101 |
if os.path.isdir("%s.meta" % path): |
... | ... | |
164 | 181 |
return False |
165 | 182 |
|
166 | 183 |
while 1: |
167 |
init=session["upload"] if "upload" in session else ''
|
|
184 |
init = session["upload"] if "upload" in session else ''
|
|
168 | 185 |
(code, answer) = d.inputbox("Please provide a filename:", init=init, |
169 | 186 |
width=INPUTBOX_WIDTH) |
170 |
|
|
187 |
|
|
171 | 188 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
172 | 189 |
return False |
173 | 190 |
|
... | ... | |
175 | 192 |
if len(filename) == 0: |
176 | 193 |
d.msgbox("Filename cannot be empty", width=MSGBOX_WIDTH) |
177 | 194 |
continue |
178 |
|
|
195 |
|
|
179 | 196 |
break |
180 | 197 |
|
181 | 198 |
out = GaugeOutput(d, "Image Upload", "Uploading...") |
... | ... | |
215 | 232 |
finally: |
216 | 233 |
out.cleanup() |
217 | 234 |
|
218 |
d.msgbox("Image file `%s' was successfully uploaded to pithos+" % filename,
|
|
235 |
d.msgbox("Image file `%s' was successfully uploaded to pithos+" % filename, |
|
219 | 236 |
width=MSGBOX_WIDTH) |
220 | 237 |
return True |
221 | 238 |
|
... | ... | |
288 | 305 |
("Register", "Register image to cyclades: %s" % upload)], |
289 | 306 |
cancel="Back", |
290 | 307 |
default_item=default_item, |
308 |
help_button=1, |
|
291 | 309 |
title="Image Registration Menu") |
292 | 310 |
|
293 | 311 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
... | ... | |
331 | 349 |
default_item = "Register" |
332 | 350 |
|
333 | 351 |
|
352 |
def add_property(session): |
|
353 |
d = session['dialog'] |
|
354 |
|
|
355 |
while 1: |
|
356 |
(code, answer) = d.inputbox("Please provide a name for a new image" |
|
357 |
" property:", width=INPUTBOX_WIDTH) |
|
358 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
359 |
return False |
|
360 |
|
|
361 |
name = answer.strip() |
|
362 |
if len(name) == 0: |
|
363 |
d.msgbox("A property name cannot be empty", width=MSGBOX_WIDTH) |
|
364 |
continue |
|
365 |
|
|
366 |
break |
|
367 |
|
|
368 |
while 1: |
|
369 |
(code, answer) = d.inputbox("Please provide a value for image " |
|
370 |
"property %s" % name, width=INPUTBOX_WIDTH) |
|
371 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
372 |
return False |
|
373 |
|
|
374 |
value = answer.strip() |
|
375 |
if len(value) == 0: |
|
376 |
d.msgbox("Value cannot be empty", width=MSGBOX_WIDTH) |
|
377 |
continue |
|
378 |
|
|
379 |
break |
|
380 |
|
|
381 |
session['metadata'][name] = value |
|
382 |
|
|
383 |
return True |
|
384 |
|
|
385 |
|
|
386 |
def modify_properties(session): |
|
387 |
d = session['dialog'] |
|
388 |
|
|
389 |
while 1: |
|
390 |
choices = [] |
|
391 |
for (key, val) in session['metadata'].items(): |
|
392 |
choices.append((str(key), str(val))) |
|
393 |
|
|
394 |
(code, choice) = d.menu( |
|
395 |
"In this menu you can edit existing image properties or add new " |
|
396 |
"ones. Be carefull! Most properties have special meaning and " |
|
397 |
"alter the image deployment behaviour. Press <HELP> to see more " |
|
398 |
"information about image properties. Press <BACK> when done.", |
|
399 |
height=18, |
|
400 |
width=MENU_WIDTH, |
|
401 |
choices=choices, menu_height=10, |
|
402 |
ok_label="EDIT", extra_button=1, extra_label="ADD", cancel="BACK", |
|
403 |
help_button=1, help_label="HELP", title="Image Metadata") |
|
404 |
|
|
405 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
406 |
break |
|
407 |
# Edit button |
|
408 |
elif code == d.DIALOG_OK: |
|
409 |
(code, answer) = d.inputbox("Please provide a new value for " |
|
410 |
"the image property with name `%s':" % choice, |
|
411 |
init=session['metadata'][choice], width=INPUTBOX_WIDTH) |
|
412 |
if code not in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
413 |
value = answer.strip() |
|
414 |
if len(value) == 0: |
|
415 |
d.msgbox("Value cannot be empty!") |
|
416 |
continue |
|
417 |
else: |
|
418 |
session['metadata'][choice] = value |
|
419 |
# ADD button |
|
420 |
elif code == d.DIALOG_EXTRA: |
|
421 |
add_property(session) |
|
422 |
|
|
423 |
|
|
424 |
def delete_properties(session): |
|
425 |
d = session['dialog'] |
|
426 |
|
|
427 |
choices = [] |
|
428 |
for (key, val) in session['metadata'].items(): |
|
429 |
choices.append((key, "%s" % val, 0)) |
|
430 |
|
|
431 |
(code, to_delete) = d.checklist("Choose which properties to delete:", |
|
432 |
choices=choices) |
|
433 |
count = len(to_delete) |
|
434 |
# If the user exits with ESC or CANCEL, the returned tag list is empty. |
|
435 |
for i in to_delete: |
|
436 |
del session['metadata'][i] |
|
437 |
|
|
438 |
if count > 0: |
|
439 |
d.msgbox("%d image properties were deleted.", width=MSGBOX_WIDTH) |
|
440 |
|
|
441 |
|
|
442 |
def exclude_task(session): |
|
443 |
d = session['dialog'] |
|
444 |
|
|
445 |
choices = [] |
|
446 |
for (key, val) in session['metadata'].items(): |
|
447 |
choices.append((key, "%s" % val, 0)) |
|
448 |
|
|
449 |
(code, to_delete) = d.checklist("Choose which properties to delete:", |
|
450 |
choices=choices) |
|
451 |
count = len(to_delete) |
|
452 |
# If the user exits with ESC or CANCEL, the returned tag list is empty. |
|
453 |
for i in to_delete: |
|
454 |
del session['metadata'][i] |
|
455 |
|
|
456 |
if count > 0: |
|
457 |
d.msgbox("%d image properties were deleted.", width=MSGBOX_WIDTH) |
|
458 |
|
|
459 |
|
|
460 |
def deploy_menu(session): |
|
461 |
d = session['dialog'] |
|
462 |
|
|
463 |
default_item = "View/Modify" |
|
464 |
actions = {"View/Modify": modify_properties, "Delete": delete_properties} |
|
465 |
while 1: |
|
466 |
(code, choice) = d.menu( |
|
467 |
"Choose one of the following or press <Back> to exit.", |
|
468 |
width=MENU_WIDTH, |
|
469 |
choices=[("View/Modify", "View/Modify image properties"), |
|
470 |
("Delete", "Delete image properties"), |
|
471 |
("Exclude", "Exclude configuration tasks from running")], |
|
472 |
cancel="Back", |
|
473 |
default_item=default_item, |
|
474 |
title="Image Deployment Menu") |
|
475 |
|
|
476 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
|
477 |
break |
|
478 |
elif choice in actions: |
|
479 |
default_item = choice |
|
480 |
actions[choice](session) |
|
481 |
|
|
482 |
|
|
334 | 483 |
def main_menu(session): |
335 | 484 |
d = session['dialog'] |
336 | 485 |
dev = session['device'] |
337 | 486 |
d.setBackgroundTitle("OS: %s, Distro: %s" % (dev.ostype, dev.distro)) |
338 |
actions = {"Register": kamaki_menu, "Extract": extract_image} |
|
487 |
actions = {"Deploy": deploy_menu, |
|
488 |
"Register": kamaki_menu, |
|
489 |
"Extract": extract_image} |
|
339 | 490 |
default_item = "Customize" |
340 | 491 |
|
341 | 492 |
while 1: |
... | ... | |
369 | 520 |
actions[choice](session) |
370 | 521 |
|
371 | 522 |
|
372 |
def select_file(d): |
|
523 |
def select_file(d, media):
|
|
373 | 524 |
root = os.sep |
374 | 525 |
while 1: |
375 |
(code, path) = d.fselect(root, 10, 50, |
|
526 |
if media is not None: |
|
527 |
if not os.path.exists(media): |
|
528 |
d.msgbox("The file you choose does not exist", |
|
529 |
width=MSGBOX_WIDTH) |
|
530 |
else: |
|
531 |
break |
|
532 |
|
|
533 |
(code, media) = d.fselect(root, 10, 50, |
|
376 | 534 |
title="Please select input media") |
377 | 535 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
378 | 536 |
if confirm_exit(d, "You canceled the media selection dialog box."): |
379 | 537 |
sys.exit(0) |
380 | 538 |
else: |
539 |
media = None |
|
381 | 540 |
continue |
382 | 541 |
|
383 |
if not os.path.exists(path): |
|
384 |
d.msgbox("The file you choose does not exist", width=MSGBOX_WIDTH) |
|
385 |
continue |
|
386 |
else: |
|
387 |
break |
|
388 |
|
|
389 |
return path |
|
542 |
return media |
|
390 | 543 |
|
391 | 544 |
|
392 | 545 |
def collect_metadata(dev, out): |
... | ... | |
413 | 566 |
if os.geteuid() != 0: |
414 | 567 |
raise FatalError("You must run %s as root" % basename) |
415 | 568 |
|
416 |
media = sys.argv[1] if len(sys.argv) == 2 else select_file(d)
|
|
569 |
media = select_file(d, sys.argv[1] if len(sys.argv) == 2 else None)
|
|
417 | 570 |
|
418 | 571 |
out = InitializationOutput(d) |
419 | 572 |
disk = Disk(media, out) |
... | ... | |
454 | 607 |
|
455 | 608 |
d = dialog.Dialog(dialog="dialog") |
456 | 609 |
|
610 |
# Add extra button in dialog library |
|
611 |
dialog._common_args_syntax["extra_button"] = \ |
|
612 |
lambda enable: dialog._simple_option("--extra-button", enable) |
|
613 |
|
|
614 |
dialog._common_args_syntax["extra_label"] = \ |
|
615 |
lambda string: ("--extra-label", string) |
|
616 |
|
|
457 | 617 |
while 1: |
458 | 618 |
try: |
459 | 619 |
try: |
Also available in: Unified diff