2021-02-17 21:07:12 -05:00
|
|
|
#!/srv/newsblur/venv/newsblur3/bin/python
|
2021-02-04 17:42:55 -05:00
|
|
|
import os
|
|
|
|
import digitalocean
|
|
|
|
|
|
|
|
TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.token"
|
|
|
|
|
2021-02-18 20:53:23 -05:00
|
|
|
OLD = False
|
|
|
|
# Uncomment below to allow existing servers to find the consul-manager
|
|
|
|
OLD = True
|
|
|
|
|
2021-02-04 17:42:55 -05:00
|
|
|
with open(TOKEN_FILE) as f:
|
|
|
|
token = f.read().strip()
|
|
|
|
os.environ['DO_API_TOKEN'] = token
|
|
|
|
|
|
|
|
manager = digitalocean.Manager(token=token)
|
|
|
|
my_droplets = manager.get_all_droplets()
|
2021-05-12 15:41:17 -04:00
|
|
|
consul_manager_droplets = [d for d in my_droplets if d.name.startswith("db-consul")]
|
2021-02-18 20:53:23 -05:00
|
|
|
if OLD:
|
2021-05-12 15:41:17 -04:00
|
|
|
consul_manager_ip_address = ','.join([f"\"{droplet.ip_address}\"" for droplet in consul_manager_droplets])
|
2021-02-18 20:53:23 -05:00
|
|
|
else:
|
2021-05-12 15:41:17 -04:00
|
|
|
consul_manager_ip_address = ','.join([f"\"{droplet.private_ip_address}\"" for droplet in consul_manager_droplets])
|
2021-02-04 17:42:55 -05:00
|
|
|
|
2021-02-10 18:38:38 -05:00
|
|
|
print(consul_manager_ip_address)
|
|
|
|
|
|
|
|
# # write or overwrite the consul-manager ip
|
|
|
|
# if "consul_manager_ip.txt" not in os.listdir('/srv/newsblur/consul/'):
|
|
|
|
# with open('/srv/newsblur/consul/consul_manager_ip.txt', 'w') as f:
|
|
|
|
# f.write(consul_manager_ip_address)
|