Skip to content

Instantly share code, notes, and snippets.

@heffo42
Last active July 7, 2019 19:05
Show Gist options
  • Save heffo42/e27a71497dcfce1b19f1867c72ad0728 to your computer and use it in GitHub Desktop.
Save heffo42/e27a71497dcfce1b19f1867c72ad0728 to your computer and use it in GitHub Desktop.
import digitalocean
from pymongo import MongoClient
#Creation
with open('/Users/dhefferna/Desktop/TwitterProject/Admin/cloud-config.yml', 'r') as file:
USER_DATA = file.read()
SSH = ["ssh pubkey"]
key = "<DigitalOcean API Key>"
for i in range(100):
droplet = digitalocean.Droplet(token=key,
name=f'node-{str(i).zfill(2)}',
region='nyc3',
image='docker-18-04',
size_slug='s-1vcpu-1gb',
backups=False,
ssh_keys=SSH,
private_networking = True,
user_data=USER_DATA)
droplet.create()
#Deletion
client = MongoClient('mongodb://monogdb:27017', username='<username>', password='<password>', authSource='admin')
todoCol = client['twitter']['queriesTodo']
while True:
if todoCol.find_one() == None:
manager = digitalocean.Manager(token=key)
my_droplets = manager.get_all_droplets()
[droplet.destroy() for droplet in my_droplets]
break
else
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment