Tags

Tag

class doapi.Tag[source]

New in version 0.2.0.

A tag resource, representing a label that can be applied to other resources.

New tags are created via the doapi.create_tag() method and can be retrieved with the doapi.fetch_tag() and doapi.fetch_all_tags() methods.

The DigitalOcean API specifies the following fields for tag objects:

Variables:
  • name (string) – the name of the tag
  • resources – a dict mapping resource types (e.g., "droplets") to sub-dicts containing fields "count" (the number of resources of the given type with the given tag) and "last_tagged" (the resource of the given type to which the tag was most recently applied)
url

The endpoint for general operations on the individual tag

fetch()[source]

Fetch & return a new Tag object representing the tag’s current state

Return type:Tag
Raises:DOAPIError – if the API endpoint replies with an error (e.g., if the tag no longer exists)
__str__()[source]

Convert the tag object to its name

update_tag(name)[source]

Update (i.e., rename) the tag

Parameters:name (str) – the new name for the tag
Returns:an updated Tag object
Return type:Tag
Raises:DOAPIError – if the API endpoint replies with an error
delete()[source]

Delete the tag

Returns:None
Raises:DOAPIError – if the API endpoint replies with an error
add(*resources)[source]

Apply the tag to one or more resources

Parameters:resources – one or more Resource objects to which tags can be applied
Returns:None
Raises:DOAPIError – if the API endpoint replies with an error
remove(*resources)[source]

Remove the tag from one or more resources

Parameters:resources – one or more Resource objects to which tags can be applied
Returns:None
Raises:DOAPIError – if the API endpoint replies with an error
fetch_all_droplets()[source]

Returns a generator that yields all of the droplets to which the tag is currently applied

Return type:generator of Droplets
Raises:DOAPIError – if the API endpoint replies with an error
delete_all_droplets()[source]

Delete all of the droplets to which the tag is applied

Returns:None
Raises:DOAPIError – if the API endpoint replies with an error
act_on_droplets(**data)[source]

Perform an arbitrary action on all of the droplets to which the tag is applied. data will be serialized as JSON and POSTed to the proper API endpoint. All currently-documented actions require the POST body to be a JSON object containing, at a minimum, a "type" field.

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
power_cycle()[source]

Power cycle all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
power_on()[source]

Power on all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
power_off()[source]

Power off all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
shutdown()[source]

Shut down all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
enable_private_networking()[source]

Enable private networking on all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
enable_ipv6()[source]

Enable IPv6 networking on all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
enable_backups()[source]

Enable backups on all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
disable_backups()[source]

Disable backups on all of the droplets to which the tag is applied

Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error
snapshot(name)[source]

Create snapshot images of all of the droplets to which the tag is applied

Parameters:name (str) – the name for the new snapshots
Returns:a generator of Actions representing the in-progress operations on the droplets
Return type:generator of Actions
Raises:DOAPIError – if the API endpoint replies with an error