-
-
Save peterkodermac/d9f5bbeeb8b70cfae8a3abb3d4e67799 to your computer and use it in GitHub Desktop.
import digitalocean | |
import random | |
api_key = 'REPLACE_API' | |
manager = digitalocean.Manager(token=api_key) | |
my_droplets = manager.get_all_droplets() | |
zmayDroplet=my_droplets[0] | |
zmayDroplet.take_snapshot('snapshot-'+str(random.randint(1,10000))) #this makes a snapshot | |
print "snapshot made" | |
snapshots=manager.get_all_snapshots() | |
if len(snapshots)>1: | |
destroySnapshot=digitalocean.Snapshot.get_object(api_key, snapshots[0].id) | |
destroySnapshot.destroy() | |
else: | |
print "no snapshots to delete" |
Hi thanks for you reply i will check and let you know
Thanks you so much It worked like a charm
But i have one doubt can we create snapshot for a particular Droplet?
Yes you can. In line 13 you select which droplet you want to backup. I have only 1 so I always use the first one.
You are genius ...
Thanks a lot code is working perfect..i need one more help
I am trying to create Loadbalancer from lastr two days but i can't able to do ,I am trying below code but no luck can you guide me how to create LoadBalancer and how can we add and remove the droplets from `LB?
import digitalocean
lb = digitalocean.LoadBalancer(token="api_token",
name= 'test',
region= 'BLR1',
forwarding_rules= ["entry_protocol::http"])
lb.create()
print('LB is Created')```
Thanks a lot code is working perfect..i need one more help
I am trying to create Loadbalancer from lastr two days but i can't able to do ,I am trying below code but no luck can you guide me how to create LoadBalancer and how can we add and remove the droplets from `LB?
import digitalocean
lb = digitalocean.LoadBalancer(token="api_token",
name= 'test',
region= 'BLR1',
forwarding_rules= ["entry_protocol::http"])lb.create()
print('LB is Created')```
sorry but I have no experience with loadbalancer whatsoever. Maybe there's something useful at the documentation of the library which you import at the beginning of the script.
Ok thanks no worries
Hey Hi ,
Hiw are you are doing
I just wanted to know can we create a snapshot basesd on the tag name or any otherway apart from position of droplet?
This script creates a new snapshot and deletes the old one