[dhcp] On ajoute isc à dydhcp, et on passe quelques modifs de Valentin

This commit is contained in:
Pierre-Elliott Bécue 2013-05-19 18:45:49 +02:00
parent 662061781b
commit 9a5294c7ee
4 changed files with 23 additions and 34 deletions

View file

@ -17,12 +17,14 @@ from pypureomapi import Omapi, OmapiMessage, OmapiError, OmapiErrorNotFound
import struct
class dydhcp:
def __init__(self):
def __init__(self, server):
import sys
sys.path.append('/usr/scripts/gestion/secrets')
from secrets import dhcp_omapi_keyname,dhcp_omapi_key
self.dhcp_omapi_keyname=dhcp_omapi_keyname
self.dhcp_omapi_key=dhcp_omapi_key
from secrets import dhcp_omapi_keyname,dhcp_omapi_keys
self.dhcp_omapi_keyname = dhcp_omapi_keyname
self.dhcp_omapi_key = dhcp_omapi_keys[server]
self.server = server.lower()
def add_host(self, ip, mac,name=None):
"""
@type ip: str
@ -40,7 +42,7 @@ class dydhcp:
msg.obj.append((b"ip-address", pack_ip(ip)))
if name:
msg.obj.append((b"name", bytes(name)))
conn=Omapi('dhcp.adm.crans.org',9991,self.dhcp_omapi_keyname, self.dhcp_omapi_key)
conn=Omapi(self.server, 9991,self.dhcp_omapi_keyname, self.dhcp_omapi_key)
response = conn.query_server(msg)
conn.close()
@ -56,7 +58,7 @@ class dydhcp:
msg.obj.append((b"hardware-address", pack_mac(mac)))
msg.obj.append((b"hardware-type", struct.pack("!I", 1)))
msg.obj.append((b"ip-address", pack_ip(ip)))
conn=Omapi('dhcp.adm.crans.org',9991,self.dhcp_omapi_keyname, self.dhcp_omapi_key)
conn=Omapi(self.server,9991,self.dhcp_omapi_keyname, self.dhcp_omapi_key)
response = conn.query_server(msg)
if response.opcode == OMAPI_OP_UPDATE:
response = conn.query_server(OmapiMessage.delete(response.handle))
@ -72,23 +74,7 @@ class dhcp(gen_config) :
"""
######################################PARTIE DE CONFIGURATION
# Fichier à écire
if hostname == 'sable':
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' }
elif hostname == 'titanic':
restart_cmd = '/etc/init.d/isc-dhcp-server restart'
reseaux = { '10.2.9.0/24' : '/etc/dhcp3/generated/appartements.liste' }
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' }
elif hostname == 'isc':
if hostname in ['dhcp', 'isc']:
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',
@ -163,7 +149,7 @@ class dhcp(gen_config) :
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() , 'host' : machine.nom().split('.')[0],'mac' : machine.mac() , 'ip' : machine.ip() }
d = { 'nom' : machine.nom() , 'host' : machine.nom().split('.', 1)[0],'mac' : machine.mac() , 'ip' : machine.ip() }
try :
hosts[net] += host_template % d
except : hosts[net] = host_template % d