2021-01-26 19:45:15 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
2021-02-08 15:57:00 -05:00
|
|
|
import time
|
|
|
|
import sys
|
2021-01-26 19:45:15 -05:00
|
|
|
import subprocess
|
2021-02-08 15:57:00 -05:00
|
|
|
import digitalocean
|
2021-01-26 19:45:15 -05:00
|
|
|
|
2021-01-28 19:06:30 -05:00
|
|
|
TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.token"
|
|
|
|
# TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.readprod.token"
|
2021-01-26 19:45:15 -05:00
|
|
|
|
2021-02-08 15:57:00 -05:00
|
|
|
try:
|
|
|
|
api_token = open(TOKEN_FILE, 'r').read().strip()
|
|
|
|
except IOError:
|
|
|
|
print(f" ---> Missing Digital Ocean API token: {TOKEN_FILE}")
|
|
|
|
exit()
|
2021-01-26 19:45:15 -05:00
|
|
|
|
2021-01-29 11:27:45 -05:00
|
|
|
# Install from https://github.com/do-community/do-ansible-inventory/releases
|
2021-02-08 15:57:00 -05:00
|
|
|
ansible_inventory_cmd = f'do-ansible-inventory -t {api_token} --out /srv/newsblur/ansible/inventories/digital_ocean.ini'
|
|
|
|
subprocess.call(ansible_inventory_cmd,
|
2021-01-26 19:45:15 -05:00
|
|
|
shell=True)
|
2021-02-08 15:57:00 -05:00
|
|
|
|
2021-02-08 17:10:33 -05:00
|
|
|
do = digitalocean.Manager(token=api_token)
|
|
|
|
droplets = do.get_all_droplets()
|
|
|
|
|
|
|
|
print("\n ---> Checking droplets: %s\n" % (' '.join([d.name for d in droplets])))
|
|
|
|
|
|
|
|
|
|
|
|
def check_droplets_created():
|
2021-02-08 15:57:00 -05:00
|
|
|
droplets = do.get_all_droplets()
|
2021-02-08 17:10:33 -05:00
|
|
|
|
|
|
|
for instance in droplets:
|
|
|
|
if instance.status == 'new':
|
2021-02-08 15:57:00 -05:00
|
|
|
print(".", end=' ')
|
|
|
|
sys.stdout.flush()
|
|
|
|
i += 1
|
|
|
|
time.sleep(i)
|
2021-02-08 17:10:33 -05:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
print(" ---> All booted!")
|
|
|
|
return True
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
if check_droplets_created():
|
|
|
|
break
|