示例#1
0
def ask_for_region(
    manager: Manager, available_regions: list
) -> Tuple[Region, list]:
    """
    Prompts the user to select a region (London, Amsterdam etc).

    :param Manager manager: instance
    :param list available_regions: list of digitalocean.Region instances
    :return: tuple of digitalocean.Region instance and list of Size instances
    """
    # User's region selection
    regions = api.get_all_regions(manager)
    available_regions = list(
        filter(lambda r: r.slug in available_regions and r.available, regions)
    )
    q = q_radio(
        message="Select a region",
        choices=choices.prepare_region_choices(available_regions),
    )
    selected_region = answer(q)

    # Get available sizes from the selected region
    region_iter = filter(lambda x: x.slug == selected_region.slug, regions)
    available_sizes = list(region_iter)[0].sizes

    return selected_region, available_sizes
示例#2
0
def ask_for_image_type() -> str:
    """
    Prompts the user to select an image type (distribution, application, all).

    :return: str (the selected image type)
    """
    q = q_radio(
        message="Select an image type",
        choices=choices.prepare_image_type_choices(),
    )
    selected_image_type = answer(q)
    return selected_image_type
示例#3
0
def ask_for_tag_addition_method() -> str:
    """
    Prompts the user to select an addition method to add tags.

    :return: str (the selected addition method)
    """
    tag_method_choices = choices.prepare_tag_addition_method_choices()
    q = q_radio(
        message="Select a method to add tags", choices=tag_method_choices
    )
    addition_method = answer(q)
    return addition_method
示例#4
0
def ask_for_ssh_keys_addition_method() -> str:
    """
    Given some options for addition methods of the ssh keys,
    present a prompt for the user to select one.

    :return: str (the selected addition method)
    """
    ssh_method_choices = choices.prepare_ssh_keys_addition_method_choices()
    q = q_radio(
        message="SSH addition method", choices=ssh_method_choices
    )
    addition_method = answer(q)
    return addition_method
示例#5
0
def ask_for_size(manager: Manager, available_sizes: list):
    """
    Prompts the user to select a droplet size (€5, €10, €15 per month etc).

    :param Manager manager: instance
    :param list available_sizes: list of digitalocean.Size instances
    :return: digitalocean.Size instance
    """
    sizes = api.get_all_sizes(manager)
    available_sizes = list(
        filter(lambda s: s.slug in available_sizes and s.available, sizes)
    )
    q = q_radio(
        message="Select a size",
        choices=choices.prepare_size_choices(available_sizes),
    )
    selected_size = answer(q)
    return selected_size
示例#6
0
def ask_for_image(manager: Manager, image_type: str) -> Tuple[Image, list]:
    """
    Given an image type, prompts the user to select one of the available images
    (Ubuntu, Fedora, Debian etc).

    :param Manager manager: instance
    :param str image_type: an image type
    :return: tuple of digitalocean.Image instance and list of Region instances
    """
    # User's image selection
    images = api.get_all_images(manager, image_type)
    q = q_radio(
        message="Select an image",
        choices=choices.prepare_image_choices(images),
    )
    selected_image = answer(q)

    # Get available regions from the selected image
    image_iter = filter(lambda x: x.slug == selected_image.slug, images)
    available_regions = list(image_iter)[0].regions

    return selected_image, available_regions