Exemple #1
0
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", title="Clouds")

        if code in (d.CANCEL, d.ESC):
            return True
        elif code == d.OK:  # Edit button
            edit_cloud(session, choice)
        elif code == d.EXTRA:  # Add button
            add_cloud(session)
 def cloud_validate(cloud):
     """Checks if a cloud is valid"""
     if not Kamaki.get_account(cloud):
         if session['dialog'].yesno(
                 "The cloud you have selected is not valid! Would you "
                 "like to edit it now?", width=PAGE_WIDTH,
                 defaultno=0) == session['dialog'].OK:
             if edit_cloud(session, cloud):
                 return cloud
         raise WizardReloadPage
     return cloud
 def cloud_validate(cloud):
     """Checks if a cloud is valid"""
     if not Kamaki.get_account(cloud):
         if session['dialog'].yesno(
                 "The cloud you have selected is not valid! Would you "
                 "like to edit it now?",
                 width=PAGE_WIDTH,
                 defaultno=0) == session['dialog'].OK:
             if edit_cloud(session, cloud):
                 return cloud
         raise WizardReloadPage
     return cloud
Exemple #4
0
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
            else:
                # Select the newly added cloud
                session['current_cloud'] = Kamaki.get_clouds().keys()[0]
            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",
            title="Clouds")

        if code in (d.CANCEL, d.ESC):
            return True
        elif code == d.OK:  # Edit button
            edit_cloud(session, choice)
        elif code == d.EXTRA:  # Add button
            add_cloud(session)
Exemple #5
0
def select_cloud(session):
    """Select one of the existing cloud accounts"""
    d = session['dialog']

    clouds = Kamaki.get_clouds()
    if not len(clouds):
        d.msgbox("No clouds available. Please add a new cloud!",
                 width=SMALL_WIDTH)
        return False

    try:
        current = session['current_cloud']
    except KeyError:
        current = clouds.keys()[0]
        session['current_cloud'] = current

    choices = []
    for name, info in clouds.items():
        default = 1 if current == name else 0
        descr = info['description'] if 'description' in info else ""
        choices.append((name, descr, default))

    (code, answer) = d.radiolist("Please select a cloud:",
                                 width=WIDTH,
                                 choices=choices)
    if code in (d.CANCEL, d.ESC):
        return True

    if answer not in session['clouds']:
        session['clouds'][answer] = {}

    cloud = session['clouds'][answer]
    cloud['account'] = Kamaki.get_account(answer)

    if cloud['account'] is None:  # invalid account
        if d.yesno("The cloud %s' is not valid! Would you like to edit it?" %
                   answer,
                   width=WIDTH) == d.OK:
            if edit_cloud(session, answer):
                session['current_cloud'] = answer
                cloud['account'] = Kamaki.get_account(answer)
                Kamaki.set_default_cloud(answer)

    if cloud['account'] is not None:
        session['current_cloud'] = answer
        Kamaki.set_default_cloud(answer)
        return True
    else:
        del cloud['account']
        del session['current_cloud']
Exemple #6
0
def select_cloud(session):
    """Select one of the existing cloud accounts"""
    d = session['dialog']

    clouds = Kamaki.get_clouds()
    if not len(clouds):
        d.msgbox("No clouds available. Please add a new cloud!",
                 width=SMALL_WIDTH)
        return False

    try:
        current = session['current_cloud']
    except KeyError:
        current = clouds.keys()[0]
        session['current_cloud'] = current

    choices = []
    for name, info in clouds.items():
        default = 1 if current == name else 0
        descr = info['description'] if 'description' in info else ""
        choices.append((name, descr, default))

    (code, answer) = d.radiolist("Please select a cloud:", width=WIDTH,
                                 choices=choices)
    if code in (d.CANCEL, d.ESC):
        return True

    if answer not in session['clouds']:
        session['clouds'][answer] = {}

    cloud = session['clouds'][answer]
    cloud['account'] = Kamaki.get_account(answer)

    if cloud['account'] is None:  # invalid account
        if d.yesno("The cloud %s' is not valid! Would you like to edit it?"
                   % answer, width=WIDTH) == d.OK:
            if edit_cloud(session, answer):
                session['current_cloud'] = answer
                cloud['account'] = Kamaki.get_account(answer)
                Kamaki.set_default_cloud(answer)

    if cloud['account'] is not None:
        session['current_cloud'] = answer
        Kamaki.set_default_cloud(answer)
        return True
    else:
        del cloud['account']
        del session['current_cloud']