Lève une erreur si la config proposée ne permet plus de joindre le switch

master
chirac 6 years ago committed by root
parent 57db5abf91
commit 004f9c998b

@ -31,16 +31,7 @@ ENV = Environment(loader=FileSystemLoader('.'))
# Création du template final avec les valeurs contenues dans le dictionnaire "valeurs" - Ces valeurs sont positionnées dans un objet "temp", qui sera utilisé par le moteur, et que l'on retrouve dans le template.
for arg in sys.argv:
if arg=="--force":
sw = Switch()
for switch in all_switchs:
sw.switch = switch
sw.gen_conf_and_write()
try:
sw.apply_conf()
except:
print("Erreur dans l'application de la conf pour " + switch["short_name"])
@ -86,6 +77,8 @@ class Switch:
#Trie les ip par vlan, et les ajoute ainsi que les subnet
for ip, subnet in self.switch["interfaces_subnet"].items():
if not subnet[0]["vlan_id"] in vlans:
raise RuntimeError("La config est dangeureuse, le vlan d'administration n'est pas propagé au switch !")
vlans[subnet[0]["vlan_id"]].setdefault("ipv4", {})
vlans[subnet[0]["vlan_id"]]["ipv4"][ip] = subnet
for ipv6, subnet in self.switch["interfaces6_subnet"].items():
@ -165,9 +158,12 @@ class Switch:
"""Génère la conf suivant le bon constructeur et l'écrit"""
if self.switch["model"]:
constructor = self.switch["model"]["constructor"].lower()
if "hp" in constructor or "aruba" in constructor:
self.gen_conf_hp()
self.write_conf()
try:
if "hp" in constructor or "aruba" in constructor:
self.gen_conf_hp()
self.write_conf()
except RuntimeError:
print("Il y a eu une erreur pour le switch %s, la config proposée n'est pas intègre" % self.switch["short_name"])
def apply_conf(self):
if self.check_and_get_login():
@ -183,12 +179,22 @@ class Switch:
f.write(self.conf)
for arg in sys.argv:
if arg=="--force":
sw = Switch()
for switch in all_switchs:
sw.switch = switch
sw.gen_conf_and_write()
try:
sw.apply_conf()
except:
print("Erreur dans l'application de la conf pour " + switch["short_name"])
for service in api_client.list("services/regen/"):
if service['hostname'] == client_hostname and \
service['service_name'] == 'switchs' and \
service['need_regen']:
error = False
error = False
sw=Switch()
for switch in all_switchs:
sw.switch = switch

Loading…
Cancel
Save