HEX
Server: nginx/1.22.0
System: Linux iZuf6jdxbygmf6cco977lcZ 5.10.84-10.4.al8.x86_64 #1 SMP Tue Apr 12 12:31:07 CST 2022 x86_64
User: root (0)
PHP: 7.4.29
Disabled: passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen
Upload Files
File: //lib/python3.6/site-packages/cloudinit/config/cc_ntp_conf.py

from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
from cloudinit import templater
from copy import deepcopy

LOG = logging.getLogger(__name__)

frequency = PER_INSTANCE


# example
# cfg['ntp_conf'] = {
#     'ntp_servers': []
#     }


def generate_ntp_conf(template_fn, params):
    target_fname = '/etc/ntp.conf'
    if not params.get('ntp-servers'):
        LOG.debug("in module named cc_ntp_conf,"
                   " no 'ntp-servers' key in params")
        return
    ntp_params = {'ntp_servers': params['ntp-servers'],
                    'restrict_ntp_servers': params['ntp-servers']
                }
    templater.render_to_file(template_fn, target_fname, ntp_params)


def handle(name, cfg, cloud, log, _args):
    if not cloud.datasource.get_ntp_conf():
        LOG.debug(("Skipping module named %s,"
                   " no 'ntp_conf' key in metadata"), name)
        return

    template_fn = cloud.get_template_filename('ntp.conf')
    if not template_fn:
        LOG.warn("No template found, not rendering /etc/ntp.conf")
        return

    return generate_ntp_conf(template_fn=template_fn, params=cloud.datasource.get_ntp_conf())