def post(self): parser = reqparse.RequestParser() parser.add_argument('host') args = parser.parse_args() dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') hetz_hosts = get_hetzner() bit_hosts = get_bitbsd() try: addr = args['host'] result = {"status": "wrong host"} except KeyError as e: return {"error": "need a host (btc addr)"} for host in hetz_hosts: if host['address'] == addr: result = { "ip": host['ipv4'], "pwd": host['pwd'], "status": "subscribed" } for host in bit_hosts: if host['address'] == addr: result = { "ip": 'bitbsd.org', "ssh_pwd": host['pwd'], "ssh_usr": '******', "rpc_user": host['rpc_user'], "rpc_pwd": host['rpc_pwd'], "rpc_port": host['rpc_port'], "ssh_port": host['ssh_port'] } accs = find_hosts() for acc in accs: if acc['address'] == addr: balance = acc['balance'] image = acc['image'] if (image == 'freebsd') or (image == 'bitcoind') or ( image == 'lightningd'): result['login_username'] = "******" if balance > 0: result['hours_left'] = balance else: result = {"status": "pending payment"} return result
def del_server(address): hosts = find_hosts() for host in hosts: if address == host['address']: image = host['image'] bitbsd_servers = get_bitbsd(image) for serv in bitbsd_servers: if serv['address'] == address: delete_jail(address) hetzner_servers = getServers() for serv in hetzner_servers: if serv['name'] == address: deleteServer(serv['id'])
def delete_jail(address): hosts = find_hosts() for host in hosts: if address == host['address']: image = host['image'] jails = get_bitbsd(image) for jail in jails: if jail['address'] == address: starname = jail['address'] jname = jail['id'] print('now removing from bitbsd ' + starname + "(" + jname + ")") system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds/controller/playbooks/remove_btcnode.yml --extra-vars="jname=' + str(jname) + '"')
def accountant(): threading.Timer(3600.0, accountant).start() hosts = find_hosts() for host in hosts: if host['status'] == 'subscribed': #print(host) deduct_host(host['address']) dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') os.system("echo '"+dtime + ": " + host['address'] + "is subscribed; balance: " + str( host['balance']) + "' >> /tmp/acc.log") print(dtime + ": " + host['address'] + "is subscribed; balance: " + str( host['balance'])) last = host['address'] for host in get_suspended(): dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') os.system("echo '" + dtime + ": " + host['address'] + " is expired; balance: " + str( host['balance']) + " - DELETING!' >> /tmp/acc.log") print(dtime + 'DELETING: ' + host['address']) del_server(host['address']) delete_host(host['address']) time.sleep(5)
def status(host): hetz_hosts = get_hetzner() bit_hosts = get_bitbsd() cln_hosts = get_bitbsd('lightningd') rs_hosts = get_bitbsd('rootshell') p2e_hosts = get_bitbsd('pay2exec') result = dict() for hh in hetz_hosts: if hh['address'] == host: result = { "ip": hh['ipv4'], "pwd": hh['pwd'] } for bh in bit_hosts: if bh['address'] == host: result = { "ip": 'bitclouds.link', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "rpc_user": bh['rpc_user'], "rpc_pwd": bh['rpc_pwd'], "rpc_port": bh['rpc_port'], "ssh_port": bh['ssh_port'] } for bh in cln_hosts: if bh['address'] == host: result = { "ip": 'bitclouds.link', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "ssh_port": bh['ssh_port'], "app_port": bh['app_port'], "user_port": bh['user_port'], "sparko": 'https://bitclouds.link:' + str(bh['sparko_port'])+'/rpc', "ssh2onion": "you can ssh directly to your .onion (/home/lightning/onion.domain) on port 22" } for bh in p2e_hosts: if bh['address'] == host: result = { "ip": 'pay2exec.dev', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "ssh_port": bh['ssh_port'], "app_port": bh['app_port'], "web_port": bh['user_port'], "sparko": 'https://pay2exec.dev:' + str(bh['sparko_port'])+'/rpc', "webapp": 'http://pay2exec.dev:'+str(bh['user_port'])+'/', "ssh2onion": "you can open web/ssh directly to your .onion (/home/lightning/onion.domain) on port 80/22" } for bh in rs_hosts: if bh['address'] == host: result = { "ip": 'bitclouds.link', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "ssh_port": bh['ssh_port'], "app_port": bh['app_port'] } accs = find_hosts() for acc in accs: if acc['address'] == host: balance = acc['balance'] image = acc['image'] result['status'] = acc['status'] if balance > 0: result['hours_left'] = balance else: result = { "status": "awaiting payment! if you paid already wait until your instance is created." } return result
import configparser import os import datetime import time import sys config = configparser.ConfigParser() config.read('../controller/config.ini') from ctrldbops import find_hosts, deduct_host, get_suspended, delete_host, get_bitbsd, hardclear from orchestrator import del_server hosts = find_hosts() if sys.argv[1] in ['new', 'subscribed', 'deleted', 'suspended']: for host in hosts: if host['status'] == sys.argv[1]: print(host) elif sys.argv[1] == 'housekeeper': for host in hosts: if host['status'] == 'deleted': del_server(host['address']) elif sys.argv[1] == 'bc': for host in get_bitbsd('rootshell'): print(host) for host in get_bitbsd('lightningd'): print(host) elif sys.argv[1] == 'del': host2del = sys.argv[2] for host in hosts: