+ (code, choice) = d.menu(
+ self.text, width=PAGE_WIDTH, ok_label="Next", cancel="Back",
+ title=title, choices=choices, height=PAGE_HEIGHT,
+ default_item=default_item, extra_label=self.extra_label,
+ extra_button=extra_button)
+
+ if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
+ return self.PREV
+ elif code == d.DIALOG_EXTRA:
+ self.extra()
+ raise WizardReloadPage
+
+ self.default = choice
+ w[self.name] = self.validate(choice)
+ self.info = "%s: %s" % (self.display_name, self.display(w[self.name]))
+
+ return self.NEXT
+
+
+def start_wizard(session):
+ """Run the image creation wizard"""
+
+ image = session['image']
+ distro = image.distro
+ ostype = image.ostype
+
+ # Create Cloud Wizard Page
+ def cloud_choices():
+ choices = []
+ for (name, cloud) in Kamaki.get_clouds().items():
+ descr = cloud['description'] if 'description' in cloud else ''
+ choices.append((name, descr))
+
+ return choices
+
+ def cloud_add():
+ return add_cloud(session)
+
+ def cloud_none_available():
+ if not session['dialog'].yesno(
+ "No available clouds found. Would you like to add one now?",
+ width=PAGE_WIDTH, defaultno=0):
+ return add_cloud(session)
+ return False
+
+ def cloud_validate(cloud):
+ if not Kamaki.get_account(cloud):
+ if not session['dialog'].yesno(
+ "The cloud you have selected is not valid! Would you "
+ "like to edit it now?", width=PAGE_WIDTH, defaultno=0):
+ if edit_cloud(session, cloud):
+ return cloud
+
+ raise WizardReloadPage
+
+ return cloud
+
+ cloud = WizardMenuPage(
+ "Cloud", "Cloud",
+ "Please select a cloud account or press <Add> to add a new one:",
+ choices=cloud_choices, extra_label="Add", extra=cloud_add,
+ title="Clouds", validate=cloud_validate, fallback=cloud_none_available)
+
+ # Create Image Name Wizard Page