From ce443b9bfab07be84b53fb0c54d84ff2bd413e9f Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Thu, 25 Oct 2012 23:24:09 +0200 Subject: [PATCH] =?UTF-8?q?[dhcp=5Fnew,generate,switchs,ldap=5Fcrans]=20On?= =?UTF-8?q?=20ajoute=20dhcp=20=C3=A0=20g=C3=A9n=C3=A9rate=20et=20son=20ip?= =?UTF-8?q?=20dans=20dhcp-snooping,=20on=20active=20le=20dhcp-nopping=20su?= =?UTF-8?q?r=20tous=20les=20vlan.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore-this: c3a151a94e71f2bb4761a9ecc9707bcf darcs-hash:20121025212409-3a55a-cd8c2857721d655c5dd67124a380fbe7eb5161b3.gz --- gestion/gen_confs/dhcpd_new.py | 14 +++++++++++--- gestion/gen_confs/generate.py | 5 +++++ gestion/gen_confs/switchs.py | 24 ++++++++++++++++++++---- gestion/ldap_crans.py | 3 +++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/gestion/gen_confs/dhcpd_new.py b/gestion/gen_confs/dhcpd_new.py index 04e5227a..a0f42c4f 100755 --- a/gestion/gen_confs/dhcpd_new.py +++ b/gestion/gen_confs/dhcpd_new.py @@ -32,12 +32,19 @@ class dhcp(gen_config) : elif hostname == 'gordon': restart_cmd = '/etc/init.d/isc-dhcp-server restart' reseaux = { '138.231.144.0/21' : '/etc/dhcp3/generated/wifi.liste' } + elif hostname == 'dhcp': + restart_cmd = '/etc/init.d/isc-dhcp-server restart' + reseaux = { '138.231.136.0/21' : '/etc/dhcp3/generated/adherents.liste', + '10.42.0.0/16' : '/etc/dhcp3/generated/gratuit.liste', + '10.2.9.0/24' : '/etc/dhcp3/generated/appartements.liste', + '138.231.144.0/21' : '/etc/dhcp3/generated/wifi.liste' } + host_template = """ host %(nom)s { hardware ethernet %(mac)s; fixed-address %(ip)s; - option host-name "%(nom)s"; + option host-name "%(host)s"; } """ @@ -45,7 +52,7 @@ class dhcp(gen_config) : host %(nom)s { hardware ethernet %(mac)s; fixed-address %(ip)s; - option host-name "%(nom)s"; + option host-name "%(host)s"; next-server 138.231.136.98; filename "yaboot"; option root-path "/opt/ltsp/powerpc"; @@ -77,7 +84,8 @@ class dhcp(gen_config) : if AddrInNet(machine.ip(), net) : host_template = self.host_template # variable pour remplir le template - d = { 'nom' : machine.nom().split('.')[0] , 'mac' : machine.mac() , 'ip' : machine.ip() } + #d = { 'nom' : machine.nom().split('.')[0] , 'mac' : machine.mac() , 'ip' : machine.ip() } + d = { 'nom' : machine.nom() , 'host' : machine.nom().split('.')[0],'mac' : machine.mac() , 'ip' : machine.ip() } try : hosts[net] += host_template % d except : hosts[net] = host_template % d diff --git a/gestion/gen_confs/generate.py b/gestion/gen_confs/generate.py index 040f992f..179ce9f9 100644 --- a/gestion/gen_confs/generate.py +++ b/gestion/gen_confs/generate.py @@ -246,6 +246,11 @@ class dyson(base_reconfigure): from gen_confs.dhcpd_new import dhcp self._do(dhcp(), self._machines()) +class dhcp(base_reconfigure): + def dhcp(self): + from gen_confs.dhcpd_new import dhcp + self._do(dhcp(), self._machines()) + class sable(base_reconfigure): def dhcp(self): from gen_confs.dhcpd_new import dhcp diff --git a/gestion/gen_confs/switchs.py b/gestion/gen_confs/switchs.py index 15f11a08..8532c7fc 100644 --- a/gestion/gen_confs/switchs.py +++ b/gestion/gen_confs/switchs.py @@ -143,10 +143,16 @@ no stack """ dhcp_snooping_template = """;------------------------------------------------------- DHCP Snooping -dhcp-snooping vlan %(vlan_adherent)s +dhcp-snooping vlan %(vlan_adherent)s %(vlan_wifi)s %(vlan_accueil)s %(vlan_gratuit)s %(vlan_isolement)s %(vlan_appts)s dhcp-snooping trust %(uplinks)s no dhcp-snooping trust %(non_uplinks)s dhcp-snooping authorized-server %(dhcp)s +dhcp-snooping authorized-server %(dhcp-1)s +dhcp-snooping authorized-server %(dhcp-3)s +dhcp-snooping authorized-server %(dhcp-6)s +dhcp-snooping authorized-server %(dhcp-7)s +dhcp-snooping authorized-server %(dhcp-9)s +dhcp-snooping authorized-server %(dhcp-21)s ; Activation dhcp-snooping""" @@ -162,7 +168,15 @@ exit rad_template = "radius-server host %s\n" # Serveur DHCP du vlan par défaut - dhcp_server = "138.231.136.9" + dhcp_servers = { '0':'138.231.136.9', + '1':'138.231.136.34', + '3':'138.231.148.34', + '6':'10.42.0.34', + '7':'10.51.0.34', + '9':'10.52.0.34', + '21':'10.2.9.34' + } + def __init__(self,truc): """ truc est soit : @@ -279,7 +293,7 @@ exit # Batiment et numéro du switch bat = switch[3].lower() sw_num = int(switch[5]) - dhcp_server = self.dhcp_server + dhcp_servers = self.dhcp_servers # Conf radius sys.path.append('/usr/scripts/gestion/secrets') from secrets import radius_key @@ -294,7 +308,9 @@ exit params = { 'switch' : switch, 'bat' : bat.upper() , 'radius_key' : radius_key , 'radius-serveurs' : rad[:-1] % tuple(self.rad_servs), - 'dhcp': dhcp_server} + 'dhcp': dhcp_servers['0']} + for i in dhcp_servers.keys(): + params['dhcp-%s' % i]=dhcp_servers[i] self.aff.cycle() diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 01156952..29f3a3a1 100644 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -1817,6 +1817,7 @@ class BaseProprietaire(BaseClasseCrans): self.services_to_restart('macip', [m.ip()] ) self.services_to_restart('classify', [m.ip()] ) self.services_to_restart('dns') + self.services_to_restart('dhcp-dhcp') if isinstance(m, MachineWifi): self.services_to_restart('conf_wifi_ng') self.services_to_restart('gordon-dhcp') @@ -3061,6 +3062,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) if reconf_ip: self.services_to_restart('macip', reconf_ip) self.services_to_restart('classify', reconf_ip) + self.services_to_restart('dhcp-dhcp') if isinstance(self, MachineWifi) or isinstance(self, BorneWifi): self.services_to_restart('gordon-dhcp') else: @@ -3128,6 +3130,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) self._delete(self.dn, comment) # Services à redémarrer + self.services_to_restart('dhcp-dhcp') if isinstance(self, MachineWifi): self.services_to_restart('conf_wifi_ng') self.services_to_restart('gordon-dhcp')