Beispiel #1
0
def review_droplet_data(data: dict) -> None:
    """
    Pretty print the data dictionary that contains droplet's configuration.

    :param dict data: droplet data to be submitted
    :return: None
    """
    exclude = "token"
    to_review = {k: v for k, v in data.items() if k != exclude}
    print(config.cyan_text(padding_text("Droplet configuration")))
    pprint(to_review, indent=4, width=10)
    print(config.cyan_text(padding_text("End droplet configuration")))
Beispiel #2
0
def get_remote_tags(manager: Manager) -> list:
    """
    API call to DigitalOcean's API v2 in order to fetch all remote tags.

    :param digitalocean.Manager.Manager manager: instance
    :return: list of digitalocean.Tag.Tag instances
    """
    with pong(text=cyan_text("Retrieving existing tags...")):
        return manager.get_all_tags()
Beispiel #3
0
def get_remote_ssh_keys(manager: Manager) -> list:
    """
    API call to DigitalOcean's API v2 in order to fetch ssh keys.

    :param digitalocean.Manager.Manager manager: instance
    :return: list of digitalocean.SSHKey.SSHKey instances
    """
    with pong(text=cyan_text("Retrieving public keys from your account...")):
        return manager.get_all_sshkeys()
Beispiel #4
0
def get_all_sizes(manager: Manager) -> list:
    """
    API call to DigitalOcean's API v2 in order to fetch all sizes.

    :param digitalocean.Manager.Manager manager: instance
    :return: list of digitalocean.Size.Size instances
    """
    with pong(text=cyan_text("Retrieving available sizes...")):
        return manager.get_all_sizes()
Beispiel #5
0
def get_account_data(manager: Manager) -> Account:
    """
    API call to DigitalOcean's API v2 in order to get account data.

    :param digitalocean.Manager.Manager manager: instance
    :return: digitalocean.Account.Account instance
    """
    with pong(text=cyan_text("Retrieving account data...")):
        return manager.get_account()
Beispiel #6
0
def create_ssh_key(ssh_key: SSHKey) -> SSHKey:
    """
    API call to DigitalOcean's API v2 in order to create the ssh key.

    :param digitalocean.SSHKey.SSHKey ssh_key: object
    :return: digitalocean.SSHKey.SSHKey
    """
    with pong(text=cyan_text("The SSH key is posted...")):
        ssh_key.create()
    return ssh_key
Beispiel #7
0
def boot_droplet(droplet: Droplet) -> Droplet:
    """
    API call to DigitalOcean's API v2 in order to initialize the droplet.
    This function will just "hit the switch-on button" on the server.
    During boot, the droplet is not considered as "created" yet.

    :param digitalocean.Droplet.Droplet droplet: instance
    :return: an instance of digitalocean.Droplet.Droplet
    """
    with pong(text=cyan_text("Your droplet is initializing...")):
        droplet.create()

    # droplet, now, has an id but not yet been fully created
    return droplet
Beispiel #8
0
def poll_droplet(droplet: Droplet, poll_interval: int = 4) -> Droplet:
    """
    Given a new-born droplet (without an IP), poll every poll_interval seconds
    the DO API in order to find out when the droplet is ready.

    :param digitalocean.Droplet.Droplet droplet: instance
    :param int poll_interval: get droplet status every poll_interval seconds
    :return: digitalocean.Droplet.Droplet instance or None
    """
    action = droplet.get_action(droplet.action_ids[0])
    action.droplet_id = droplet.id
    result = action.wait(update_every_seconds=poll_interval)
    if result:
        # droplet is now fully created (with IP, tags etc)
        text = "Retrieving droplet data after boot..."
        with pong(text=cyan_text(text)):
            return droplet.load()
Beispiel #9
0
def get_all_images(manager: Manager,
                   image_type: str = "distribution",
                   text="") -> list:
    """
    API call to DigitalOcean's API v2 in order to fetch available images per
    the selected image type.

    :param digitalocean.Manager.Manager manager: instance
    :param str image_type: "distribution" or "application" or "all"
    :param str text: a text to appear while fetching
    :return: list of digitalocean.Image.Image instances
    """
    text = text or f"Retrieving {image_type.lower()} images..."
    if image_type == "all":
        image_type = None
    with pong(text=cyan_text(text)):
        return manager.get_images(type=image_type)