summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-09-15 13:37:55 -0600
committerChad Smith <chad.smith@canonical.com>2017-09-15 13:38:56 -0600
commitda1db792b2721d94ef85df8c136e78012c49c6e5 (patch)
tree0b2909066d31028fa1beb86e436f48a8669e56f2 /cloudinit
parent024ecc1f758d36cc0aa5ebce65704eed6bd66d45 (diff)
downloadvyos-cloud-init-da1db792b2721d94ef85df8c136e78012c49c6e5.tar.gz
vyos-cloud-init-da1db792b2721d94ef85df8c136e78012c49c6e5.zip
CloudStack: consider dhclient lease files named with a hyphen.
A regression in 'get_latest_lease' made it ignore files starting with 'dhclient-' rather than just 'dhclient.'. The fix here is to allow those files to be considered. There is a lot more we could do here to better ensure that we pick the most recent lease, but this change fixes the regression. LP: #1717147
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceCloudStack.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/cloudinit/sources/DataSourceCloudStack.py b/cloudinit/sources/DataSourceCloudStack.py
index 0188d894..7e0f9bb8 100644
--- a/cloudinit/sources/DataSourceCloudStack.py
+++ b/cloudinit/sources/DataSourceCloudStack.py
@@ -187,22 +187,36 @@ def get_dhclient_d():
return None
-def get_latest_lease():
+def get_latest_lease(lease_d=None):
# find latest lease file
- lease_d = get_dhclient_d()
+ if lease_d is None:
+ lease_d = get_dhclient_d()
if not lease_d:
return None
lease_files = os.listdir(lease_d)
latest_mtime = -1
latest_file = None
- for file_name in lease_files:
- if file_name.startswith("dhclient.") and \
- (file_name.endswith(".lease") or file_name.endswith(".leases")):
- abs_path = os.path.join(lease_d, file_name)
- mtime = os.path.getmtime(abs_path)
- if mtime > latest_mtime:
- latest_mtime = mtime
- latest_file = abs_path
+
+ # lease files are named inconsistently across distros.
+ # We assume that 'dhclient6' indicates ipv6 and ignore it.
+ # ubuntu:
+ # dhclient.<iface>.leases, dhclient.leases, dhclient6.leases
+ # centos6:
+ # dhclient-<iface>.leases, dhclient6.leases
+ # centos7: ('--' is not a typo)
+ # dhclient--<iface>.lease, dhclient6.leases
+ for fname in lease_files:
+ if fname.startswith("dhclient6"):
+ # avoid files that start with dhclient6 assuming dhcpv6.
+ continue
+ if not (fname.endswith(".lease") or fname.endswith(".leases")):
+ continue
+
+ abs_path = os.path.join(lease_d, fname)
+ mtime = os.path.getmtime(abs_path)
+ if mtime > latest_mtime:
+ latest_mtime = mtime
+ latest_file = abs_path
return latest_file