Petr Horáček has uploaded a new change for review. Change subject: net: lookup dhclient file ......................................................................
net: lookup dhclient file Change-Id: I94d2c35bfa8acfc808d3852d41b45b7df38c2c41 Bug-Url: https://bugzilla.redhat.com/1195208 Signed-off-by: Petr Horáček <phora...@redhat.com> --- M lib/vdsm/network/ip/dhclient.py 1 file changed, 38 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/18/61918/1 diff --git a/lib/vdsm/network/ip/dhclient.py b/lib/vdsm/network/ip/dhclient.py index 318217c..95b3226 100644 --- a/lib/vdsm/network/ip/dhclient.py +++ b/lib/vdsm/network/ip/dhclient.py @@ -23,6 +23,7 @@ import errno import logging import os +import re import subprocess import threading @@ -36,6 +37,8 @@ DHCLIENT_CGROUP = 'vdsm-dhclient' LEASE_DIR = '/var/lib/dhclient' LEASE_FILE = os.path.join(LEASE_DIR, 'dhclient{0}--{1}.lease') +NM_LEASE_DIR = '/var/lib/NetworkManager' +NM_LEASE_FILE_REGEX = '^dhclient{0}-.*-{1}.lease$' class DhcpClient(object): @@ -46,8 +49,7 @@ self.iface = iface self.family = family self.default_route = default_route - self.duid_source_file = None if duid_source is None else ( - LEASE_FILE.format('' if family == 4 else '6', duid_source)) + self.duid_source = duid_source self.pidFile = self.PID_FILE % (family, self.iface) if not os.path.exists(LEASE_DIR): os.mkdir(LEASE_DIR) @@ -64,8 +66,10 @@ if not self.default_route: # Instruct Fedora/EL's dhclient-script not to set gateway on iface cmd += ['-e', 'DEFROUTE=no'] - if self.duid_source_file and supports_duid_file(): - cmd += ['-df', self.duid_source_file] + if self.duid_source and supports_duid_file(): + duid_source_file = _lease_file_lookup(self.iface, self.family) + if duid_source_file: + cmd += ['-df', duid_source_file] cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup) return execCmd(cmd) @@ -102,6 +106,36 @@ return False +@memoized +def _network_manager(): + return os.path.exists(NM_LEASE_DIR) + + +def _lease_file_lookup(device_name, family): + if _network_manager(): + nm_lease = _newest_nm_lease(device_name, family) + if nm_lease: + return nm_lease + + lease = LEASE_FILE.format('' if family == 4 else '6', device_name) + if os.path.exists(lease): + return lease + + +def _newest_nm_lease(device_name, family): + regex = re.compile( + NM_LEASE_FILE_REGEX.format('' if family == 4 else '6', device_name)) + leases = [os.path.join(NM_LEASE_DIR, file) + for file in os.listdir(NM_LEASE_DIR) + if regex.match(file)] + if not leases: + return None + elif len(leases) == 1: + return leases[0] + else: + return sorted(leases, key=os.path.getmtime, reverse=True)[0] + + def _pid_lookup(device_name, family): for pid in pgrep('dhclient'): try: -- To view, visit https://gerrit.ovirt.org/61918 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I94d2c35bfa8acfc808d3852d41b45b7df38c2c41 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Petr Horáček <phora...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org