Skip to content
59 changes: 59 additions & 0 deletions py-core/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def node_start_page():
p_snapshot_restore = request.args.get("restore")
p_network = str(request.args.get("network"))
p_history_mode = str(request.args.get("mode"))
p_conseil_branch = str(request.args.get("conseil-branch"))
logging.debug("Node options retrieved from user.")

# Checking if there are any problems with the user input
Expand Down Expand Up @@ -93,6 +94,8 @@ def node_start_page():
data["restore"] = p_snapshot_restore
data["status"] = "starting"

data["conseil_branch"] = p_conseil_branch

if not request.args.get("arronax"):
data["arronax_port"] = 0

Expand All @@ -108,6 +111,13 @@ def node_start_page():
db.add_node(data)
logging.debug("Node added to database.")

if data["conseil_port"] != 0 and data["conseil_branch"] != "latest":
try:
node_functions.build_conseil_image(data["conseil_branch"])
except Exception:
flash("The branch given was not found in the Conseil Repository.", "error")
return render_template("node_options.html")

logging.debug("Adding node start job to work queue.")
job_queue.enqueue_call(func=node_functions.create_node, args=(data,), timeout=86400)
logging.debug("Node start job added to work queue.")
Expand Down Expand Up @@ -227,6 +237,55 @@ def get_ram():
return jsonify(ram=ram_data)


@app.route("/remove_conseil")
def remove_conseil():
p_name = str(request.args.get("name"))
db.remove_conseil(p_name)
db.remove_arronax(p_name)
job_queue.enqueue_call(func=node_functions.stop_node, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.remove_conseil, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.restart_node, args=(p_name,), result_ttl=-1)
return redirect("/node?name={}".format(p_name))


@app.route("/add_conseil")
def add_conseil():
p_name = str(request.args.get("name"))
p_conseil_branch = str(request.args.get("conseil_branch"))

if p_conseil_branch != "latest":
try:
node_functions.build_conseil_image(p_conseil_branch)
except Exception as e:
p_conseil_branch = "latest"

db.add_conseil(p_name, get_next_port(1)[0])
job_queue.enqueue_call(func=node_functions.stop_node, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.add_conseil, args=(p_name, p_conseil_branch), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.restart_node, args=(p_name,), result_ttl=-1)
return redirect("/node?name={}".format(p_name))


@app.route("/remove_arronax")
def remove_arronax():
p_name = str(request.args.get("name"))
db.remove_arronax(p_name)
job_queue.enqueue_call(func=node_functions.stop_node, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.remove_arronax, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.restart_node, args=(p_name,), result_ttl=-1)
return redirect("/node?name={}".format(p_name))


@app.route("/add_arronax")
def add_arronax():
p_name = str(request.args.get("name"))
db.add_arronax(p_name, get_next_port(1)[0])
job_queue.enqueue_call(func=node_functions.stop_node, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.add_arronax, args=(p_name,), result_ttl=-1)
job_queue.enqueue_call(func=node_functions.restart_node, args=(p_name,), result_ttl=-1)
return redirect("/node?name={}".format(p_name))


