diff --git a/main.py b/main.py index 860c7cd..3209723 100644 --- a/main.py +++ b/main.py @@ -76,10 +76,10 @@ 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["vlan_id"] in vlans: + 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["vlan_id"]].setdefault("ipv4", {}) - vlans[subnet["vlan_id"]]["ipv4"][ip] = subnet + vlans[subnet[0]["vlan_id"]].setdefault("ipv4", {}) + vlans[subnet[0]["vlan_id"]]["ipv4"][ip] = subnet for ipv6, subnet in self.switch["interfaces6_subnet"].items(): vlans[subnet["vlan_id"]].setdefault("ipv6", {}) vlans[subnet["vlan_id"]]["ipv6"][ipv6] = subnet @@ -237,34 +237,38 @@ class Switch: post_reboot = requests.post(url_reboot, data=json.dumps(data), headers=self.headers) -if "--force" in sys.argv: - 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"]) - -if "--upgrade" in sys.argv: - sw = Switch() - for switch in all_switchs: - sw.switch = switch - sw.upgrade() -for service in api_client.list("services/regen/"): - if service['hostname'] == client_hostname and \ - service['service_name'] == 'switchs' and \ - service['need_regen']: - error = False - sw=Switch() +if __name__=='__main__': + + if "--force" in sys.argv: + sw = Switch() for switch in all_switchs: sw.switch = switch sw.gen_conf_and_write() try: sw.apply_conf() except: - error = True - api_client.patch(service['api_url'], data={'need_regen': error}) + print("Erreur dans l'application de la conf pour " + switch["short_name"]) + + if "--upgrade" in sys.argv: + sw = Switch() + for switch in all_switchs: + sw.switch = switch + sw.upgrade() + + + for service in api_client.list("services/regen/"): + if service['hostname'] == client_hostname and \ + service['service_name'] == 'switchs' and \ + service['need_regen']: + error = False + sw=Switch() + for switch in all_switchs: + sw.switch = switch + sw.gen_conf_and_write() + try: + sw.apply_conf() + except: + error = True + api_client.patch(service['api_url'], data={'need_regen': error}) diff --git a/templates/hp.tpl b/templates/hp.tpl index 394874b..edf146f 100644 --- a/templates/hp.tpl +++ b/templates/hp.tpl @@ -57,7 +57,7 @@ vlan {{ id }} {%- endif %} {%- if vlan.ipv4 %} {%- for ipv4, subnet in vlan.ipv4.items() %} - ip address {{ ipv4 }}/{{ subnet.netmask_cidr }} + ip address {{ ipv4 }}/{{ subnet.0.netmask_cidr }} {%- endfor %} {%- else %} no ip address @@ -95,7 +95,7 @@ aaa authentication ssh enable public-key none ip ssh ip ssh filetransfer {%- if settings.switchs_management_utils.subnet %} -ip authorized-managers {{ settings.switchs_management_utils.subnet.network }} {{ settings.switchs_management_utils.subnet.netmask }} access manager +ip authorized-managers {{ settings.switchs_management_utils.subnet.0.network }} {{ settings.switchs_management_utils.subnet.0.netmask }} access manager {%- endif %} {%- for ipv4 in settings.switchs_management_utils.dns_recursive_servers.ipv4 %} ip dns server-address priority {{ loop.index }} {{ ipv4 }} @@ -111,7 +111,7 @@ loop-protect {{ additionals.loop_protected|join(',') }} {%- endif %} ;--- Serveurs Radius radius-server dead-time 2 -{%- for ipv4 in switch.get_radius_servers.ipv4 %} +{%- for ipv4 in settings.switchs_management_utils.radius_servers.ipv4 %} radius-server host {{ ipv4 }} key "{{ switch.get_radius_key_value }}" radius-server host {{ ipv4 }} dyn-authorization {%- endfor %}