def decreaser(): threading.Timer(60.0, decreaser).start() hosts = find_hosts() for host in hosts: #print(host) if host['balance'] > 0: subscribe_host(host['name'], -1) elif host['status'] == 'subscribed': delete_host(host['name'])
def create_host(name): newhost_data = get_hostdata(name) print("create host output: \n" + str(newhost_data)) image = newhost_data['image'] pwd = newhost_data['pwd'] pub_key = newhost_data['init_pub'] print("check image for " + name) if image == 'ubuntu': print("get lan ip for " + name) lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") print(lan_ip) print("get wan ip for " + name) wan_ip = get_free_wan() print(wan_ip) print("bind ip for " + name) bind_ip(name, wan_ip) print("run ansible for " + name) print( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_ubuntu.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_ubuntu.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') print("init " + name) init_host(name, lan_ip, wan_ip) print("subscribe " + name) subscribe_host(name, 99 - 33) elif image == 'centos': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_centos.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) subscribe_host(name, 99 - 33) elif image == 'debian': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_debian.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) subscribe_host(name, 99 - 33) elif image == 'freebsd': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_freebsd.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) subscribe_host(name, 99) elif image == 'freebsd-ufs': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_freebsd-ufs.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) subscribe_host(name, 99) elif image == 'bitcoind': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) bitcoin_data = { 'rpcuser': get_random_string(10), 'rpc_pwd': get_random_string(10), } os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_bitcoind.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' rpcuser='******'rpcuser'] + ' rpc_pwd=' + bitcoin_data['rpc_pwd'] + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) init_bitcoind(name, bitcoin_data) subscribe_host(name, 99) elif image == 'lnd': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) bitcoin_data = { 'rpcuser': get_random_string(10), 'rpc_pwd': get_random_string(10), } os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_lnd.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' rpcuser='******'rpcuser'] + ' rpc_pwd=' + bitcoin_data['rpc_pwd'] + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) init_bitcoind(name, bitcoin_data) subscribe_host(name, 99 - 66) elif image == 'clightning': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) sparko_data = { 'login': get_random_string(10), 'pwd_web': get_random_string(10), 'pwd_rw': get_random_string(10), 'pwd_ro': get_random_string(10), } os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_clightning.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' sparko_login='******'login'] + ' sparko_pwd_web=' + sparko_data['pwd_web'] + ' sparko_pwd_rw=' + sparko_data['pwd_rw'] + ' sparko_pwd_ro=' + sparko_data['pwd_ro'] + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) init_sparko(name, sparko_data) subscribe_host(name, 99) elif image == 'bsdjail': lan_ip = os.popen('ssh nvme cbsd dhcpd').read().rstrip("\n") wan_ip = get_free_wan() bind_ip(name, wan_ip) os.system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds.sh/ansible/create_jail.yml ' '--extra-vars="iname=' + name.replace('-', '_') + ' dname=' + name + ' pwd=' + pwd + ' pub_key=\'' + pub_key + '\' lan_ip=\'' + lan_ip + '\' wan_ip=\'' + wan_ip + '\'"') init_host(name, lan_ip, wan_ip) subscribe_host(name, 99) elif image in MARKET: if image == 'k8s': k8s_data = get_k8s()['data'] init_k8s(name, k8s_data) subscribe_host(name, 99) else: return False else: return False
print("creating host " + instance_name) create_host(instance_name) elif hostdata['status'] == 'subscribed': print("subscribing host " + instance_name) subscribed_data = get_hostdata(instance_name) # remember paid sats and manipulate sats to be added paid_sats = sats if subscribed_data['image'] == 'lnd': sats = int(paid_sats * 0.7) elif subscribed_data['image'] == 'bitcoind': sats = int(paid_sats * 1.2) elif subscribed_data['image'] in ['debian', 'centos']: sats = int(paid_sats * 1.5) elif subscribed_data['image'] in [ 'clightning', 'freebsd', 'freebsd-ufs' ]: sats = int(paid_sats * 2) elif subscribed_data['image'] == 'bsdjail': sats = int(paid_sats * 2.5) subscribe_host(instance_name, sats) notify(instance_name + " top up for " + str(sats) + " (paid " + str(paid_sats) + " sats)") else: print('non-existent host topped up') print("paid invoice for:" + data['label']) except Exception as e: print("loading json exception: " + str(e))