diff options
author | hamalq <81582959+hamalq@users.noreply.github.com> | 2021-04-15 16:45:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-15 18:45:12 -0500 |
commit | 45db197cfc7e3488baae7dc1053c45da070248f6 (patch) | |
tree | 91b0148c026c619e6f7f9f50064e6d07c1f47fac /cloudinit/distros/__init__.py | |
parent | 0d90596b56db5d306125ead08c571fc8d44d528e (diff) | |
download | vyos-cloud-init-45db197cfc7e3488baae7dc1053c45da070248f6.tar.gz vyos-cloud-init-45db197cfc7e3488baae7dc1053c45da070248f6.zip |
add prefer_fqdn_over_hostname config option (#859)
the above option allows the user to control the behavior of a distro
hostname selection if both short hostname and FQDN are supplied.
If `prefer_fqdn_over_hostname` is true the FQDN will be selected as
hostname; if false the hostname will be selected
LP: #1921004
Diffstat (limited to 'cloudinit/distros/__init__.py')
-rwxr-xr-x | cloudinit/distros/__init__.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 220bd11f..8b8a647d 100755 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -79,6 +79,7 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta): shutdown_options_map = {'halt': '-H', 'poweroff': '-P', 'reboot': '-r'} _ci_pkl_version = 1 + prefer_fqdn = False def __init__(self, name, cfg, paths): self._paths = paths @@ -131,6 +132,9 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta): def get_option(self, opt_name, default=None): return self._cfg.get(opt_name, default) + def set_option(self, opt_name, value=None): + self._cfg[opt_name] = value + def set_hostname(self, hostname, fqdn=None): writeable_hostname = self._select_hostname(hostname, fqdn) self._write_hostname(writeable_hostname, self.hostname_conf_fn) @@ -259,6 +263,9 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta): def _select_hostname(self, hostname, fqdn): # Prefer the short hostname over the long # fully qualified domain name + if util.get_cfg_option_bool(self._cfg, "prefer_fqdn_over_hostname", + self.prefer_fqdn) and fqdn: + return fqdn if not hostname: return fqdn return hostname |