Exemple #1
0
    def cron_read(request, mnidx):
        coin = Polis(config["Polis"])
        vps = VPS(config["masternodes"][mnidx], coin)
        result = {"result": vps.actions("view_crontab", coin).splitlines()}
        logging.info(f"Crontab requested got:\n{result}")

        return json.dumps(result)
Exemple #2
0
    def start_polisd(request):

        if request.method == 'POST':
            mns = request.form.getlist('mns')
            actions = request.form.getlist('params')

            result = 'Attempted starting: ' + ', '.join(mns)
            for idx in mns:
                vps = VPS(config['masternodes'][int(idx)],
                          Polis(config['Polis']))
                result = vps.daemon_action(Polis(config["Polis"]))
                logging.info(f"Restarted {vps.getIP()} got: {result}")

            return f"Result of polisd {actions}: {result} <br><a href=/mns/cli/masternodes/status></a>"
        else:
            #diisplay list of all MNs with "start" button
            mnlist = "<form method='POST'>\n<select name=mns multiple>\n"
            idx = 0

            for masternode in config["masternodes"]:
                mnlist += f"\t<option value='{str(idx)}'>{masternode['connection_string']}</option>\n"
                idx += 1

            mnlist += "</select>\n"
            return mnlist + "<p><input type=submit value=start></form>"
Exemple #3
0
def upgrade(request, mnidx):
    coin = Polis(config["Polis"])
    vps = VPS(config["masternodes"][mnidx], coin)

    logging.info(f"vps.upgrade called ! for: {vps.getIP()}")
    result = vps.upgrade(coin)
    return result
Exemple #4
0
    def daemon_masternode_start(request, mn_idx, reindex):
        coin = Polis(config['Polis'])

        vps = VPS(config["masternodes"][mn_idx], coin)
        result = vps.kill_daemon(coin)
        time.sleep(10)
        logging.info(f"Killed daemon {result}")
        result = vps.daemon_action(coin, reindex)
        logging.info(f"Executed: polisd @ {mn_idx} returned: {result}")
        return result
Exemple #5
0
    def cli_mn_action(request, mnidx, actidx=0):
        actions = {
            'mnstat': 'masternode status',
            'gi': 'getinfo',
            'mnss': 'mnsync status',
            'mnsr': 'mnsync reset'
        }

        coin = Polis(config["Polis"])
        vps = VPS(config["masternodes"][mnidx], coin)

        result = vps.async_cli(actions[actidx], coin)
        return result
Exemple #6
0
 def ps(request, mnidx):
     coin = Polis(config["Polis"])
     return json.dumps({
         "result":
         VPS(config["masternodes"][mnidx], coin).actions("ps",
                                                         coin).splitlines()
     })
Exemple #7
0
def action(mnidx, actidx=0):
    coin = Polis(config["Polis"])
    vps = VPS(config["masternodes"][mnidx], coin)
    res = vps.async_cli(actions[actidx], coin)
    memcached.client.set('{}{}'.format(actidx, mnidx), res)
Exemple #8
0
 def crontab_clean(request, mnidx):
     coin = Polis(config['Polis'])
     return VPS(config["masternodes"][mnidx],
                coin).actions("clean_dupes_ctab", coin)
Exemple #9
0
def create(request):
    """
    Create a new Masternode :
    Deploy a new MN based on form information, also save it to config
    TODO:
        - Runs script to update VPS, copy polis binary from local,
        generate priv key, install sentinel and crontab job, install
        cron task to watch daemon every minute and relaunch it
    :param request:
    :return:
    """
    if request.method == b'POST':
        password = (request.args.get(b'password', [0])[0]).decode()
        ip = (request.args.get(b'ip', [0])[0]).decode()
        port = (request.args.get(b'port', [0])[0]).decode()
        name = (request.args.get(b'name', [0])[0]).decode()
        user = (request.args.get(b'user', [0])[0]).decode()

        logging.info(
            f"ip = {ip}, password = {password}, port = {port}, name = {name}")

        coin = Polis(config['Polis'])

        masternode = {
            "connection_string": f"{user}@{ip}:{port}",
            "password": password,
            "name": name
        }

        vps = VPS(masternode, coin)
        '''
        does all the apt get
        get polisd from another mn if not available locally (polis.tgz)
        '''
        result = vps.preconf(coin)
        logging.info(
            f"Preconf done apt gets and made directorys, copied polis.tgz:\n{result}"
        )

        result = vps.daemonconf(coin)
        logging.info(f"Daemon configured\n{result}")

        masternode["masternodeprivkey"] = result

        result = vps.install_watcher(Polis(config["Polis"]))
        logging.info(f"Uploaded and ran watcher_cron.sh :\n {result}")

        result = vps.install_sentinel(coin)
        logging.info(f"Uploaded and ran sentinel_setup.sh :\n {result}")

        config["masternodes"].append(masternode)

        with open('config.json', 'w') as outfile:
            json.dump(config,
                      outfile,
                      sort_keys=True,
                      indent=4,
                      ensure_ascii=False)

        return f"{{\"status\":\"{masternode.masternodeprivkey}}}\""

    else:
        template = "new_mn.html"
        return render_without_request(template)
Exemple #10
0
 def watcher_install(request, mnidx):
     return VPS(config["masternodes"][mnidx],
                Polis(config['Polis'])).install_watcher(
                    Polis(config["Polis"]))