mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-31 22:20:12 +00:00
Removing dependencies from ssh helper.
This commit is contained in:
parent
73380a2e74
commit
87c3b111a8
2 changed files with 15 additions and 22 deletions
|
@ -1,9 +1,10 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
import digitalocean
|
import digitalocean
|
||||||
from django.conf import settings
|
# from django.conf import settings
|
||||||
|
|
||||||
sys.path.append('/srv/newsblur')
|
sys.path.append('/srv/newsblur')
|
||||||
|
|
||||||
|
@ -12,23 +13,15 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'newsblur_web.settings'
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Check and clean second argument (ex: sshdo task 2)
|
# Check and clean second argument (ex: sshdo task 2)
|
||||||
second_arg = sys.argv[2] if len(sys.argv) > 2 else "1"
|
second_arg = sys.argv[2] if len(sys.argv) > 2 else "1"
|
||||||
droplet_index = int(second_arg) if second_arg.isnumeric() else 1
|
droplet_index = int(second_arg) if str(second_arg).isnumeric() else 1
|
||||||
droplet_name = sys.argv[1]
|
droplet_name = sys.argv[1]
|
||||||
|
|
||||||
# Use correct Digital Ocean team based on "old"
|
# Use correct Digital Ocean team based on "old"
|
||||||
|
commands = ['ansible-inventory', '--list']
|
||||||
|
env = None
|
||||||
if second_arg == "old":
|
if second_arg == "old":
|
||||||
doapi = digitalocean.Manager(token=settings.DO_TOKEN_FABRIC)
|
env = dict(os.environ, ANSIBLE_CONFIG="ansible.old.cfg")
|
||||||
# Cycle through droplets finding match
|
hosts = subprocess.check_output(commands, env=env)
|
||||||
droplets = doapi.get_all_droplets()
|
|
||||||
for droplet in droplets:
|
|
||||||
if droplet.name.startswith(droplet_name):
|
|
||||||
if droplet_index > 1:
|
|
||||||
droplet_index -= 1
|
|
||||||
continue
|
|
||||||
print(droplet.ip_address)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
hosts = subprocess.check_output(['ansible-inventory', '--list'])
|
|
||||||
if not hosts:
|
if not hosts:
|
||||||
print(" ***> Could not load ansible-inventory!")
|
print(" ***> Could not load ansible-inventory!")
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ LPURPLE='\033[01;35m'
|
||||||
LCYAN='\033[01;36m'
|
LCYAN='\033[01;36m'
|
||||||
WHITE='\033[01;37m'
|
WHITE='\033[01;37m'
|
||||||
|
|
||||||
ipaddr=`python /srv/newsblur/utils/hostname_ssh.py $1 $2`
|
ipaddr=`python3 /srv/newsblur/utils/hostname_ssh.py $1 $2`
|
||||||
printf "\n ${BLUE}---> ${LBLUE}Connecting to ${LGREEN}$1${BLUE} / ${LRED}$ipaddr${BLUE} <--- ${RESTORE}\n\n"
|
printf "\n ${BLUE}---> ${LBLUE}Connecting to ${LGREEN}$1${BLUE} / ${LRED}$ipaddr${BLUE} <--- ${RESTORE}\n\n"
|
||||||
if [ "$2" == "old" ];
|
if [ "$2" == "old" ];
|
||||||
then
|
then
|
||||||
|
|
Loading…
Add table
Reference in a new issue