Compare commits
No commits in common. "1894a6dce9747b4aa6a8c9e44f9160ba0744a57d" and "67f10102b38f63f28628c6081d1422539e844a0e" have entirely different histories.
1894a6dce9
...
67f10102b3
3 changed files with 35 additions and 56 deletions
|
@ -144,7 +144,7 @@ class PeeringManager:
|
||||||
print(wg_enable)
|
print(wg_enable)
|
||||||
wg_up = subprocess.run(self.__config["wg-commands"]["up"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
wg_up = subprocess.run(self.__config["wg-commands"]["up"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
print(wg_up)
|
print(wg_up)
|
||||||
time.sleep(3)
|
time.sleep(5)
|
||||||
with open(f"{self.__config['bird-peers']}/dn42_{peering['MNT'][:-4].lower()}_{peering['ASN'][-4:]}.conf", "w") as bgp_file:
|
with open(f"{self.__config['bird-peers']}/dn42_{peering['MNT'][:-4].lower()}_{peering['ASN'][-4:]}.conf", "w") as bgp_file:
|
||||||
bgp_file.write(bgp_conf)
|
bgp_file.write(bgp_conf)
|
||||||
bgp_reload = subprocess.run(self.__config["bird-reload"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
bgp_reload = subprocess.run(self.__config["bird-reload"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
|
@ -161,7 +161,7 @@ class PeeringManager:
|
||||||
print(wg_down)
|
print(wg_down)
|
||||||
wg_up = subprocess.run(self.__config["wg-commands"]["up"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
wg_up = subprocess.run(self.__config["wg-commands"]["up"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
print(wg_up)
|
print(wg_up)
|
||||||
time.sleep(3)
|
time.sleep(5)
|
||||||
with open(f"{self.__config['bird-peers']}/dn42_{peering['MNT'][:-4].lower()}_{peering['ASN'][-4:]}.conf", "w") as bgp_file:
|
with open(f"{self.__config['bird-peers']}/dn42_{peering['MNT'][:-4].lower()}_{peering['ASN'][-4:]}.conf", "w") as bgp_file:
|
||||||
bgp_file.write(bgp_conf)
|
bgp_file.write(bgp_conf)
|
||||||
bgp_reload = subprocess.run(self.__config["bird-reload"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
bgp_reload = subprocess.run(self.__config["bird-reload"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
|
@ -172,7 +172,7 @@ class PeeringManager:
|
||||||
os.remove(f"{self.__config['bird-peers']}/dn42_{peering['MNT'][:-4].lower()}_{peering['ASN'][-4:]}.conf")
|
os.remove(f"{self.__config['bird-peers']}/dn42_{peering['MNT'][:-4].lower()}_{peering['ASN'][-4:]}.conf")
|
||||||
bgp_reload = subprocess.run(self.__config["bird-reload"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
bgp_reload = subprocess.run(self.__config["bird-reload"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
print(bgp_reload)
|
print(bgp_reload)
|
||||||
time.sleep(3)
|
time.sleep(5)
|
||||||
wg_down = subprocess.run(self.__config["wg-commands"]["down"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
wg_down = subprocess.run(self.__config["wg-commands"]["down"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
print(wg_down)
|
print(wg_down)
|
||||||
wg_disable = subprocess.run(self.__config["wg-commands"]["disable"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
wg_disable = subprocess.run(self.__config["wg-commands"]["disable"].replace("{PEERING}",peering['ASN'][-6:] if len(peering["ASN"]) >=6 else peering["ASN"]).split(" "))
|
||||||
|
|
|
@ -391,9 +391,8 @@ def peerings_new():
|
||||||
|
|
||||||
if not peering_valid:
|
if not peering_valid:
|
||||||
return render_template("peerings-new.html", session=session, config=config, peerings=peerings, msg=peering_or_msg), 400
|
return render_template("peerings-new.html", session=session, config=config, peerings=peerings, msg=peering_or_msg), 400
|
||||||
success, code = peerings.add_peering(session["user-data"]["asn"], request.args["node"], session["user-data"]["mnt"], peering_or_msg["peer-wgkey"], peering_or_msg["peer-endpoint"], peering_or_msg["peer-v6ll"], peering_or_msg["peer-v4"], peering_or_msg["peer-v6"], peering_or_msg["bgp-mp"], peering_or_msg["bgp-enh"])
|
if not peerings.add_peering(session["user-data"]["asn"], request.args["node"], session["user-data"]["mnt"], peering_or_msg["peer-wgkey"], peering_or_msg["peer-endpoint"], peering_or_msg["peer-v6ll"], peering_or_msg["peer-v4"], peering_or_msg["peer-v6"], peering_or_msg["bgp-mp"], peering_or_msg["bgp-enh"]):
|
||||||
if not success:
|
return render_template("peerings-new.html", session=session, config=config, peerings=peerings, msg="this ASN already has a peering with the requested node"), 400
|
||||||
return render_template("peerings-new.html", session=session, config=config, peerings=peerings, msg="this ASN already has a peering with the requested node or something failed in the backend, please retry later"), code
|
|
||||||
|
|
||||||
return redirect(f"{config['base-dir']}peerings")
|
return redirect(f"{config['base-dir']}peerings")
|
||||||
|
|
||||||
|
@ -412,7 +411,6 @@ def peerings_view():
|
||||||
elif request.method == "DELETE":
|
elif request.method == "DELETE":
|
||||||
return peerings_delete()
|
return peerings_delete()
|
||||||
else:
|
else:
|
||||||
# shouldn't get here
|
|
||||||
abort(405)
|
abort(405)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,21 +15,14 @@ class NodeCommunicator:
|
||||||
self.__api_addr = config["api-con"]
|
self.__api_addr = config["api-con"]
|
||||||
|
|
||||||
def update(self, action: str, peering: dict):
|
def update(self, action: str, peering: dict):
|
||||||
try:
|
if action == "add":
|
||||||
if action == "add":
|
print(requests.post(f"{self.__api_addr}peerings", json=peering))
|
||||||
req = requests.post(f"{self.__api_addr}peerings", json=peering, timeout=6)
|
elif action == "update":
|
||||||
elif action == "update":
|
print(requests.put(f"{self.__api_addr}peerings", json=peering))
|
||||||
req = requests.put(f"{self.__api_addr}peerings", json=peering, timeout=6)
|
elif action == "delete":
|
||||||
elif action == "delete":
|
print(requests.delete(f"{self.__api_addr}peerings", json=peering))
|
||||||
req = requests.delete(f"{self.__api_addr}peerings", json=peering, timeout=6)
|
else:
|
||||||
else:
|
return 400
|
||||||
return 400
|
|
||||||
|
|
||||||
# should only get here if a request was "successful" (not necessarily http code 200)
|
|
||||||
return req.status_code
|
|
||||||
except requests.exceptions.ReadTimeout:
|
|
||||||
# if it took more than timeout for the client to respond
|
|
||||||
return 504
|
|
||||||
|
|
||||||
|
|
||||||
class PeeringManager:
|
class PeeringManager:
|
||||||
|
@ -85,13 +78,15 @@ class PeeringManager:
|
||||||
new_peering: if mode=="update" the new peering to update to
|
new_peering: if mode=="update" the new peering to update to
|
||||||
"""
|
"""
|
||||||
if peering["node"] in self._nodes:
|
if peering["node"] in self._nodes:
|
||||||
return_code = self._nodes[peering["node"]].update(action=action, peering = peering if not new_peering else new_peering)
|
#thread = threading.Thread(target=
|
||||||
if return_code in [200, 201]:
|
self._nodes[peering["node"]].update(#), kwargs={
|
||||||
return True, return_code
|
action=action, peering = peering if not new_peering else new_peering#, })
|
||||||
else:
|
)
|
||||||
return False, return_code
|
#thread.start()
|
||||||
|
#self._threads.append(thread)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return False, 404
|
return False
|
||||||
|
|
||||||
def _update_amounts(self):
|
def _update_amounts(self):
|
||||||
__new = {}
|
__new = {}
|
||||||
|
@ -163,14 +158,10 @@ class PeeringManager:
|
||||||
|
|
||||||
peering = {"MNT": mnt, "ASN": asn, "node": node, "wg_key": wg_key, "endpoint": endpoint,
|
peering = {"MNT": mnt, "ASN": asn, "node": node, "wg_key": wg_key, "endpoint": endpoint,
|
||||||
"ipv6ll": ipv6ll, "ipv4": ipv4, "ipv6": ipv6, "bgp_mp": bgp_mp, "bgp_enh": bgp_enh}
|
"ipv6ll": ipv6ll, "ipv4": ipv4, "ipv6": ipv6, "bgp_mp": bgp_mp, "bgp_enh": bgp_enh}
|
||||||
success, code = self._update_nodes("add", peering=peering)
|
|
||||||
if not success:
|
|
||||||
# if ssomething failed notify user and don't add it to the list
|
|
||||||
return False, code
|
|
||||||
#
|
|
||||||
self.peerings["asn"][asn].append(peering)
|
self.peerings["asn"][asn].append(peering)
|
||||||
|
self._update_nodes("add", peering=peering)
|
||||||
self._save_peerings()
|
self._save_peerings()
|
||||||
return True, code
|
return True
|
||||||
|
|
||||||
def update_peering(self, asn, node, mnt, wg_key, endpoint=None, ipv6ll=None, ipv4=None, ipv6=None, bgp_mp=True, bgp_enh=True):
|
def update_peering(self, asn, node, mnt, wg_key, endpoint=None, ipv6ll=None, ipv4=None, ipv6=None, bgp_mp=True, bgp_enh=True):
|
||||||
# check if this MNT already has a/this asn
|
# check if this MNT already has a/this asn
|
||||||
|
@ -179,15 +170,13 @@ class PeeringManager:
|
||||||
# ... and add it if it hasn't
|
# ... and add it if it hasn't
|
||||||
self.peerings[mnt].append(asn)
|
self.peerings[mnt].append(asn)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# ... and create it if it doesn't have any yet
|
# ... and cerate it if it doesn't have any yet
|
||||||
self.peerings["mnter"][mnt] = [asn]
|
self.peerings["mnter"][mnt] = [asn]
|
||||||
try:
|
try:
|
||||||
# there are no peerings for this asn -> can't edit nothing...
|
|
||||||
if not asn in self.peerings["asn"]:
|
if not asn in self.peerings["asn"]:
|
||||||
return False, 404
|
return False
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# this should only happen if "asn" not in self.peerings
|
return False
|
||||||
return False, 404
|
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
for pNr in range(len(self.peerings["asn"][asn])):
|
for pNr in range(len(self.peerings["asn"][asn])):
|
||||||
|
@ -196,31 +185,23 @@ class PeeringManager:
|
||||||
new_peering = self.peerings["asn"][asn][pNr] = {"MNT": mnt, "ASN": asn, "node": node, "wg_key": wg_key,
|
new_peering = self.peerings["asn"][asn][pNr] = {"MNT": mnt, "ASN": asn, "node": node, "wg_key": wg_key,
|
||||||
"endpoint": endpoint, "ipv6ll": ipv6ll, "ipv4": ipv4, "ipv6": ipv6, "bgp_mp": bgp_mp, "bgp_enh": bgp_enh}
|
"endpoint": endpoint, "ipv6ll": ipv6ll, "ipv4": ipv4, "ipv6": ipv6, "bgp_mp": bgp_mp, "bgp_enh": bgp_enh}
|
||||||
success = True
|
success = True
|
||||||
peering_number = pNr
|
|
||||||
if not success:
|
if not success:
|
||||||
return False
|
return False
|
||||||
# notify the node
|
|
||||||
|
|
||||||
success, code = self._update_nodes("update", old_peering, new_peering=new_peering)
|
|
||||||
if not success:
|
|
||||||
# revert updating peering
|
|
||||||
self.peerings["asn"][asn][peering_number] = old_peering
|
|
||||||
return False, code
|
|
||||||
else:
|
|
||||||
|
|
||||||
self._save_peerings()
|
self._save_peerings()
|
||||||
return True, code
|
self._update_nodes("update", old_peering, new_peering=new_peering)
|
||||||
|
return True
|
||||||
|
|
||||||
def delete_peering(self, asn, node, mnt, wg_key=None):
|
def delete_peering(self, asn, node, mnt, wg_key=None):
|
||||||
if not self.exists(asn, node, mnt=mnt, wg_key=wg_key):
|
if not self.exists(asn, node, mnt=mnt, wg_key=wg_key):
|
||||||
return False, 404
|
return False
|
||||||
for p in self.peerings["asn"][asn]:
|
for p in self.peerings["asn"][asn]:
|
||||||
if p["node"] == node:
|
if p["node"] == node:
|
||||||
|
if wg_key and p["wg_key"] != wg_key:
|
||||||
|
continue
|
||||||
self.peerings["asn"][asn].remove(p)
|
self.peerings["asn"][asn].remove(p)
|
||||||
self._save_peerings()
|
self._save_peerings()
|
||||||
success, code = self._update_nodes("delete", peering=p)
|
self._update_nodes("delete", peering=p)
|
||||||
print(f"DELETE: {asn} on {node}: {success}, {code}")
|
return True
|
||||||
return success, code
|
|
||||||
# if nothing got found (should have been catched by self.exists)
|
# if nothing got found (should have been catched by self.exists)
|
||||||
return False, 404
|
return False
|
||||||
|
|
Loading…
Add table
Reference in a new issue