Commit a066e7e8 authored by Hamza Dely's avatar Hamza Dely

Mise à jour de switchs2.py pour le VLAN 4

parent 623b925b
......@@ -50,8 +50,8 @@ V_UNTAGGED = 2
V_NO = 3
# Vlans disponibles
ENABLED_VLANS = ['adherent', 'adm', 'switches', 'wifi', 'v6only', 'accueil', 'isolement',
'appts', 'event', 'federez']
ENABLED_VLANS = ['adherent', 'adm', 'wifi', 'switches', 'v6only', 'accueil',
'isolement', 'appts', 'event', 'federez']
def vlan_id(vlans):
"""Vlan id of a name (filtre jinja)"""
......@@ -174,6 +174,9 @@ class Port(object):
# Précisons tout de suite qu'adm ne va pas plus loin
elif vlan == 'adm':
return V_NO
# Idem pour le VLAN des switches
elif vlan == 'switches':
return V_NO
elif self.bornes:
if vlan in ['wifi', 'accueil', 'isolement', 'v6only', 'appts',
'event', 'federez']:
......@@ -310,7 +313,8 @@ def fill_port_infos(hostname, port_dict):
def check_conf_ldap(hostname):
"""Vérifie la conf du switch, la base ldap et les macs/prises associées"""
bat, sw_num = get_bat_num(hostname)
switch = ldap.search(u'host=bat%s-%d.adm.crans.org' % (bat, sw_num))[0]
switch = ldap.search(u'(&(host=%s.switches.crans.org)'
'(objectClass=switchCrans))' % hostname)[0]
port_dict = get_port_dict(switch)
fill_port_infos(hostname, port_dict)
......@@ -440,12 +444,8 @@ def format_prises_group(data, first, last):
def pretty_print(hostname):
"""Affiche joliement le plan de connexion d'un switch"""
bat, sw_num = get_bat_num(hostname)
try:
switch = ldap.search(u'host=bat%s-%d.adm.crans.org' % (bat, sw_num))[0]
except IndexError:
switch = ldap.search(u'host=bat%s-%d.crans.org' % (bat, sw_num))[0]
switch = ldap.search(u'(&(host=%s.switches.crans.org)'
'(objectClass=switchCrans))' % hostname)[0]
port_dict = get_port_dict(switch)
total = max(port_dict.keys())
......@@ -465,11 +465,8 @@ def conf_switch(hostname):
"""Affiche la configuration d'un switch"""
bat, sw_num = get_bat_num(hostname)
try:
switch = ldap.search(u'host=bat%s-%d.adm.crans.org' % (bat, sw_num))[0]
except IndexError:
switch = ldap.search(u'host=bat%s-%d.crans.org' % (bat, sw_num))[0]
switch = ldap.search(u'(&(host=%s.switches.crans.org)'
'(objectClass=switchCrans))' % hostname)[0]
tpl_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
##for info:
......@@ -483,8 +480,8 @@ def conf_switch(hostname):
'date_gen': datetime.datetime.now(),
# TODO fill that depuis bcfg2 ou whatever
'radius_servers': [
'10.231.136.72',
'10.231.136.11',
'10.231.100.72',
'10.231.100.11',
],
'radius_key': secrets.get('radius_key'),
......@@ -533,6 +530,13 @@ def conf_switch(hostname):
data['gateway'] = '10.231.136.4'
data['network_id'] = '10.231.136.0'
data['subnet'] = '255.255.255.0'
if u"switches" in unicode(switch['host']):
data['public'] = False
data['ntp_servers'] = ['10.231.100.38']
data['log_servers'] = ['10.231.100.38']
data['gateway'] = '10.231.100.4'
data['network_id'] = '10.231.100.0'
data['subnet'] = '255.255.255.0'
else:
data['public'] = True
data['ntp_servers'] = ['138.231.136.98']
......@@ -570,9 +574,9 @@ def conf_switch(hostname):
vlan.setdefault(attr, PortList())
vlan[attr].extend(p)
if name == 'adm' and not data['public']:
vlan['ip_cfg'] = (gethostbyname(hostname), '255.255.255.0')
if name == 'switchs':
vlan['ip_cfg'] = (gethostbyname(hostname).replace('136','100'), '255.255.255.0')
vlan['ip_cfg'] = (gethostbyname(hostname + u".adm.crans.org"), '255.255.255.0')
if name == 'switches':
vlan['ip_cfg'] = (gethostbyname(hostname + u".switches.crans.org"), '255.255.255.0')
if name == 'adherent':
# TODO : proprifier cela
# Si le switch est publique, adh en non tagué partout
......@@ -603,7 +607,7 @@ if __name__ == "__main__":
parser.add_argument('hostname', help="Nom du switch à regénérer " +
"(ex: batg-4)")
parser.add_argument('-c', '--check', action='store_true', default=False,
help="Vérifie la conf par rapport aux macs et vlans effectivement" +\
help="Vérifie la conf par rapport aux macs et vlans effectivement " +\
"présents sur le switch")
parser.add_argument('--pretty', action='store_true', default=False,
help="Affiche un tableau ascii du plan de connexion du switch")
......@@ -616,4 +620,3 @@ if __name__ == "__main__":
pretty_print(options.hostname)
else:
print(conf_switch(options.hostname))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment