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())