Fix port profile + add datetime to template

This commit is contained in:
chirac 2018-10-13 22:46:46 +02:00 committed by root
parent 7e1e3ae347
commit 4d0219b691

17
main.py
View file

@ -9,7 +9,7 @@ from jinja2 import Environment, FileSystemLoader
import requests
import base64
import json
import datetime
import sys
config = ConfigParser()
@ -34,7 +34,6 @@ ENV = Environment(loader=FileSystemLoader('.'))
class Switch:
def __init__(self):
self.additionnal = None
@ -69,10 +68,10 @@ class Switch:
vlans = dict()
for port in self.switch['ports']:
if port['get_port_profil']['vlan_untagged']:
add_to_vlans(vlans, port['get_port_profil']['vlan_untagged'], port, tagged=False)
if port['get_port_profil']['vlan_tagged']:
for vlan in port['get_port_profil']['vlan_tagged']:
if port['get_port_profile']['vlan_untagged']:
add_to_vlans(vlans, port['get_port_profile']['vlan_untagged'], port, tagged=False)
if port['get_port_profile']['vlan_tagged']:
for vlan in port['get_port_profile']['vlan_tagged']:
add_to_vlans(vlans, vlan, port)
#Trie les ip par vlan, et les ajoute ainsi que les subnet
@ -91,8 +90,8 @@ class Switch:
dhcpv6_snooping_vlans = [vlan["vlan_id"] for vlan in self.all_vlans if vlan["dhcpv6_snooping"]]
igmp_vlans = [vlan["vlan_id"] for vlan in self.all_vlans if vlan["igmp"]]
mld_vlans = [vlan["vlan_id"] for vlan in self.all_vlans if vlan["mld"]]
ra_guarded = [str(port['port']) for port in self.switch['ports'] if port['get_port_profil']['ra_guard']]
loop_protected = [str(port['port']) for port in self.switch['ports'] if port['get_port_profil']['loop_protect']]
ra_guarded = [str(port['port']) for port in self.switch['ports'] if port['get_port_profile']['ra_guard']]
loop_protected = [str(port['port']) for port in self.switch['ports'] if port['get_port_profile']['loop_protect']]
self.additionals = {'ra_guarded' : ra_guarded, 'loop_protected' : loop_protected, 'vlans' : vlans, 'arp_protect_vlans' : arp_protect_vlans, 'dhcp_snooping_vlans' : dhcp_snooping_vlans, 'dhcpv6_snooping_vlans' : dhcpv6_snooping_vlans, 'igmp_vlans' : igmp_vlans, 'mld_vlans': mld_vlans}
@ -100,7 +99,7 @@ class Switch:
def gen_conf_hp(self):
"""Génère la config pour ce switch hp"""
self.preprocess_hp()
self.conf = self.hp_tpl.render(switch=self.switch, settings=self.settings, additionals=self.additionals)
self.conf = self.hp_tpl.render(switch=self.switch, settings=self.settings, additionals=self.additionals, date_gen=datetime.datetime.now())
def check_and_get_login(self):
"""Récupère les login/mdp du switch, renvoie false si ils sont indisponibles"""