0 $ˆl–ß=¿J µ2ÛR‚œP-\l1hßÀ „qÑï¿ÄÃ?÷# Copyright (C) 2012 Canonical Ltd. # Copyright (C) 2012, 2013 Hewlett-Packard Development Company, L.P. # Copyright (C) 2012 Yahoo! Inc. # # Author: Scott Moser # Author: Juerg Haefliger # Author: Joshua Harlow # Author: Ben Howard # # This file is part of cloud-init. See LICENSE file for license information. import abc import logging import os import re import stat import string import urllib.parse from collections import defaultdict from contextlib import suppress from io import StringIO from typing import ( Any, Dict, List, Mapping, MutableMapping, Optional, Set, Tuple, Type, Union, ) import cloudinit.net.netops.iproute2 as iproute2 from cloudinit import ( helpers, importer, lifecycle, net, persistence, ssh_util, subp, temp_utils, type_utils, util, ) from cloudinit.distros.networking import LinuxNetworking, Networking from cloudinit.distros.package_management.package_manager import PackageManager from cloudinit.distros.package_management.utils import known_package_managers from cloudinit.distros.parsers import hosts from cloudinit.features import ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES from cloudinit.lifecycle import log_with_downgradable_level from cloudinit.net import activators, dhcp, renderers from cloudinit.net.netops import NetOps from cloudinit.net.network_state import parse_net_config_data from cloudinit.net.renderer import Renderer # Used when a cloud-config module can be run on all cloud-init distributions. # The value 'all' is surfaced in module documentation for distro support. ALL_DISTROS = "all" OSFAMILIES = { "alpine": ["alpine"], "aosc": ["aosc"], "arch": ["arch"], "debian": ["debian", "ubuntu"], "freebsd": ["freebsd", "dragonfly"], "gentoo": ["gentoo", "cos"], "netbsd": ["netbsd"], "openbsd": ["openbsd"], "redhat": [ "almalinux", "amazon", "azurelinux", "centos", "cloudlinux", "eurolinux", "fedora", "mariner", "miraclelinux", "openmandriva", "photon", "rhel", "rocky", "virtuozzo", ], "suse": [ "opensuse", "opensuse-leap", "opensuse-microos", "opensuse-tumbleweed", "sle_hpc", "sle-micro", "sles", "suse", ], "openeuler": ["openeuler"], "OpenCloudOS": ["OpenCloudOS", "TencentOS"], } LOG = logging.getLogger(__name__) # This is a best guess regex, based on current EC2 AZs on 2017-12-11. # It could break when Amazon adds new regions and new AZs. _EC2_AZ_RE = re.compile("^[a-z][a-z]-(?:[a-z]+-)+[0-9][a-z]$") # Default NTP Client Configurations PREFERRED_NTP_CLIENTS = ["chrony", "systemd-timesyncd", "ntp", "ntpdate"] # Letters/Digits/Hyphen characters, for use in domain name validation LDH_ASCII_CHARS = string.ascii_letters + string.digits + "-" # Before you try to go rewriting this better using Unions, read # https://github.com/microsoft/pyright/blob/main/docs/type-concepts.md#generic-types # noqa: E501 # The Immutable types mentioned there won't work for us because # we need to distinguish between a str and a Sequence[str] # This also isn't exhaustive. If you have a unique case that adheres to # the `packages` schema, you can add it here. PackageList = Union[ List[str], List[Mapping], List[List[str]], List[Union[str, List[str]]], List[Union[str, List[str], Mapping]], ] class PackageInstallerError(Exception): pass class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta): pip_package_name = "python3-pip" usr_lib_exec = "/usr/lib" hosts_fn = "/etc/hosts" doas_fn = "/etc/doas.conf" ci_sudoers_fn = "/etc/sudoers.d/90-cloud-init-users" hostname_conf_fn = "/etc/hostname" shadow_fn = "/etc/shadow" shadow_extrausers_fn = "/var/lib/extrausers/shadow" # /etc/shado