Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 18.116.239.11
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/cloudinit/config/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/lib/python3/dist-packages/cloudinit/config/cc_fan.py
# 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
---
**Summary:** configure ubuntu fan networking

This module installs, configures and starts the ubuntu fan network system. For
more information about Ubuntu Fan, see:
``https://wiki.ubuntu.com/FanNetworking``.

If cloud-init sees a ``fan`` entry in cloud-config it will:

    - write ``config_path`` with the contents of the ``config`` key
    - install the package ``ubuntu-fan`` if it is not installed
    - ensure the service is started (or restarted if was previously running)

**Internal name:** ``cc_fan``

**Module frequency:** per instance

**Supported distros:** ubuntu

**Config keys**::

    fan:
        config: |
            # fan 240
            10.0.0.0/8 eth0/16 dhcp
            10.0.0.0/8 eth1/16 dhcp off
            # fan 241
            241.0.0.0/8 eth0/16 dhcp
        config_path: /etc/network/fan
"""

from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
from cloudinit import subp
from cloudinit import util

LOG = logging.getLogger(__name__)

frequency = PER_INSTANCE

BUILTIN_CFG = {
    'config': None,
    'config_path': '/etc/network/fan',
}


def stop_update_start(service, config_file, content, systemd=False):
    if systemd:
        cmds = {'stop': ['systemctl', 'stop', service],
                'start': ['systemctl', 'start', service],
                'enable': ['systemctl', 'enable', service]}
    else:
        cmds = {'stop': ['service', 'stop'],
                'start': ['service', 'start']}

    def run(cmd, msg):
        try:
            return subp.subp(cmd, capture=True)
        except subp.ProcessExecutionError as e:
            LOG.warning("failed: %s (%s): %s", service, cmd, e)
            return False

    stop_failed = not run(cmds['stop'], msg='stop %s' % service)
    if not content.endswith('\n'):
        content += '\n'
    util.write_file(config_file, content, omode="w")

    ret = run(cmds['start'], msg='start %s' % service)
    if ret and stop_failed:
        LOG.warning("success: %s started", service)

    if 'enable' in cmds:
        ret = run(cmds['enable'], msg='enable %s' % service)

    return ret


def handle(name, cfg, cloud, log, args):
    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(
        service='ubuntu-fan', config_file=mycfg.get('config_path'),
        content=mycfg.get('config'), systemd=distro.uses_systemd())

# vi: ts=4 expandtab

Anon7 - 2022
AnonSec Team