Developer Interface¶
This part of the documentation covers all the interfaces of Pontoon.
Library Module¶
pontoon.lib is the main entry point for using the library as a developer.
digitalocean API to manage droplets
Manager Class¶
-
class
pontoon.lib.
Manager
(*args, **kwargs)[source]¶ -
_Manager__deal_with_pagination
(url, data, params)¶ Perform multiple calls in order to have a full list of elements when the API are “paginated”. (content list is divided in more than one page)
-
get_all_images
()[source]¶ This function returns a list of Image objects containing all available DigitalOcean images, both public and private.
-
get_app_images
()[source]¶ This function returns a list of Image objectobjects representing public DigitalOcean ‘One-Click’ application images.
-
get_data
(*args, **kwargs)[source]¶ Customized version of get_data to perform __check_actions_in_data.
The default amount of elements per page defined is 200 as explained here: https://github.com/koalalorenzo/python-digitalocean/pull/78
-
get_distro_images
()[source]¶ This function returns a list of Image objects representing public base distribution images.
-
get_global_images
()[source]¶ This function returns a list of Image objects representing public DigitalOcean images (e.g. base distribution images and ‘One-Click’ applications).
-
Droplet Class¶
-
class
pontoon.lib.
Droplet
(*args, **kwargs)[source]¶ “Droplet management
- Attributes accepted at creation time:
- name: str - name size_slug: str - droplet size image: str - image name to use to create droplet region: str - region ssh_keys: [str] - list of ssh keys backups: bool - True if backups enabled ipv6: bool - True if ipv6 enabled private_networking: bool - True if private networking enabled user_data: str - arbitrary data to pass to droplet
- Attributes returned by API:
id: int - droplet id memory: str - memory size vcpus: int - number of vcpus disk: int - disk size in GB status: str - status locked: bool - True if locked created_at: str - creation date in format u‘2014-11-06T10:42:09Z’ status: str - status, e.g. ‘new’, ‘active’, etc networks: dict - details of connected networks kernel: dict - details of kernel backup_ids: [int] - list of ids of backups of this droplet snapshot_ids: [int] - list of ids of snapshots of this droplet action_ids: [int] - list of ids of actions features: [str] - list of enabled features. e.g.
[u’private_networking’, u’virtio’]- min_size: str - minumum size of droplet that can bew created from a
- snapshot of this droplet
image: dict - details of image used to create this droplet ip_address: str - public ip addresses private_ip_address: str - private ip address ip_v6_address: [str] - list of ipv6 addresses assigned end_point: str - url of api endpoint used
-
_Droplet__get_ssh_keys_id_or_fingerprint
()¶ Check and return a list of SSH key IDs or fingerprints according to DigitalOcean’s API. This method is used to check and create a droplet with the correct SSH keys.
-
_perform_action
(params, return_dict=True)[source]¶ Perform a droplet action.
- Args:
- params - dict : parameters of the action
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
change_kernel
(kernel, return_dict=True)[source]¶ Change the kernel to a new one
- Args:
- kernel : instance of digitalocean.Kernel.Kernel
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
create
(*args, **kwargs)[source]¶ Create the droplet with object properties.
Note: Every argument and parameter given to this method will be assigned to the object.
-
disable_backups
(return_dict=True)[source]¶ Disable automatic backups
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
enable_ipv6
(return_dict=True)[source]¶ Enable IPv6 on an existing Droplet where available.
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
enable_private_networking
(return_dict=True)[source]¶ Enable private networking on an existing Droplet where available.
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
get_action
(action_id)[source]¶ Returns a specific Action by its ID.
- Args:
- action_id: int - id of action
-
get_actions
()[source]¶ Returns a list of Action objects This actions can be used to check the droplet’s status
-
get_data
(*args, **kwargs)[source]¶ Customized version of get_data to perform __check_actions_in_data
-
classmethod
get_object
(api_token, droplet_id, mocked)[source]¶ Class method that will return a Droplet object by ID.
- Args:
- api_token: str - token droplet_id: int - droplet id mocked: bool - mocked
-
get_snapshots
()[source]¶ This method will return the snapshots/images connected to that specific droplet.
-
power_cycle
(return_dict=True)[source]¶ restart the droplet
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
power_off
(return_dict=True)[source]¶ restart the droplet
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
power_on
(return_dict=True)[source]¶ Boot up the droplet
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
reboot
(return_dict=True)[source]¶ restart the droplet
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
rebuild
(image_id=None, return_dict=True)[source]¶ Restore the droplet to an image ( snapshot or backup )
- Args:
- image_id : int - id of image
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
rename
(name, return_dict=True)[source]¶ Rename the droplet
- Args:
- name : str - new name
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
reset_root_password
(return_dict=True)[source]¶ reset the root password
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
resize
(new_size_slug, return_dict=True, disk=True)[source]¶ Resize the droplet to a new size slug. https://developers.digitalocean.com/documentation/v2/#resize-a-droplet
- Args:
- new_size_slug: str - name of new size
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
disk - bool : If a permanent resize, with disk changes included.
Returns dict or Action
-
restore
(image_id, return_dict=True)[source]¶ Restore the droplet to an image ( snapshot or backup )
- Args:
- image_id : int - id of image
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
shutdown
(return_dict=True)[source]¶ shutdown the droplet
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
Returns dict or Action
-
take_snapshot
(snapshot_name, return_dict=True, power_off=False)[source]¶ Take a snapshot!
- Args:
- snapshot_name: str - name of snapshot
- Optional Args:
- return_dict - bool : Return a dict when True (default),
- otherwise return an Action.
- power_off - bool : Before taking the snapshot the droplet will be
- turned off with another API call. It will wait until the droplet will be powered off.
Returns dict or Action
Account Class¶
Action Class¶
Domain Class¶
-
class
pontoon.lib.
Domain
(*args, **kwargs)[source]¶ -
-
create_new_domain_record
(*args, **kwargs)[source]¶ Create new domain record. https://developers.digitalocean.com/#create-a-new-domain-record
Args:
@type The record type (A, MX, CNAME, etc). @name The host name, alias, or service being defined by the record @data Variable data depending on record type.
Optional Args:
@priority The priority of the host @port The port that the service is accessible on @weight The weight of records with the same priority
-
FloatingIP Class¶
-
class
pontoon.lib.
FloatingIP
(*args, **kwargs)[source]¶ -
-
create
(*args, **kwargs)[source]¶ Creates a FloatingIP and assigns it to a Droplet.
Note: Every argument and parameter given to this method will be assigned to the object.
- Args:
- droplet_id: int - droplet id
-
classmethod
get_object
(api_token, ip, mocked)[source]¶ Class method that will return a FloatingIP object by its IP.
- Args:
- api_token: str - token ip: str - floating ip address
-
Image Class¶
Record Class¶
SSHKey Class¶
UI module¶
This module handles all output for the CLI, as well as some filesystem interactions. This is the only location outside of tests where the print statement is invoked directly.
-
pontoon.ui.
ask_yesno
(question)[source]¶ Present a string as a yes/no question on an interactive prompt
-
pontoon.ui.
box
(text, decor='*', decor_x=None, decor_y=None, boxwidth=60, borderwidth=2)[source]¶ Create a formatted textbox for highlighting important information
-
pontoon.ui.
format_droplet_info
(machine)[source]¶ Present Droplet information in a more human parseable format
-
pontoon.ui.
mask
(text, masker='*')[source]¶ Hide part of a string,
If the input is small, hide the entire string. Otherwise, show only the last few characters.
-
pontoon.ui.
ticker
()[source]¶ A loading/waiting indicator.
Sends a ‘.’ to the screen, resets, and sleeps.
Mocking Module¶
-
pontoon.mocking.
_raise
(ex=None)[source]¶ Wrapper for exceptions so they can be thrown from inside lambdas
Exceptions¶
Configure Module¶
The configure module is a collection of methods for handling interaction with some external tools, config files, and for interactive configuration.
-
pontoon.configure.
combined
(*args, **kwargs)[source]¶ Merge configuration defaults with values from config file.
-
pontoon.configure.
create_config
(*args, **kwargs)[source]¶ Create a YAML config file from a dictionary
-
pontoon.configure.
read_config
(*args, **kwargs)[source]¶ Read a YAML formatted config into a dictionary
Command Class¶
The Command class encapsulates plumbing common to all CLI commands.