if __name__ == "__main__":
# Setup sqlite database with schema
logging.debug("Setting up database.")
Expand Down
8 changes: 8 additions & 0 deletions py-core/app/static/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ a {
height: 25px;
border-radius: 5px;
}
#conseilBranch {
font-family: "Raleway", 'sans-serif';
text-align: center;
font-size: 16px;
width: 250px;
height: 18px;
border-radius: 5px;
}
.radio-button-holder {
position: relative;
display: block;
Expand Down
49 changes: 49 additions & 0 deletions py-core/app/templates/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,55 @@ <h3>Node Options</h3>
<br>
</div>
</div>
<div class="option-box" id="conseil-options">
<br>
<h3>Conseil Options</h3>
<br>
<div class="node-button-holder">
{% if node['history_mode'] == 'archive' and node['conseil_port'] != 0%}
<a href="/remove_conseil?name={{node['name']}}">
<div class="button">
Remove Conseil
</div>
</a>
<br>
<br>
{% if node['history_mode'] == 'archive' and node['arronax_port'] == 0%}
<a href="/add_arronax?name={{node['name']}}">
<div class="button">
Add Arronax
</div>
</a>
<br>
<br>
{% endif %}
{% if node['history_mode'] == 'archive' and node['arronax_port'] != 0%}
<a href="/remove_arronax?name={{node['name']}}">
<div class="button">
Remove Arronax
</div>
</a>
<br>
<br>
{% endif %}
{% endif %}
{% if node['history_mode'] == 'archive' and node['conseil_port'] == 0%}
<form action="/add_conseil" method="get" id="add_conseil_form">
<div class="button" onclick="javascript:document.getElementById('add_conseil_form').submit()">
Add Conseil
</div>
<br>
<br>
<label>
Conseil Branch: <input type="text" value="latest" id="conseilBranch" name="conseil_branch">
</label>
<input type="hidden" value="{{ node['name'] }}" name="name">
</form>
<br>
<br>
{% endif %}
</div>
</div>
</div>

{% endblock %}
Expand Down
12 changes: 12 additions & 0 deletions py-core/app/templates/node_options.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ <h3>Setup Your Node</h3>
</label>
<br>
<br>
<label>
Conseil Branch
<br>
<input type="text" name="conseil-branch" id="conseilBranch" disabled="disabled" value="latest">
</label>
<br>
<br>
</div>
</div>
<button type="submit" id="submit-button" class="button">Submit</button>
Expand All @@ -140,13 +147,16 @@ <h3>Setup Your Node</h3>
var fullModeSelection = document.getElementById("fullModeSelection")
var rollingModeSelection = document.getElementById("rollingModeSelection")

var conseilBranchName = document.getElementById("conseilBranch")

var startArronax = document.getElementById("startArronax")
var startConseil = document.getElementById("startConseil")

archiveModeSelection.addEventListener("change", function () {
if(archiveModeSelection.checked) {
startArronax.disabled = false
startConseil.disabled = false
conseilBranchName.disabled = false
startArronax.checked = true
startConseil.checked = true
}
Expand All @@ -158,6 +168,7 @@ <h3>Setup Your Node</h3>
startConseil.checked = false
startArronax.disabled = "disabled"
startConseil.disabled = "disabled"
conseilBranchName.disabled = "disabled"
}
})

Expand All @@ -167,6 +178,7 @@ <h3>Setup Your Node</h3>
startConseil.checked = false
startArronax.disabled = "disabled"
startConseil.disabled = "disabled"
conseilBranchName.disabled = "disabled"
}
})

Expand Down
32 changes: 32 additions & 0 deletions py-core/app/util/database_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,35 @@ def remove_node(name):
s = get_new_session()
s.query(Node).filter_by(name=name).delete()
s.commit()


def remove_conseil(name):
s = get_new_session()
query = s.query(Node).filter_by(name=name).first()
query.conseil_port = 0
s.commit()
s.close()


def add_conseil(name, port):
s = get_new_session()
query = s.query(Node).filter_by(name=name).first()
query.conseil_port = port
s.commit()
s.close()


def remove_arronax(name):
s = get_new_session()
query = s.query(Node).filter_by(name=name).first()
query.arronax_port = 0
s.commit()
s.close()


def add_arronax(name, port):
s = get_new_session()
query = s.query(Node).filter_by(name=name).first()
query.arronax_port = port
s.commit()
s.close()
76 changes: 69 additions & 7 deletions py-core/app/util/docker_compose_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import yaml

from util.database_functions import *

CONSEIL_API_TEXT = \
"""
image: cryptonomictech/conseil:latest
Expand Down Expand Up @@ -69,7 +71,7 @@
expose:
- 5423
volumes:
- ../../data/conseil.sql:/docker-entrypoint-initdb.d/conseil.sql
- ./conseil.sql:/docker-entrypoint-initdb.d/conseil.sql
logging:
driver: "json-file"
"""
Expand Down Expand Up @@ -99,23 +101,23 @@


def get_conseil_docker_compose():
return yaml.load(CONSEIL_API_TEXT, Loader=yaml.BaseLoader)
return yaml.safe_load(CONSEIL_API_TEXT)


def get_lorre_docker_compose():
return yaml.load(LORRE_TEXT, Loader=yaml.BaseLoader)
return yaml.safe_load(LORRE_TEXT)


def get_postgres_docker_compose():
return yaml.load(POSTGRES_TEXT, Loader=yaml.BaseLoader)
return yaml.safe_load(POSTGRES_TEXT)


def get_arronax_docker_compose():
return yaml.load(ARRONAX_TEXT, Loader=yaml.BaseLoader)
return yaml.safe_load(ARRONAX_TEXT)


