diff options
author | Brett Holman <brett.holman@canonical.com> | 2023-04-19 16:12:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 16:12:55 -0600 |
commit | 5942f4023e2581a43f31d547995095ca49954353 (patch) | |
tree | 510009a412671c4adb041c05fc803db1ea4e8c22 /cloudinit/distros/freebsd.py | |
parent | 9e4cb4f06b2e362889bcbda77ef6fad52afed52b (diff) | |
download | cloud-init-git-5942f4023e2581a43f31d547995095ca49954353.tar.gz |
[1/2] DHCP: Refactor dhcp client code (#2122)
Move isc-dhclient code to dhcp.py
In support of the upcoming deprecation of
isc-dhcp-client, this code refactors current
dhcp code into classes in dhcp.py. The
primary user-visible change should be the
addition of the following log:
dhcp.py[DEBUG]: DHCP client selected: dhclient
This code lays groundwork to enable
alternate implementations to live side by
side in the codebase to be selected with
distro-defined priority fallback. Note that
maybe_perform_dhcp_discovery() now selects
which dhcp client to call, and then runs the
corresponding client's dhcp_discovery()
method. Currently only class IscDhclient is
implemented, however a yet-to-be-implemented
class Dhcpcd exists to test fallback behavior
and this will be implemented in part two of
this series.
Part of this refactor includes shifting
dhclient service management from hardcoded
calls to the distro-defined manage_service()
method in the *BSDs. Future work is required
in this area to support multiple clients via
select_dhcp_client().
Diffstat (limited to 'cloudinit/distros/freebsd.py')
-rw-r--r-- | cloudinit/distros/freebsd.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 4268abe6..77a94c61 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -37,14 +37,17 @@ class Distro(cloudinit.distros.bsd.BSD): prefer_fqdn = True # See rc.conf(5) in FreeBSD home_dir = "/usr/home" - def manage_service(self, action: str, service: str): + @classmethod + def manage_service( + cls, action: str, service: str, *extra_args: str, rcs=None + ): """ Perform the requested action on a service. This handles FreeBSD's 'service' case. The FreeBSD 'service' is closer in features to 'systemctl' than SysV init's 'service', so we override it. May raise ProcessExecutionError """ - init_cmd = self.init_cmd + init_cmd = cls.init_cmd cmds = { "stop": [service, "stop"], "start": [service, "start"], @@ -55,8 +58,8 @@ class Distro(cloudinit.distros.bsd.BSD): "try-reload": [service, "restart"], "status": [service, "status"], } - cmd = list(init_cmd) + list(cmds[action]) - return subp.subp(cmd, capture=True) + cmd = init_cmd + cmds[action] + list(extra_args) + return subp.subp(cmd, capture=True, rcs=rcs) def _get_add_member_to_group_cmd(self, member_name, group_name): return ["pw", "usermod", "-n", member_name, "-G", group_name] @@ -191,6 +194,3 @@ class Distro(cloudinit.distros.bsd.BSD): ["update"], freq=PER_INSTANCE, ) - - -# vi: ts=4 expandtab |