diff --git a/main.py b/main.py index 33be9bd..f87f5bc 100644 --- a/main.py +++ b/main.py @@ -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