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 thedoapi.fetch_floating_ip()
anddoapi.fetch_all_floating_ips()
methods.The DigitalOcean API specifies the following fields for floating IP objects:
Variables: -
action_url
¶ The endpoint for actions on the individual resource
-
act
(**data)¶ Perform an arbitrary action on the resource.
data
will be serialized as JSON and POSTed to the resource’saction_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 resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
wait_for_action
(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 no actions have ever been performed on the resource, return
self
. If the resource no longer exists by the time the action has completed, returnNone
.If
wait_time
is exceeded, aWaitTimeoutError
(containing the resource’s current state) is raised.If a
KeyboardInterrupt
is caught, the resource’s current state is returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutChanged in version 0.2.0: Name changed from
wait
towait_for_action
Changed in version 0.2.0: Return
self
if there were no actions on the resourceChanged in version 0.2.0: Return
None
if the resource no longer exists afterwardsParameters: - wait_interval (number) – how many seconds to sleep between
requests; defaults to the
doapi
object’swait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if the action has not yet completed, or
a negative number to wait indefinitely; defaults to the
doapi
object’swait_time
if not specified orNone
Returns: the resource’s final state
Raises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- wait_interval (number) – how many seconds to sleep between
requests; defaults to the
-
fetch_all_actions
()¶ Returns a generator that yields all of the actions associated with the resource
Return type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_last_action
()¶ Fetch the most recent action performed on the resource, or
None
if no actions have been performed on it yet. If multiple actions were triggered simultaneously, the choice of which to return is undefined.Changed in version 0.2.0: Return
None
if there were no actions on the resourceReturn 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 actionReturn type: Action
orNone
Raises: DOAPIError – if the API endpoint replies with an error
-
url
¶ The endpoint for general operations on the individual floating IP
-
fetch
()[source]¶ Fetch & return a new
FloatingIP
object representing the floating IP’s current stateReturn 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 aDroplet
objectReturns: an Action
representing the in-progress operation on the floating IPReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-