Package: digitaloceanobjects
digitalocean objects (pip3 install digitaloceanobjects)everyone:I wish, for once, to just have a simple object oriented experience with the api.digitaloceanobjects:Please visitGitHubpage for documentation that has navigation that works.Table of ContentsHow to installConfigurationsOMG OMG SHOW ME SHOW ME HOW... NOW!!!Blocking Wonderful BlockingAccountAccount ManagerRetrieve Account InformationSizesSize ManagerRetrieve SizesSize ObjectRegionsRegion ManagerRetrieve All RegionsRegion ObjectSSH KeysSSH Key ManagerRetrieve All SSH KeysCreate New KeyRetrieve SSH Key Using IDSSH Key ObjectUpdate SSH Key NameDelete SSH KeyDropletsDroplet ManagerCreate New DropletRetrieve Droplet By IDRetrieve Droplets By NameRetrieve All DropletsRetrieve Droplets With ANY tagsRetrieve Droplets With ALL tagsRetrieve Droplets With ONLY tagsDelete Droplets With ANY tagsDelete Droplets With ALL tagsDelete Droplets With ONLY tagsDelete Droplet By IDDroplet ObjectRebootPower CycleShutdownPower OffPower OnRebuildRenameCreate SnapshotRetrieve SnapshotsRetrieve Snapshot By IDRetrieve Associated VolumesRetrieve Associated Volume SnapshotsAttach A VolumeDetach A VolumeRestore DropletResize DropletDelete DropletBlock Storage (Volumes)Volume ManagerCreate New VolumeRetrieve All VolumesRetrieve All Volumes By NameRetrieve Volume By IDRetrieve Volume By Name And RegionRetrieve Volumes With ANY TagsRetrieve Volumes With ALL TagsRetrieve Volumes With ONLY TagsDelete Volume By IDDelete Volume By Name And RegionDelete Volumes With ANY TagsDelete Volumes With ALL TagsDelete Volumes With ONLY TagsVolume ObjectCreate SnapshotRetrieve SnapshotsDetach From DropletsResize VolumeSnapshotsSnapshot ManagerRetrieve All SnapshotsRetrieve All Droplet SnapshotsRetrieve All Volume SnapshotsRetrieve Snapshot By IDSnapshot ObjectDelete SnapshotFloating IPsFloating IP ManagerRetrieve All Floating IPsCreate New Floating IPCreate Region Reserve IPRetrieve Floating IPFloating IP ObjectDelete Floating IPUnassign Floating IPRetrieve All IP ActionsRetrieve Existing IP ActionActionsAction ManagerRetrieve All ActionsRetrieve ActionAction ObjectExceptionsDroplet ExceptionsVolume ExceptionsSnapshot ExceptionsAction ExceptionsRegion ExceptionsFloating IP ExceptionsSSH Key ExceptionsHow to installHere are your options.Install from pypi repositoryThe most popular way is to install the latest package available on pypi.You can install digitaloceanobjects usingpip3pip3 install -U digitaloceanobjectsYou can uninstall if you like using,pip3 uninstall digitaloceanobjectsInstall from the cloned git hub repoThere are a few ways to install this python package from a clone of its github repo.
Check out a copy and try the following...Build a .tar.gz install packageFrom the root of the repo build a repo, and check the repo.python3 setup.py sdist
twine check dist/*Check the newly created dist directory for newly created .tar.gz files.
This is your .tar.gz package and you can install using...pip3 install ./dist/digitaloceanobjects-0.0.17.tar.gzYou can still uninstall using the same commands,pip3 uninstall digitaloceanobjectsInstall using the setup.py file!WARNING! Install does not track which files, and where they are placed.
So, you need to keep a record of there python3 does this.This is how... from the github repo root directory.sudo python3 setup.py install --record files.txtYou can uninstall using by playing back that files.txt file,sudo xargs rm -rf < files.txtLocal interactive installUsing this method you can modify this packages code and have changes immediately available.
Perfect for if you want to tinker with the library, poke around and contribute to the project.From the cloned repository root directory.pip3 install -e ./You can uninstall using the usual command,pip3 uninstall digitaloceanobjects⬆ back to topConfigurationsTokenSet the DIGITALOCEAN_ACCESS_TOKEN environment variable with your api key.export DIGITALOCEAN_ACCESS_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'api connection settingsYou don't need to look too deeply here, this is for information only.digitaloceanobjects is powered by a baserestapi class from the following project.https://github.com/zorani/cloudapi/blob/main/cloudapi/baserestapi.pydigitaloceanobjects/digitaloceanapi/digitaloceanapiconnection.py inherits baserestapi,
baseresapi takes care of all the tricky rate limiting.Inside /digitaloceanapiconnection.py you will find
a 'callrateperhour' variable set to the current digital ocean limit of 5000.
digitalocean-objects converts 'callrateperhour' to seconds between requests.You will also see the following variables.geometric_delay_multiplier: If a request fails, the 'seconds between requests' is increased by multiplying by this number.maximum_geometric_delay_multiplicaiton: How many times should you increase the 'seconds between requests' before considering it a fail.maximum_failed_attempts: a failed attempt is put to the back of an internal queue for a retry. how many failed attempts are allowed before
returning the response with failure codes and content.BaseRESTAPI.__init__(self,baseurl="https://api.digitalocean.com",callrateperhour=5000,geometric_delay_multiplier=2,maximum_geometric_delay_multiplications=6,maximum_failed_attempts=3,)⬆ back to topOMG OMG SHOW ME SHOW ME HOW NOWOkay!! Okay!!  Here is a quick start example!Look how easy it is to work with digitaloceanobjects......read the code comments...#!/usr/bin/env python3fromdigitaloceanobjectsimportDroplet,DropletManagerfromdigitaloceanobjectsimportVolume,VolumeManager#Create a droplet manager, to you know... manage your droplets.droplet_manager=DropletManager()#Create a new droplet.my_brand_new_droplet=droplet_manager.create_new_droplet(name="test-droplet",region="ams3",size="s-1vcpu-1gb",image="ubuntu-16-04-x64",tags=["digitalocean","objects","are","great"],)#What? Done already?#Yup... now output the droplet details.print(type(my_brand_new_droplet))print(my_brand_new_droplet.attributes)#Want to attache a volume? No problem...#Create a volume manager.volume_manager=VolumeManager()#You'll need a volume, so lets create a new volume.my_brand_new_volume=volume_manager.create_new_volume(size_gigabytes=10,name="test-volume",region="ams3",description="BlockStoreFor Examples",filesystem_type="ext4",filesystem_label="example",tags=["is","it","really","this","easy"],)#Well... damn that was easy. Peek at the volume object and the attributes. Nice.print(type(my_brand_new_volume))print(my_brand_new_volume.attributes)#So, now just ask your droplet to attach your new volume.my_brand_new_droplet.attach_a_volume(my_brand_new_volume)#Still don't beleive how easy this was? Check the droplet attributes, you will now have a volume id attached to it.print(my_brand_new_droplet.attributes.volume_ids)Hope you're happy...... now read the rest of the documentation to see what other amazing things you can do!⬆ back to topBlocking Wonderful BlockingDid you notice in the quick start example above we didn't at any point check to see if the droplet, or the volume were ready and available?Well... that's because digitaloceanobjects is 'blocking', it waits for an operation on digital ocean to complete before returning.You can code away, without any worries.For example, digitaloceanobjects will wait for a droplet to be ready before any further actions are applied to it. You can't attach a volume to a droplet that hasn't finished setting up.If you want to setup multiple droplets concurrently you should thread your droplet set up script so you're not waiting on independent services.AccountRetrieve information about your current digital ocean account.fromdigitaloceanobjectsimportAccountManagerAccount Manageraccount_manager=AccountManager()Retrieve Account Informationdroplet_limit=account_manager.droplet_limit()floating_ip_limit=account_manager.floating_ip_limit()volume_limit=account_manager.volume_limit()email=account_manager.email()email_verified=account_manager.email_verified()uuid=account_manager.uuid()status=account_manager.status()status_message=account_manager.status_message()⬆ back to topSizesThesizesobjects represent different packages of hardware resources that can be used for Droplets. When a Droplet is created, a size must be selected so that the correct resources can be allocated.Each size represents a plan that bundles together specific sets of resources. This includes the amount of RAM, the number of virtual CPUs, disk space, and transfer. The size object also includes the pricing details and the regions that the size is available in.Import the size object, and the sizemanager.fromdigitaloceanobjectsimportSize,SizeManagerSize ManagerThe size manager contains methods to query information about available sizes on digital ocean.size_manager=SizeManager()Retrieve Sizeslist_of_size_objects=size_manager.retrieve_sizes()Size ObjectSize objects contains an attributes data class with the standard digital oceansize attributes.The size objects worked on by the above manager contain a data class with attributes describing the available digital ocean sizes.classSize:def__init__(self):self.attributes=SizeAttributes()@dataclassclassSizeAttributes:slug:str=Noneavailable:bool=Nonetransfer:float=Noneprice_monthly:float=Noneprice_hourly:float=Nonememory:int=Nonevcpus:int=Nonedisk:int=Noneregions:list=field(default_factory=list)description:str=None⬆ back to topRegionsA region in DigitalOcean represents a datacenter where Droplets can be deployed and images can be transferred.Each region represents a specific datacenter in a geographic location. Some geographical locations may have multiple "regions" available. This means that there are multiple datacenters available within that area.Import the digitaloceanobject Region and RegionManger to interact with Regions.fromdigitaloceanobjectsimportRegion,RegionManagerRegion ManagerCreate a region manager.region_manager=RegionManager()Retrieve All RegionsRetrieve a list of region objects.list_of_region_objects=region_manager.retrieve_all_regions()Region ObjectRegion objects contains an attributes data class with the standard digital oceanregion attributes.classRegion:def__init__(self):self.attributes=RegionAttributes()...@dataclassclassRegionAttributes:slug:str=Nonename:str=Nonesizes:list=field(default_factory=list)available:bool=Nonefeatures:list=field(default_factory=list)⬆ back to topSSH KeysSSH Keys. DigitalOcean allows you to add SSH public keys to the interface so that you can embed your public key into a Droplet at the time of creation. Only the public key is required to take advantage of this functionality.Import the digitaloceanobject SSHKey and SSHKeyManger to interact with SSH Keys.fromdigitaloceanobjectsimportSSHKey,SSHKeyManagerSSH Key ManagerCreate an SSH key manager.sshkey_manager=SSHKeyManager()Retrieve All SSH KeysReturns a list of SSHKey objects each containing details of existing keys.list_of_sshkey_objects=sshkey_manager.retrieve_all_sshkeys()Create New Key'upload' a new key to digital ocean by providing your public key, and an easy to remember name.Returns an SSHKey object with details of your new key stored in it's attribute data class.sshkey_object=sshkey_manager.create_new_key(name:str,public_key:str)Retrieve SSH Key Using IDEach SSH Key has an ID.  Using this ID you can retrieve information on an existing SSH Key.Returns an SSHKey object with details of your existing key stored in it's attribute data class.sshkey_object=sshkey_manager.retrieve_sshkey_with_id(id:int)SSH Key ObjectSSH Key objects contains an attributes data class with the standard digital oceanSSH Key attributes.sshkey_object=SSHKey()classSSHKey:def__init__(self):self.attributes=SSHKeyAttributes()...@dataclassclassSSHKeyAttributes:id:str=Nonefingerprint:str=Nonepublic_key:str=Nonename:str=NoneTo work on your digital ocean ssh keys first retrieve your ssh key objects using the ssh key object manager.  Then apply the objects following methods.Update SSH Key NameThen call the objects update name method with your new ssh key name.sshkey_object.update_name(name:str)Delete SSH KeyYou can delete an ssh key by calling the objects delete method.sshkey_object.delete()⬆ back to topDropletsADropletis a DigitalOcean virtual machine.Import the digitaloceanobject Droplet and DropletManger to interact with or create new droplets.fromdigitaloceanobjectsimportDroplet,DropletManagerDroplet ManagerCreate a droplet manager.droplet_manager=DropletManager()Create New DropletTo create a new droplet use the following method supplying your desired dropletAttribute Values.droplet_object=droplet_manager.create_new_droplet(name="example.com",region="nyc3",size="s-1vcpu-1gb",image="ubuntu-16-04-x64",ssh_keys=[],backups=False,ipv6=True,user_data=None,private_networking=None,volumes=None,tags=["bananas"],)Retrieve Droplet By IDYou can retreive an existing droplet by calling the following method and supplying the droplets id.A droplet object will be returned. The droplet object will contain the standard digital oceandroplet attributes.droplet_object=droplet_manager.retrieve_droplet_by_id(id:int)Retrieve Droplets By NameMany droplets can have the same name.To retrieve a list of droplet objects that have a particular name use the following method supplying your name.list_of_droplet_objects=droplet_manager.retrieve_droplet_by_name(name:str)Retrieve All DropletsTo retrieve all droplets in your account apply the following method.A list of droplet objects will be returned.list_of_droplet_objects=droplet_manager.retrieve_all_droplets()Retrieve Droplets With ANY tagsYou can tag droplets with as many tags as you like.This method will return a list of digital ocean objects that contain any of the tags you provide in a list.list_of_droplet_objects=droplet_manager.retrieve_droplets_with_any_tags(tag:list)Retrieve Droplets With ALL tagsThis method will return a list of droplet objects, but only throse droplets that
have at least all of the tags that you specify in a list of tags.list_of_droplet_objects=droplet_manager.retrieve_droplets_with_all_tags(tag:list)Retrieve Droplets With ONLY tagsThis method will return a list of droplet objects that exactly match a list of tags that you specify.list_of_droplet_objects=droplet_manager.retrieve_droplets_with_only_tags(tag:list)Delete Droplets With ANY tagsYou can also delete droplets by tags.This method allows you to delete all droplets that contain any, one or more, of a list of tags that you specify.droplet_manager.delete_droplets_with_any_tags(tag:list)Delete Droplets With ALL tagsThis method will delete any droplets that contain all, at least all, of the tags that you specify.droplet_manager.delete_droplets_with_all_tags(tag:list)Delete Droplets With ONLY tagsThis method will delete droplets that match exactly a tag list that you specify.droplet_manager.delete_droplets_with_only_tags(tag:list)Delete Droplet By IDThe droplet manager allowes you to request droplet deletion by supplying a droplet id.You might prefer to delete a droplet by calling a droplet objects delete method directly though.droplet_manager.delete_droplet_by_id(id:int)⬆ back to topDroplet ObjectDroplet objects contains an attributes data class with the standard digital oceandroplet attributes.Some of the droplet attributes such asregionandimagecan be further inspected by retrieving their relative digitaloceanobject objects.droplet_object=Droplet()classDroplet:def__init__(self,status=None):self.attributes=DropletAttributes()self.attributes.status=statusself.deleted=False...@dataclassclassDropletAttributes:id:int=Nonename:str=Nonememory:int=Nonevcpus:int=Nonedisk:int=Nonelocked:bool=Nonecreated_at:str=Nonestatus:str=Nonebackup_ids:list=field(default_factory=list)snapshot_ids:list=field(default_factory=list)features:list=field(default_factory=list)region:object=field(default_factory=list)image:object=field(default_factory=list)size:object=field(default_factory=list)size_slug:str=Nonenetworks:object=field(default_factory=list)kernel:object=field(default_factory=list)next_backup_window:object=field(default_factory=list)tags:list=field(default_factory=list)volume_ids:list=field(default_factory=list)vpc_uuid:list=field(default_factory=list)RebootA reboot action is an attempt to reboot the Droplet in a graceful way, similar to using the reboot command from the console.You can reboot a droplet by calling the following method.droplet_object.reboot()Power CycleA power cycle action is similar to pushing the reset button on a physical machine, it's similar to booting from scratch.You can power cycle a droplet by calling the following method.droplet_object.powercycle()ShutdownA shutdown action is an attempt to shutdown the Droplet in a graceful way, similar to using the shutdown command from the console. Since a shutdown command can fail, this action guarantees that the command is issued, not that it succeeds. The preferred way to turn off a Droplet is to attempt a shutdown, with a reasonable timeout, followed by a power off action to ensure the Droplet is off.You can shutdown a droplet by calling the following method.droplet_object.shutdown()Power OffA power_off event is a hard shutdown and should only be used if the shutdown action is not successful. It is similar to cutting the power on a server and could lead to complications.You can power off a droplet by calling the following method.droplet_object.poweroff()Power OnYou can power on a droplet by calling the following method.droplet_object.poweron()RebuildA rebuild action functions just like a new create.You can supply an image slug, or an image id. Your droplet will
be rebuilt, and you object attributes will be updated to reflect
the changed this method makes.You can rebuild a droplet by calling the following method.droplet_object.rebuild(img:str)RenameYou can rename a droplet by calling the following method.droplet_object.rename(name:str)Create SnapshotYou can create a droplet snapshot using the following method supplying a name to be use for your snapshot.dropletsnapshot_object=droplet_object.createsnapshot(name:str)Adroplet snapshotobject is returned.  This type of snapshot, droplet snapshot, has more details than the usualsnapshotcovered later.Here are the DropletSnapshot details.classDropletSnapshot:def__init__(self):self.attributes=DropletSnapshotAttributes()@dataclassclassDropletSnapshotAttributes:id:int=Nonename:str=Nonedistribution:str=Noneslug:str=Nonepublic:bool=Noneregions:list=field(default_factory=list)created_at:str=Nonemin_disk_size:int=Nonetype:str=Nonesize_gigabytes:float=NoneRetrieve SnapshotsYou can retrieve all the DropletSnapshots for a droplet by calling the following method.list_of_dropletsnapshot_objects=droplet_object.retrieve_snapshots()Retrieve Snapshot By IDYou can retrieve a DropletSnapshot for a droplet by calling the following method and supplying an id.This method will only search snapshots associated to the droplet.dropletsnapshot_object=droplet_object.retrieve_snapshot_by_id(id:int)Retrieve Associated VolumesA droplet may have block storage attached to it.
You can retrieve a list ofvolume objectsassociated to your droplet by calling the following method.list_of_volume_objects=droplet_object.retrieve_associated_volumes()Retrieve Associated Volume SnapshotsYou can retrieve all associatedvolume snapshotsby calling the following method.list_of_volume_snapshot_objects=droplet_object.retrieve_associated_volume_snapshots()!WARNING! These snapshot objects are slightly different to thedroplet snapshotswe just looked at.Thesnapshotsobject created here can actually detail saved instances of both Droplet or a block storage volume, which is reflected in the 'resource_type' attribute.Attach A VolumeYou can attach a volume to a droplet by calling the following method and supplying a volume object.droplet_object.attach_a_volume(target_volume:Volume)Detach A VolumeYou can similarly detach the volume by calling the following.droplet_object.detach_a_volume(target_volume:Volume)Restore DropletA Droplet restoration will rebuild an image using a backup image. The image ID that is passed in must be a backup of the current Droplet instance. The operation will leave any embedded SSH keys intact.You can restore a droplet by calling the following method.droplet_object.restore_droplet(image_id:int)Resize DropletIf  you setdisk=Falseonly the RAM will be increased.
If you setdisk=Truethe disk size will be upgraded, and you will not be able to shrink your droplet down to it's previous RAM size.droplet_object.resize_droplet(slug_size='s-1vcpu-2gb',disk_resize=False)A Droplet must be powered off prior to resizing, digitaloceandroplets does this for you.Delete DropletYou can delete a droplet from your account by applying the following method.droplet_object.delete()This method sets your objectsdroplet_object.deleted=Trueso object methods will no longer work.⬆ back to topBlock Storage (Volumes)DigitalOcean Block Storage Volumesprovide expanded storage capacity for your Droplets and can be moved between Droplets within a specific region. Volumes function as raw block devices, meaning they appear to the operating system as locally attached storage which can be formatted using any file system supported by the OS. They may be created in sizes from 1GiB to 16TiB.Import the digitaloceanobject Volume and VolumeManger to interact with or create new volumes.fromdigitaloceanobjectsimportVolume,VolumeManagerVolume ManagerCreate a volume manager.volume_manager=VolumeManager()Create New VolumeTo create a new volume use the following method supplying your desired volumeAttribute Values.volume_object=volume_manager.create_new_volume(size_gigabytes=10,name="testingavolume",region="ams3",description="BlockStoreExample",filesystem_type="ext4",filesystem_label="example",tags=["banana"],)Note: You can only create one volume per region with the same name.Retrieve All VolumesTo list all available volumes on your account apply the following method.A list ofvolume objectswill be returned.list_of_volume_objects=volume_manager.retrieve_all_volumes()Retrieve All Volumes By NameTo list volumes on your account that match a specified name use the following method.list_of_volume_objects=volume_manager.retrieve_all_volumes_by_name(name:str)Retrieve Volume By IDTo retrieve a volume by id, apply the following method.volume_object=volume_manager.retrieve_volume_by_id(id:int)Retrieve Volume By Name And RegionYou can also pick out a specific existing volume by name and region, but calling the following method.volume_object=volume_manager.retrieve_volume_by_name_region(name:str,region:str)Retrieve Volumes With ANY TagsTo retrieve a list of volumes that match any, at least one, of your specified tags use the following method and supply a list of tag strings.list_of_volume_objects=volume_manager.retrieve_volumes_with_any_tags(tag:list)Retrieve Volumes With ALL TagsTo retrieve a list of volumes that are tagged with all, at least all, of your specified tags use the following command.list_of_volume_objects=volume_manager.retrieve_volumes_with_all_tags(tag:list)Retrieve Volumes With ONLY TagsTo retrieve a list of volumes that are tagged with only, exactly matching, your list of specified tags, apply the following method supplying a list of tag strings.list_of_volume_objects=volume_manager.retrieve_volumes_with_only_tags(tag:list)Delete Volume By IDThe volume manager allows you to delete a volume by supplying its ID.Though you may prefer to delete a volume by directly calling delete on its volume object.volume_manager.delete_volumes_by_id(id:int)Delete Volume By Name And RegionThe volume manager allows you to delete a volume by supplying its name and region.Though you may prefer to delete a volume by directly calling delete on its volume object.volume_manager.delete_volume_by_name_region(name:str,region:str)Delete Volumes With ANY TagsYou can delete all volumes that match any of, at least one, of your specified tags by applying the following method and supplying a list of tag strings.volume_manager.delete_volumes_with_any_tags(tag:list)Delete Volumes With ALL TagsYou can delete all volumes that contain, at least have all, of your specified tags by applying the following method and supplying a list of tag strings.volume_manager.delete_volumes_with_all_tags(tag:list)Delete Volumes With ONLY TagsYou can also delete all volume that only contain, that match exactly, your list of specified tag strings by applying the following method.volume_manager.delete_volumes_with_only_tags(tag:list)⬆ back to topVolume ObjectVolume objects contain an attributes data class with the standard digital oceanvolume attributes.volume_object=Volume()classVolume:def__init__(self):self.attributes=VolumeAttributes()self.deleted=False...@dataclassclassVolumeAttributes:id:str=Noneregion:object=field(default_factory=list)droplet_ids:list=field(default_factory=list)name:str=Nonedescription:str=Nonesize_gigabytes:int=Nonecreated_at:str=Nonefilesystem_type:str=Nonefilesystem_label:str=Nonetags:list=field(default_factory=list)Create SnapshotYou can create asnapshotfrom your volume using the following method.Asnapshotwill be returned.snapshot_object=volume_object.create_snapshot(name:str,tags:list)Retrieve SnapshotsYou can retrieve a list of snapshots for your object using the following method.A list ofsnapshotobjects will be returned.list_of_snapshot_objects=volume_object.retrieve_snapshots()Detach From DropletsYou can detach a volume from a droplet by calling the following method.
No need to supply details of a droplet as volumes can only be attached to one droplet at a time. This method just makes sure the volume object detaches.volume_object.detach_from_droplets()Resize VolumeTo resize a volume to a new size in GiB (1024^3), call the following method.Volumes may only be resized upwards.
The maximum size for a volume is 16TiB.volume_object.resize(size_gigabytes:int)⬆ back to topSnapshotsSnapshotsare saved instances of a Droplet or a block storage volume, which is reflected in theresource_typeattribute. In order to avoid problems with compressing filesystems, each defines amin_disk_sizeattribute which is the minimum size of the Droplet or volume disk when creating a new resource from the saved snapshot.Import the digitaloceanobject Snapshot and SnapshotManger to interact with or create new snapshots.fromdigitaloceanobjectsimportSnapshot,SnapshotManagerSnapshot ManagerCreate a snapshot manager.snapshot_manager=SnapshotManager()Retrieve All SnapshotsTo retrieve all existing snapshots call the following method.A list ofSnapshot objectswill be returned.list_of_snapshot_objects=snapshot_manager.retrieve_all_snapshots()Retrieve All Droplet SnapshotsTo retrieve a list of only droplet snapshots call the following method.Snapshot objectswill be returned, remember to not confiuse this with DropletSnapshot objects.list_of_snapshot_objects=snapshot_manager.retrieve_all_droplet_snapshots()Retrieve All Volume SnapshotsTo retrieve a list of only volume snapshots call the following method.list_of_snapshot_objects=snapshot_manager.retrieve_all_volume_snapshots()Retrieve Snapshot By IDYou can retrieve a snapshot object by ID.snapshot_object=snapshot_manager.retrieve_snapshots_id(id:int)⬆ back to topSnapshot ObjectSnapshot objects contains an attributes data class with the standard digital oceansnapshot attributes.snapshot_object=Snapshot()classSnapshot:def__init__(self):self.attributes=SnapshotAttributes()...@dataclassclassSnapshotAttributes:id:str=Nonename:str=Nonecreated_at:str=Noneregions:list=field(default_factory=list)resource_id:str=Noneresource_type:str=Nonemin_disk_size:int=Nonesize_gigabytes:float=Nonetags:list=field(default_factory=list)Delete SnapshotYou can delete a snapshot from your account by calling the snapshot object delete method.snapshot_object.delete()⬆ back to topFloating IPsDigitalOcean Floating IPsare publicly-accessible static IP addresses that can be mapped to one of your Droplets. They can be used to create highly available setups or other configurations requiring movable addresses.Floating IPs are bound to a specific region.Import the digitaloceanobject FloatingIP and FloatingIPManger to interact with or create new floating ips.fromdigitaloceanobjectsimportFloatingIP,FloatingIPManagerFloating IP ManagerCreate a floating IP manager.floatingip_manager=FloatingIPManager()Retrieve All Floating IPsTo retrieve all floating IPs on your account, call the following method.A list offloating ip objectswill be returned.list_of_floatingip_objects=floatingip_manager.retrieve_all_floating_ips()Create New Floating IPCreates a floating IP and attaches it straight to the specified droplet object.Afloating ip objectis returned with details of your new floating ip.floatingip_object=floatingip_manager.create_new_floating_ip(droplet_object:Droplet)Create Region Reserve IPYou can reserve a floating ip in a specified region by calling the following method and specifying a region slug.floatingip_object=floatingip_manager.reserve_ip_for_region(region_slug:str)Retrieve Floating IPYou can retrieve details of floating ip by using the ip address itself.
Call the following method and specifying the ip address.floatingip_object=floatingip_manager.retrieve_floating_ip(ip:str)⬆ back to topFloating IP ObjectFloating IP objects contains an attributes data class with the standard digital oceanfloating IP attributes.floatingip_object=FloatingIP()classFloatingIP:def__init__(self):self.attributes=FloatingIPAttributes()...@dataclassclassFloatingIPAttributes:ip:str=Noneregion:object=Nonedroplet:object=Nonelocked:bool=NoneDelete Floating IPYou can delete a floating ip from your account by calling the following.floatingip_object.delete()Unassign Floating IP]You can unasign a floating ip from a droplet by calling the following.
Specifying a droplet is not necessary.floatingip_object.unassign()Retrieve All IP ActionsYou can retrieve all the actions applied to an ip by calling the following method.A list ofaction objectswill be returned.list_of_action_objects=floatingip_object.retrieve_all_actions()Retrieve Existing IP ActionYou can retrieve a specific action by specifying its id and using the following method.action_object=floatingip_object.retrieve_existing_actions(action_id:int)⬆ back to topActionsActionsare records of events that have occurred on the resources in your account. These can be things like rebooting a Droplet, or transferring an image to a new region.An action object is created every time one of these actions is initiated. The action object contains information about the current status of the action, start and complete timestamps, and the associated resource type and ID.Every action that creates an action object is available through this endpoint. Completed actions are not removed from this list and are always available for querying.Import the digitaloceanobject Action and ActionManger to interact with  actions.fromdigitaloceanobjectsimportAction,ActionManagerAction ManagerCreate an action manager.action_manager=ActionManager()Retrieve All ActionsThis will be the entire list of actions taken on your account, so it will be quite large. As with any large collection returned by the API, the results will be paginated with only 20 on each page by default but the following method collects them all, and returns all of them in a list of action objects.If you want to have direct access to the api call please check theactions.py. You can paginate using the api call but still benefit from the rate limit management of digitaloceanobjects.A list ofAction Objectsis returned.list_of_action_objects=action_manager.retrieve_all_actions()Retrieve ActionYou can retreive one action at a time if you like, by specifying the action id.action_object=action_manager.retrieve_action(action_id:int)Action ObjectAction objects contains an attributes data class with the standard digital oceanaction attributes.action_object=Action()classAction:def__init__(self,action_attributes:ActionAttributes):self.attributes=action_attributes'''@dataclassclassActionAttributes:id:int=Nonestatus:str=Nonetype:str=Nonestarted_at:str=Nonecompleted_at:str=Noneresource_id:int=Noneresource_type:str=Noneregion:object=Noneregion_slug:str=None⬆ back to topExceptionsSome exceptions for you to catch, to help your code run smoother.Droplet ExceptionsErrorDropletNotFoundErrorDropletNameContainsInvalidCharsErrorDropletSlugSizeNotFoundErrorDropletResizeDiskErrorErrorAccountDropletLimitReachedErrorDropletAttachedVolumeCountAlreadAtLimitVolume ExceptionsErrorVolumeAlreadyExistsErrorVolumeNotFoundErrorVolumeResizeValueTooLargeErrorVolumeResizeDirectionErrorAccountVolumeLimitReachedSnapshot ExceptionsErrorSnapshotNotFoundAction ExceptionsErrorActionDoesNotExistsErrorActionFailedRegion ExceptionsErrorNotSameRegionErrorRegionDoesNotExistFloating IP ExceptionsErrorAccountFloatingIPLimitReachedErrorFloatingIPDoesNotExistsErrorDropletAlreadyHasFloatingIPSSH Key ExceptionsErrorSSHkeyDoesNotExists