Floating IPs

FloatingIP

class doapi.FloatingIP[source]

A floating IP resource, representing a public IP address that can be (re)assigned at any time to any droplet in a certain region.

New floating IPs are created via the doapi.create_floating_ip() method and can be retrieved with the doapi.fetch_floating_ip() and doapi.fetch_all_floating_ips() methods.

The DigitalOcean API specifies the following fields for floating IP objects:

Variables:
  • ip (string) – the IP address
  • droplet (Droplet or None) – the droplet the floating IP is currently assigned to, or None if the address is currently unassigned
  • region (Region) – the region the floating IP is reserved to
action_url

The endpoint for actions on the specific resource

act(**data)

Perform an arbitrary action on the resource. data will be serialized as JSON and POSTed to the resource’s action_url. All currently-documented actions require the POST body to be a JSON object containing, at a minimum, a "type" field.

Returns:an Action representing the in-progress operation on the resource
Return type:Action
Raises:DOAPIError – if the API endpoint replies with an error
wait(wait_interval=None, wait_time=None)

Poll the server periodically until the resource’s most recent action has either completed or errored out, and return the resource’s final state afterwards. If wait_time is exceeded or a KeyboardInterrupt is caught, the resource’s current state is returned immediately without waiting for completion.

Parameters:
  • wait_interval (number) – how many seconds to sleep between requests; defaults to the doapi object’s wait_interval if not specified or None
  • wait_time (number) – the total number of seconds after which the method will return, or a negative number to wait indefinitely; defaults to the doapi object’s wait_time if not specified or None
Returns:

the resource’s final state

Raises:

DOAPIError – if the API endpoint replies with an error

fetch_all_actions()

Returns a generator that yields all of the actions associated with the resource

Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
fetch_last_action()

Fetch the most recent action performed on the resource. If multiple actions were triggered simultaneously, the choice of which to return is undefined.

Return type:Action
Raises:DOAPIError – if the API endpoint replies with an error
fetch_current_action()

Fetch the action currently in progress on the resource, or None if there is no such action

Return type:Action or None
Raises:DOAPIError – if the API endpoint replies with an error
__str__()[source]

Convert the floating IP to just the actual IP address

url

The endpoint for operations on the specific floating IP

fetch()[source]

Fetch & return a new FloatingIP object representing the floating IP’s current state

Return type:FloatingIP
Raises:DOAPIError – if the API endpoint replies with an error (e.g., if the floating IP no longer exists)
delete()[source]

Delete the floating IP

Returns:None
Raises:DOAPIError – if the API endpoint replies with an error
assign(droplet_id)[source]

Assign the floating IP to a droplet

Parameters:droplet_id (integer or Droplet) – the droplet to assign the floating IP to as either an ID or a Droplet object
Returns:an Action representing the in-progress operation on the floating IP
Return type:Action
Raises:DOAPIError – if the API endpoint replies with an error
unassign()[source]

Unassign the floating IP

Returns:an Action representing the in-progress operation on the floating IP
Return type:Action
Raises:DOAPIError – if the API endpoint replies with an error