| Server IP : 127.0.1.1 / Your IP : 216.73.216.152 Web Server : Apache/2.4.52 (Ubuntu) System : Linux bahcrestlinepropertiesllc 5.15.0-113-generic #123-Ubuntu SMP Mon Jun 10 08:16:17 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /proc/2792863/root/lib/python3/dist-packages/cloudinit/config/ |
Upload File : |
# Copyright (C) 2015 Canonical Ltd.
#
# Author: Scott Moser <scott.moser@canonical.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
"""Fan: Configure ubuntu fan networking"""
import logging
from cloudinit import subp, util
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema
from cloudinit.settings import PER_INSTANCE
meta: MetaSchema = {
"id": "cc_fan",
"distros": ["ubuntu"],
"frequency": PER_INSTANCE,
"activate_by_schema_keys": ["fan"],
}
LOG = logging.getLogger(__name__)
BUILTIN_CFG = {
"config": None,
"config_path": "/etc/network/fan",
}
def stop_update_start(distro, service, config_file, content):
try:
distro.manage_service("stop", service)
stop_failed = False
except subp.ProcessExecutionError as e:
stop_failed = True
LOG.warning("failed to stop %s: %s", service, e)
if not content.endswith("\n"):
content += "\n"
util.write_file(config_file, content, omode="w")
try:
distro.manage_service("start", service)
if stop_failed:
LOG.warning("success: %s started", service)
except subp.ProcessExecutionError as e:
LOG.warning("failed to start %s: %s", service, e)
distro.manage_service("enable", service)
def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
cfgin = cfg.get("fan")
if not cfgin:
cfgin = {}
mycfg = util.mergemanydict([cfgin, BUILTIN_CFG])
if not mycfg.get("config"):
LOG.debug("%s: no 'fan' config entry. disabling", name)
return
util.write_file(mycfg.get("config_path"), mycfg.get("config"), omode="w")
distro = cloud.distro
if not subp.which("fanctl"):
distro.install_packages(["ubuntu-fan"])
stop_update_start(
distro,
service="ubuntu-fan",
config_file=mycfg.get("config_path"),
content=mycfg.get("config"),
)