Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 3 additions & 132 deletions cloudinit/config/cc_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@

from cloudinit import log as logging
from cloudinit import subp, temp_utils, templater, type_utils, util
from cloudinit.config.schema import (
MetaSchema,
get_meta_doc,
validate_cloudconfig_schema,
)
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.settings import PER_INSTANCE

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -210,137 +206,14 @@
],
"frequency": PER_INSTANCE,
}
__doc__ = get_meta_doc(meta)


schema = {
"type": "object",
"properties": {
"ntp": {
"type": ["object", "null"],
"properties": {
"pools": {
"type": "array",
"items": {"type": "string", "format": "hostname"},
"uniqueItems": True,
"description": dedent(
"""\
List of ntp pools. If both pools and servers are
empty, 4 default pool servers will be provided of
the format ``{0-3}.{distro}.pool.ntp.org``. NOTE:
for Alpine Linux when using the Busybox NTP client
this setting will be ignored due to the limited
functionality of Busybox's ntpd."""
),
},
"servers": {
"type": "array",
"items": {"type": "string", "format": "hostname"},
"uniqueItems": True,
"description": dedent(
"""\
List of ntp servers. If both pools and servers are
empty, 4 default pool servers will be provided with
the format ``{0-3}.{distro}.pool.ntp.org``."""
),
},
"ntp_client": {
"type": "string",
"default": "auto",
"description": dedent(
"""\
Name of an NTP client to use to configure system NTP.
When unprovided or 'auto' the default client preferred
by the distribution will be used. The following
built-in client names can be used to override existing
configuration defaults: chrony, ntp, ntpdate,
systemd-timesyncd."""
),
},
"enabled": {
"type": "boolean",
"default": True,
"description": dedent(
"""\
Attempt to enable ntp clients if set to True. If set
to False, ntp client will not be configured or
installed"""
),
},
"config": {
"description": dedent(
"""\
Configuration settings or overrides for the
``ntp_client`` specified."""
),
"type": ["object"],
"properties": {
"confpath": {
"type": "string",
"description": dedent(
"""\
The path to where the ``ntp_client``
configuration is written."""
),
},
"check_exe": {
"type": "string",
"description": dedent(
"""\
The executable name for the ``ntp_client``.
For example, ntp service ``check_exe`` is
'ntpd' because it runs the ntpd binary."""
),
},
"packages": {
"type": "array",
"items": {
"type": "string",
},
"uniqueItems": True,
"description": dedent(
"""\
List of packages needed to be installed for the
selected ``ntp_client``."""
),
},
"service_name": {
"type": "string",
"description": dedent(
"""\
The systemd or sysvinit service name used to
start and stop the ``ntp_client``
service."""
),
},
"template": {
"type": "string",
"description": dedent(
"""\
Inline template allowing users to define their
own ``ntp_client`` configuration template.
The value must start with '## template:jinja'
to enable use of templating support.
"""
),
},
},
# Don't use REQUIRED_NTP_CONFIG_KEYS to allow for override
# of builtin client values.
"minProperties": 1, # If we have config, define something
"additionalProperties": False,
},
},
"additionalProperties": False,
}
},
}
REQUIRED_NTP_CONFIG_KEYS = frozenset(
["check_exe", "confpath", "packages", "service_name"]
)


__doc__ = get_meta_doc(meta, schema) # Supplement python help()


def distro_ntp_client_configs(distro):
"""Construct a distro-specific ntp client config dictionary by merging
distro specific changes into base config.
Expand Down Expand Up @@ -604,8 +477,6 @@ def handle(name, cfg, cloud, log, _args):
" is a {_type} instead".format(_type=type_utils.obj_name(ntp_cfg))
)

validate_cloudconfig_schema(cfg, schema)

# Allow users to explicitly enable/disable
enabled = ntp_cfg.get("enabled", True)
if util.is_false(enabled):
Expand Down
72 changes: 72 additions & 0 deletions cloudinit/config/cloud-init-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,77 @@
}
}
},
"cc_ntp": {
"type": "object",
"properties": {
"ntp": {
"type": ["null", "object"],
"properties": {
"pools": {
"type": "array",
"items": {
"type": "string",
"format": "hostname"
},
"uniqueItems": true,
"description": "List of ntp pools. If both pools and servers are\nempty, 4 default pool servers will be provided of\nthe format ``{0-3}.{distro}.pool.ntp.org``. NOTE:\nfor Alpine Linux when using the Busybox NTP client\nthis setting will be ignored due to the limited\nfunctionality of Busybox's ntpd."
},
"servers": {
"type": "array",
"items": {
"type": "string",
"format": "hostname"
},
"uniqueItems": true,
"description": "List of ntp servers. If both pools and servers are\nempty, 4 default pool servers will be provided with\nthe format ``{0-3}.{distro}.pool.ntp.org``."
},
"ntp_client": {
"type": "string",
"default": "auto",
"description": "Name of an NTP client to use to configure system NTP.\nWhen unprovided or 'auto' the default client preferred\nby the distribution will be used. The following\nbuilt-in client names can be used to override existing\nconfiguration defaults: chrony, ntp, ntpdate,\nsystemd-timesyncd."
},
"enabled": {
"type": "boolean",
"default": true,
"description": "Attempt to enable ntp clients if set to True. If set\nto False, ntp client will not be configured or\ninstalled"
},
"config": {
"description": "Configuration settings or overrides for the\n``ntp_client`` specified.",
"type": "object",
"properties": {
"confpath": {
"type": "string",
"description": "The path to where the ``ntp_client``\nconfiguration is written."
},
"check_exe": {
"type": "string",
"description": "The executable name for the ``ntp_client``.\nFor example, ntp service ``check_exe`` is\n'ntpd' because it runs the ntpd binary."
},
"packages": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"description": "List of packages needed to be installed for the\nselected ``ntp_client``."
},
"service_name": {
"type": "string",
"description": "The systemd or sysvinit service name used to\nstart and stop the ``ntp_client``\nservice."
},
"template": {
"type": "string",
"description": "Inline template allowing users to define their\nown ``ntp_client`` configuration template.\nThe value must start with '## template:jinja'\nto enable use of templating support.\n"
}
},
"minProperties": 1,
"additionalProperties": false
}
},
"additionalProperties": false
}
}
},
"cc_package_update_upgrade_install": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2174,6 +2245,7 @@
{ "$ref": "#/$defs/cc_mcollective" },
{ "$ref": "#/$defs/cc_migrator" },
{ "$ref": "#/$defs/cc_mounts" },
{ "$ref": "#/$defs/cc_ntp" },
{ "$ref": "#/$defs/cc_package_update_upgrade_install" },
{ "$ref": "#/$defs/cc_phone_home" },
{ "$ref": "#/$defs/cc_power_state_change"},
Expand Down
Loading