2013-05-20 12:03:04 -07:00
|
|
|
import sys
|
|
|
|
import os
|
2015-09-21 16:13:09 -07:00
|
|
|
import digitalocean
|
2013-05-20 12:03:04 -07:00
|
|
|
from django.conf import settings
|
|
|
|
|
2013-05-20 12:57:45 -07:00
|
|
|
sys.path.append('/srv/newsblur')
|
2013-05-20 12:03:04 -07:00
|
|
|
|
2020-10-13 22:10:26 +07:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'newsblur_web.settings'
|
2013-05-20 12:03:04 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-18 13:51:06 -05:00
|
|
|
# Check and clean second argument (ex: sshdo task 2)
|
|
|
|
second_arg = sys.argv[2] if len(sys.argv) > 2 else "1"
|
|
|
|
droplet_index = int(second_arg) if second_arg.isnumeric() else 1
|
|
|
|
|
|
|
|
# Use correct Digital Ocean team based on "old"
|
2021-01-28 19:06:30 -05:00
|
|
|
doapi = digitalocean.Manager(token=settings.DO_TOKEN_SSH)
|
2021-02-18 13:51:06 -05:00
|
|
|
if second_arg == "old":
|
2021-02-11 13:27:58 -05:00
|
|
|
doapi = digitalocean.Manager(token=settings.DO_TOKEN_FABRIC)
|
2021-02-18 13:51:06 -05:00
|
|
|
|
|
|
|
# Cycle through droplets finding match
|
2015-09-21 16:13:09 -07:00
|
|
|
droplets = doapi.get_all_droplets()
|
2013-05-20 12:03:04 -07:00
|
|
|
for droplet in droplets:
|
2021-02-18 13:51:06 -05:00
|
|
|
if droplet.name.startswith(sys.argv[1]):
|
|
|
|
if droplet_index > 1:
|
|
|
|
droplet_index -= 1
|
|
|
|
continue
|
2020-06-19 02:27:48 -04:00
|
|
|
print(droplet.ip_address)
|
2013-05-20 12:03:04 -07:00
|
|
|
break
|