def get_tezos_node_docker_compose():
return yaml.load(TEZOS_NODE_TEXT, Loader=yaml.BaseLoader)
return yaml.safe_load(TEZOS_NODE_TEXT)


def get_snapshot_tezos_node_docker_compose():
Expand Down Expand Up @@ -159,11 +161,71 @@ def build_docker_compose_file(data):
yaml_object["services"]["conseil-api"]["ports"] = ["{}:1337".format(data["conseil_port"])]
yaml_object["services"]["conseil-api"]["environment"]["CONSEIL_XTZ_NODE_PATH_PREFIX"] = ""

yaml_object["services"]["conseil-api"]["image"] = "cryptonomictech/conseil:{}".format(data["conseil_branch"])
yaml_object["services"]["conseil-lorre"]["image"] = "cryptonomictech/conseil:{}".format(data["conseil_branch"])

if data["arronax_port"] != 0:
yaml_object["services"]["arronax"] = get_arronax_docker_compose()

yaml_object["services"]["arronax"]["image"] = "arronax-{}".format(data["network"])
yaml_object["services"]["arronax"]["ports"] = ["{}:80".format(data["arronax_port"])]

return yaml.dump(yaml_object)
return yaml.safe_dump(yaml_object)


def remove_conseil_from_file(file):
yaml_object = yaml.safe_load(file.read()) or {}

yaml_object["services"].pop("conseil-api")
yaml_object["services"].pop("conseil-lorre")
yaml_object["services"].pop("conseil-postgres")

try:
yaml_object["services"].pop("arronax")
except Exception:
pass

file.write(yaml.safe_dump(yaml_object))


def add_conseil_to_file(file, name, branch):
yaml_object = yaml.safe_load(file.read()) or {}

data = get_node_data(name)

yaml_object["services"]["conseil-api"] = get_conseil_docker_compose()
yaml_object["services"]["conseil-lorre"] = get_lorre_docker_compose()
yaml_object["services"]["conseil-postgres"] = get_postgres_docker_compose()

yaml_object["services"]["conseil-lorre"]["environment"]["CONSEIL_XTZ_NETWORK"] = data["network"]
yaml_object["services"]["conseil-lorre"]["environment"]["LORRE_RUNNER_NETWORK"] = data["network"]
yaml_object["services"]["conseil-lorre"]["environment"]["CONSEIL_XTZ_NODE_PATH_PREFIX"] = ""
yaml_object["services"]["conseil-api"]["environment"]["CONSEIL_XTZ_NETWORK"] = data["network"]
yaml_object["services"]["conseil-api"]["ports"] = ["{}:1337".format(data["conseil_port"])]
yaml_object["services"]["conseil-api"]["environment"]["CONSEIL_XTZ_NODE_PATH_PREFIX"] = ""

yaml_object["services"]["conseil-api"]["image"] = "cryptonomictech/conseil:{}".format(branch)
yaml_object["services"]["conseil-lorre"]["image"] = "cryptonomictech/conseil:{}".format(branch)

file.write(yaml.safe_dump(yaml_object))


def add_arronax_to_file(file, name):
yaml_object = yaml.safe_load(file.read()) or {}

data = get_node_data(name)

yaml_object["services"]["arronax"] = get_arronax_docker_compose()

yaml_object["services"]["arronax"]["image"] = "arronax-{}".format(data["network"])
yaml_object["services"]["arronax"]["ports"] = ["{}:80".format(data["arronax_port"])]

file.write(yaml.safe_dump(yaml_object))


def remove_arronax_from_file(file):
yaml_object = yaml.safe_load(file.read()) or {}

yaml_object["services"].pop("arronax")

file.write(yaml.safe_dump(yaml_object))
2 changes: 1 addition & 1 deletion py-core/app/util/scripts/delete_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ name=$1

cd "$HOME/.nautilus-core/$name" || exit 1

docker-compose down
docker-compose down --remove-orphans
2 changes: 1 addition & 1 deletion py-core/app/util/scripts/restart_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ name=$1

cd "$HOME/.nautilus-core/$name" || exit 1

docker-compose up -d
docker-compose up -d --remove-orphans
2 changes: 1 addition & 1 deletion py-core/app/util/scripts/start_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ name=$1

cd "$HOME/.nautilus-core/$name" || exit 1

docker-compose up -d
docker-compose up -d --remove-orphans
Loading