From d4bea4a44a0405aaf0d181d4bffff6c07d2fb5ba Mon Sep 17 00:00:00 2001 From: Gonéri Le Bouder Date: Tue, 4 Jan 2022 12:50:31 -0500 Subject: openbsd: properly restart the network on 7.0 (#1150) OpenBSD 7.0 comes with a new service called dhcpleased to manage the DHCP requests. --- cloudinit/net/openbsd.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'cloudinit/net/openbsd.py') diff --git a/cloudinit/net/openbsd.py b/cloudinit/net/openbsd.py index da50d2ba..70e9f461 100644 --- a/cloudinit/net/openbsd.py +++ b/cloudinit/net/openbsd.py @@ -1,5 +1,7 @@ # This file is part of cloud-init. See LICENSE file for license information. +import platform + import cloudinit.net.bsd from cloudinit import log as logging from cloudinit import subp, util @@ -30,13 +32,21 @@ class Renderer(cloudinit.net.bsd.BSDRenderer): util.write_file(fn, content) def start_services(self, run=False): + has_dhcpleasectl = bool(int(platform.release().split(".")[0]) > 6) if not self._postcmds: LOG.debug("openbsd generate postcmd disabled") return - subp.subp(["pkill", "dhclient"], capture=True, rcs=[0, 1]) - subp.subp(["route", "del", "default"], capture=True, rcs=[0, 1]) - subp.subp(["route", "flush", "default"], capture=True, rcs=[0, 1]) - subp.subp(["sh", "/etc/netstart"], capture=True) + if has_dhcpleasectl: # OpenBSD 7.0+ + subp.subp(["sh", "/etc/netstart"], capture=True) + for interface in self.dhcp_interfaces(): + subp.subp( + ["dhcpleasectl", "-w", "30", interface], capture=True + ) + else: + subp.subp(["pkill", "dhclient"], capture=True, rcs=[0, 1]) + subp.subp(["route", "del", "default"], capture=True, rcs=[0, 1]) + subp.subp(["route", "flush", "default"], capture=True, rcs=[0, 1]) + subp.subp(["sh", "/etc/netstart"], capture=True) def set_route(self, network, netmask, gateway): if network == "0.0.0.0": -- cgit v1.2.3