+def modify_clouds(session):
+ """Modify existing cloud accounts"""
+ d = session['dialog']
+
+ while 1:
+ clouds = Kamaki.get_clouds()
+ if not len(clouds):
+ if not add_cloud(session):
+ break
+ continue
+
+ choices = []
+ for (name, cloud) in clouds.items():
+ descr = cloud['description'] if 'description' in cloud else ''
+ choices.append((name, descr))
+
+ (code, choice) = d.menu(
+ "In this menu you can edit existing cloud accounts or add new "
+ " ones. Press <Edit> to edit an existing account or <Add> to add "
+ " a new one. Press <Back> or hit <ESC> when done.", height=18,
+ width=WIDTH, choices=choices, menu_height=10, ok_label="Edit",
+ extra_button=1, extra_label="Add", cancel="Back", help_button=1,
+ title="Clouds")
+
+ if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
+ return True
+ elif code == d.DIALOG_OK: # Edit button
+ edit_cloud(session, choice)
+ elif code == d.DIALOG_EXTRA: # Add button
+ add_cloud(session)
+
+
+def delete_clouds(session):
+ """Delete existing cloud accounts"""
+ d = session['dialog']
+
+ choices = []
+ for (name, cloud) in Kamaki.get_clouds().items():
+ descr = cloud['description'] if 'description' in cloud else ''
+ choices.append((name, descr, 0))
+
+ if len(choices) == 0:
+ d.msgbox("No available clouds to delete!", width=SMALL_WIDTH)
+ return True
+
+ (code, to_delete) = d.checklist("Choose which cloud accounts to delete:",
+ choices=choices, width=WIDTH)
+ to_delete = map(lambda x: x.strip('"'), to_delete) # Needed for OpenSUSE
+
+ if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
+ return False
+
+ if not len(to_delete):
+ d.msgbox("Nothing selected!", width=SMALL_WIDTH)
+ return False
+
+ if not d.yesno("Are you sure you want to remove the selected cloud "
+ "accounts?", width=WIDTH, defaultno=1):
+ for i in to_delete:
+ Kamaki.remove_cloud(i)
+ if 'cloud' in session and session['cloud'] == i:
+ del session['cloud']
+ if 'account' in session:
+ del session['account']
+ else:
+ return False
+
+ d.msgbox("%d cloud accounts were deleted." % len(to_delete),
+ width=SMALL_WIDTH)
+ return True
+
+