From 57944ade6f1a4164d187ce35f121b7febf8cbf19 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Tue, 11 Jun 2013 11:34:40 +0200 Subject: [PATCH] =?UTF-8?q?[services]=20Si=20un=20dhcp=20n'est=20pas=20joi?= =?UTF-8?q?gnable,=20=C3=A7a=20n'est=20pas=20gr=C3=A2ve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/services.py b/services.py index 5f67873..0e9aad5 100644 --- a/services.py +++ b/services.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import ldap +import socket import lc_ldap import attributs import objets @@ -216,16 +217,19 @@ def services_to_restart(conn, old_attrs={}, new_attrs={}): # Cas du dhcp if attr.__class__ in services_to_attrs['dhcp']: for server in config.dhcp_servers: - dhcp=dydhcp(server) - if old_attrs.get('ipHostNumber', []) and old_attrs.get('macAddress', []): - if new_attrs.get('ipHostNumber', []) and new_attrs.get('macAddress', []): - if str(old_attrs['ipHostNumber'][0]) != str(new_attrs['ipHostNumber'][0]) or str(old_attrs['macAddress'][0]) != str(new_attrs['macAddress'][0]): + try: + dhcp=dydhcp(server) + if old_attrs.get('ipHostNumber', []) and old_attrs.get('macAddress', []): + if new_attrs.get('ipHostNumber', []) and new_attrs.get('macAddress', []): + if str(old_attrs['ipHostNumber'][0]) != str(new_attrs['ipHostNumber'][0]) or str(old_attrs['macAddress'][0]) != str(new_attrs['macAddress'][0]): + dhcp.del_host(str(old_attrs['ipHostNumber'][0]), str(old_attrs['macAddress'][0])) + dhcp.add_host(str(new_attrs['ipHostNumber'][0]), str(new_attrs['macAddress'][0]), str(new_attrs['host'][0])) + else: dhcp.del_host(str(old_attrs['ipHostNumber'][0]), str(old_attrs['macAddress'][0])) - dhcp.add_host(str(new_attrs['ipHostNumber'][0]), str(new_attrs['macAddress'][0]), str(new_attrs['host'][0])) - else: - dhcp.del_host(str(old_attrs['ipHostNumber'][0]), str(old_attrs['macAddress'][0])) - elif new_attrs.get('ipHostNumber', []) and new_attrs.get('macAddress', []): - dhcp.add_host(str(new_attrs['ipHostNumber'][0]), str(new_attrs['macAddress'][0]), str(new_attrs['host'][0])) + elif new_attrs.get('ipHostNumber', []) and new_attrs.get('macAddress', []): + dhcp.add_host(str(new_attrs['ipHostNumber'][0]), str(new_attrs['macAddress'][0]), str(new_attrs['host'][0])) + except socket.error: + pass if service in services_to_time.keys(): start = services_to_time[service](attr)