Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aosc): Add 'AOSC OS' support #5310

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cloudinit/config/cc_ca_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"ca_cert_update_cmd": ["update-ca-certificates"],
}
DISTRO_OVERRIDES = {
"aosc": {
"ca_cert_path": "/etc/ssl/certs/",
"ca_cert_local_path": "/etc/ssl/certs/",
"ca_cert_filename": "cloud-init-ca-cert-{cert_index}.pem",
"ca_cert_config": "/etc/ca-certificates/conf.d/cloud-init.conf",
"ca_cert_update_cmd": ["update-ca-bundle"],
},
"fedora": {
"ca_cert_path": "/etc/pki/ca-trust/",
"ca_cert_local_path": "/usr/share/pki/ca-trust-source/",
Expand Down Expand Up @@ -71,6 +78,7 @@

distros = [
"almalinux",
"aosc",
"cloudlinux",
"alpine",
"debian",
Expand Down Expand Up @@ -149,7 +157,7 @@ def disable_default_ca_certs(distro_name, distro_cfg):
"""
if distro_name in ["rhel", "photon"]:
remove_default_ca_certs(distro_cfg)
elif distro_name in ["alpine", "debian", "ubuntu"]:
elif distro_name in ["alpine", "aosc", "debian", "ubuntu"]:
disable_system_ca_certs(distro_cfg)

if distro_name in ["debian", "ubuntu"]:
Expand Down
7 changes: 7 additions & 0 deletions cloudinit/config/cc_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
distros = [
"almalinux",
"alpine",
"aosc",
"azurelinux",
"centos",
"cloudlinux",
Expand Down Expand Up @@ -109,6 +110,12 @@
"service_name": "ntpd",
},
},
"aosc": {
"systemd-timesyncd": {
"check_exe": "/usr/lib/systemd/systemd-timesyncd",
"confpath": "/etc/systemd/timesyncd.conf",
},
},
"azurelinux": {
"chrony": {
"service_name": "chronyd",
Expand Down
1 change: 1 addition & 0 deletions cloudinit/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

OSFAMILIES = {
"alpine": ["alpine"],
"aosc": ["aosc"],
"arch": ["arch"],
"debian": ["debian", "ubuntu"],
"freebsd": ["freebsd", "dragonfly"],
Expand Down
148 changes: 148 additions & 0 deletions cloudinit/distros/aosc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Copyright (C) 2024 AOSC Developers
#
# Author: Yuanhang Sun <leavelet@aosc.io>
#
# This file is part of cloud-init. See LICENSE file for license information.
import logging

from cloudinit import distros, helpers, subp, util
from cloudinit.distros import PackageList
from cloudinit.distros.parsers.hostname import HostnameConf
from cloudinit.distros.parsers.sys_conf import SysConf
from cloudinit.settings import PER_INSTANCE

LOG = logging.getLogger(__name__)


class Distro(distros.Distro):
systemd_locale_conf_fn = "/etc/locale.conf"
init_cmd = ["systemctl"]
network_conf_dir = "/etc/sysconfig/network"
resolve_conf_fn = "/etc/systemd/resolved.conf"
tz_local_fn = "/etc/localtime"

dhclient_lease_directory = "/var/lib/NetworkManager"
dhclient_lease_file_regex = r"dhclient-[\w-]+\.lease"

renderer_configs = {
"sysconfig": {
"control": "etc/sysconfig/network",
"iface_templates": "%(base)s/network-scripts/ifcfg-%(name)s",
"route_templates": {
"ipv4": "%(base)s/network-scripts/route-%(name)s",
"ipv6": "%(base)s/network-scripts/route6-%(name)s",
},
}
}

prefer_fqdn = False

def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
self._runner = helpers.Runners(paths)
self.osfamily = "aosc"
self.default_locale = "en_US.UTF-8"
cfg["ssh_svcname"] = "sshd"

def apply_locale(self, locale, out_fn=None):
if not out_fn:
out_fn = self.systemd_locale_conf_fn
locale_cfg = {
"LANG": locale,
}
update_locale_conf(out_fn, locale_cfg)

def _write_hostname(self, hostname, filename):
if filename.endswith("/previous-hostname"):
conf = HostnameConf("")
conf.set_hostname(hostname)
util.write_file(filename, str(conf), 0o644)
create_hostname_file = util.get_cfg_option_bool(
self._cfg, "create_hostname_file", True
)
if create_hostname_file:
subp.subp(["hostnamectl", "set-hostname", str(hostname)])
else:
subp.subp(
[
"hostnamectl",
"set-hostname",
"--transient",
str(hostname),
]
)
LOG.info("create_hostname_file is False; hostname set transiently")

def _read_hostname(self, filename, default=None):
if filename.endswith("/previous-hostname"):
return util.load_text_file(filename).strip()
(out, _err) = subp.subp(["hostname"])
out = out.strip()
if len(out):
return out
else:
return default

def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
return (self.hostname_conf_fn, sys_hostname)

def set_timezone(self, tz):
tz_file = self._find_tz_file(tz)
util.del_file(self.tz_local_fn)
util.sym_link(tz_file, self.tz_local_fn)

def package_command(self, command, args=None, pkgs=None):
if pkgs is None:
pkgs = []

cmd = ["oma"]
if command:
cmd.append(command)
cmd.append("-y")
cmd.extend(pkgs)

subp.subp(cmd, capture=False)

def install_packages(self, pkglist: PackageList):
self.package_command("install", pkgs=pkglist)

def update_package_sources(self):
self._runner.run(
"update-sources",
self.package_command,
"refresh",
freq=PER_INSTANCE,
)


def read_locale_conf(sys_path):
exists = False
try:
contents = util.load_text_file(sys_path).splitlines()
exists = True
except IOError:
contents = []
return (exists, SysConf(contents))


def update_locale_conf(sys_path, locale_cfg):
if not locale_cfg:
return
(exists, contents) = read_locale_conf(sys_path)
updated_am = 0
for (k, v) in locale_cfg.items():
if v is None:
continue
v = str(v)
if len(v) == 0:
continue
contents[k] = v
updated_am += 1
if updated_am:
lines = [
str(contents),
]
if not exists:
lines.insert(0, util.make_header())
util.write_file(sys_path, "\n".join(lines) + "\n", 0o644)
1 change: 1 addition & 0 deletions cloudinit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def _get_variant(info):
if linux_dist in (
"almalinux",
"alpine",
"aosc",
"arch",
"azurelinux",
"centos",
Expand Down
10 changes: 5 additions & 5 deletions config/cloud.cfg.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"netbsd": "NetBSD", "openbsd": "openBSD",
"openmandriva": "OpenMandriva admin", "photon": "PhotonOS",
"ubuntu": "Ubuntu", "unknown": "Ubuntu"}) %}
{% set groups = ({"alpine": "adm, wheel", "arch": "wheel, users",
{% set groups = ({"alpine": "adm, wheel", "aosc": "wheel", "arch": "wheel, users",
"azurelinux": "wheel",
"debian": "adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo, video",
"gentoo": "users, wheel", "mariner": "wheel",
Expand Down Expand Up @@ -220,7 +220,7 @@ cloud_final_modules:
# (not accessible to handlers/transforms)
system_info:
# This will affect which distro class gets used
{% if variant in ["alpine", "amazon", "arch", "azurelinux", "debian", "fedora",
{% if variant in ["alpine", "amazon", "aosc", "arch", "azurelinux", "debian", "fedora",
"freebsd", "gentoo", "mariner", "netbsd", "openbsd",
"OpenCloudOS", "openeuler", "openmandriva", "photon", "suse",
"TencentOS", "ubuntu"] or is_rhel %}
Expand All @@ -238,7 +238,7 @@ system_info:
{% else %}
name: {{ variant }}
{% endif %}
{% if variant in ["alpine", "amazon", "arch", "azurelinux", "debian", "fedora",
{% if variant in ["alpine", "amazon", "aosc", "arch", "azurelinux", "debian", "fedora",
"gentoo", "mariner", "OpenCloudOS", "openeuler",
"openmandriva", "photon", "suse", "TencentOS", "ubuntu",
"unknown"]
Expand Down Expand Up @@ -320,7 +320,7 @@ system_info:
# Automatically discover the best ntp_client
ntp_client: auto
{% endif %}
{% if variant in ["alpine", "amazon", "arch", "azurelinux", "debian", "fedora",
{% if variant in ["alpine", "amazon", "aosc", "arch", "azurelinux", "debian", "fedora",
"gentoo", "mariner", "OpenCloudOS", "openeuler",
"openmandriva", "photon", "suse", "TencentOS", "ubuntu",
"unknown"]
Expand Down Expand Up @@ -368,7 +368,7 @@ system_info:
{% endif %}
{% if variant in ["debian", "ubuntu", "unknown"] %}
ssh_svcname: ssh
{% elif variant in ["alpine", "amazon", "arch", "azurelinux", "fedora",
{% elif variant in ["alpine", "amazon", "aosc", "arch", "azurelinux", "fedora",
"gentoo", "mariner", "OpenCloudOS", "openeuler",
"openmandriva", "photon", "suse", "TencentOS"]
or is_rhel %}
Expand Down
1 change: 1 addition & 0 deletions doc/rtd/reference/distros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unix family of operating systems. See the complete list below.

* AlmaLinux
* Alpine Linux
* AOSC OS
* Arch Linux
* CentOS
* CloudLinux
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/distros/test_aosc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is part of cloud-init. See LICENSE file for license information.

from tests.unittests.distros import _get_distro
from tests.unittests.helpers import CiTestCase


class TestAOSC(CiTestCase):
def test_get_distro(self):
distro = _get_distro("aosc")
self.assertEqual(distro.osfamily, "aosc")
3 changes: 2 additions & 1 deletion tests/unittests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def test_wb_schema_subcommand_parser(self, m_read_cfg, capsys):
["all"],
[
"**Supported distros:** all",
"**Supported distros:** almalinux, alpine, azurelinux, "
"**Supported distros:** "
"almalinux, alpine, aosc, azurelinux, "
"centos, cloudlinux, cos, debian, eurolinux, fedora, "
"freebsd, mariner, miraclelinux, openbsd, openeuler, "
"OpenCloudOS, openmandriva, opensuse, opensuse-microos, "
Expand Down
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ klausenbusk
KsenijaS
landon912
ld9379435
leavelet
licebmi
linitio
LKHN
Expand Down
1 change: 1 addition & 0 deletions tools/render-template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def main():
"almalinux",
"alpine",
"amazon",
"aosc",
"arch",
"azurelinux",
"benchmark",
Expand Down
Loading