Skip to content

Commit

Permalink
schema: add json defs for modules K-L (#1321)
Browse files Browse the repository at this point in the history
schema: add JSON defs for modules K-L

Includes:
- cc_keyboard: migrated legacy scheme to cloud-init-schema.json
- cc_keys_to_console:
- cc_landscape: added schema defs for most frequent client keys
- cc_locale
- cc_lxd

Dropping duplicates docs as schema examples now cover them
 - doc/examples/cloud-config-landscape.txt 
 - doc/examples/cloud-config-lxd.txt 

LP: #1858899, #1858900, #1858901, #1858902
  • Loading branch information
blackboxsw authored Mar 28, 2022
1 parent 4ee6dcb commit 9343539
Show file tree
Hide file tree
Showing 14 changed files with 699 additions and 246 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Do these things for each feature or bug

* Apply black and isort formatting rules with `tox`_::

tox -e format
tox -e do_format

* Run unit tests and lint/formatting checks with `tox`_::

Expand Down
69 changes: 6 additions & 63 deletions cloudinit/config/cc_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@

from cloudinit import distros
from cloudinit import log as logging
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

frequency = PER_INSTANCE

# FIXME: setting keyboard layout should be supported by all OSes.
# But currently only implemented for Linux distributions that use systemd.
osfamilies = ["arch", "debian", "redhat", "suse"]
distros = distros.Distro.expand_osfamily(osfamilies)

DEFAULT_KEYBOARD_MODEL = "pc105"

distros = distros.Distro.expand_osfamily(["arch", "debian", "redhat", "suse"])

meta: MetaSchema = {
"id": "cc_keyboard",
"name": "Keyboard",
"title": "Set keyboard layout",
"description": dedent(
"""\
Handle keyboard configuration.
"""
),
"description": "Handle keyboard configuration.",
"distros": distros,
"examples": [
dedent(
Expand All @@ -55,57 +45,11 @@
"""
),
],
"frequency": frequency,
"frequency": PER_INSTANCE,
}


schema = {
"type": "object",
"properties": {
"keyboard": {
"type": "object",
"properties": {
"layout": {
"type": "string",
"description": dedent(
"""\
Required. Keyboard layout. Corresponds to XKBLAYOUT.
"""
),
},
"model": {
"type": "string",
"default": DEFAULT_KEYBOARD_MODEL,
"description": dedent(
"""\
Optional. Keyboard model. Corresponds to XKBMODEL.
"""
),
},
"variant": {
"type": "string",
"description": dedent(
"""\
Optional. Keyboard variant. Corresponds to XKBVARIANT.
"""
),
},
"options": {
"type": "string",
"description": dedent(
"""\
Optional. Keyboard options. Corresponds to XKBOPTIONS.
"""
),
},
},
"required": ["layout"],
"additionalProperties": False,
}
},
}

__doc__ = get_meta_doc(meta, schema)
__doc__ = get_meta_doc(meta)

LOG = logging.getLogger(__name__)

Expand All @@ -116,7 +60,6 @@ def handle(name, cfg, cloud, log, args):
"Skipping module named %s, no 'keyboard' section found", name
)
return
validate_cloudconfig_schema(cfg, schema)
kb_cfg = cfg["keyboard"]
layout = kb_cfg["layout"]
model = kb_cfg.get("model", DEFAULT_KEYBOARD_MODEL)
Expand Down
80 changes: 49 additions & 31 deletions cloudinit/config/cc_keys_to_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,64 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
Keys to Console
---------------
**Summary:** control which SSH host keys may be written to console
For security reasons it may be desirable not to write SSH host keys and their
fingerprints to the console. To avoid either being written to the console the
``emit_keys_to_console`` config key under the main ``ssh`` config key can be
used. To avoid the fingerprint of types of SSH host keys being written to
console the ``ssh_fp_console_blacklist`` config key can be used. By default
all types of keys will have their fingerprints written to console. To avoid
host keys of a key type being written to console the
``ssh_key_console_blacklist`` config key can be used. By default ``ssh-dss``
host keys are not written to console.
**Internal name:** ``cc_keys_to_console``
**Module frequency:** per instance
**Supported distros:** all
**Config keys**::
ssh:
emit_keys_to_console: false
ssh_fp_console_blacklist: <list of key types>
ssh_key_console_blacklist: <list of key types>
"""
"""Keys to Console: Control which SSH host keys may be written to console"""

import os
from textwrap import dedent

from cloudinit import subp, util
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.settings import PER_INSTANCE

frequency = PER_INSTANCE

# This is a tool that cloud init provides
HELPER_TOOL_TPL = "%s/cloud-init/write-ssh-key-fingerprints"

distros = ["all"]

meta: MetaSchema = {
"id": "cc_keys_to_console",
"name": "Keys to Console",
"title": "Control which SSH host keys may be written to console",
"description": (
"For security reasons it may be desirable not to write SSH host keys"
" and their fingerprints to the console. To avoid either being written"
" to the console the ``emit_keys_to_console`` config key under the"
" main ``ssh`` config key can be used. To avoid the fingerprint of"
" types of SSH host keys being written to console the"
" ``ssh_fp_console_blacklist`` config key can be used. By default,"
" all types of keys will have their fingerprints written to console."
" To avoid host keys of a key type being written to console the"
"``ssh_key_console_blacklist`` config key can be used. By default,"
" ``ssh-dss`` host keys are not written to console."
),
"distros": distros,
"examples": [
dedent(
"""\
# Do not print any SSH keys to system console
ssh:
emit_keys_to_console: false
"""
),
dedent(
"""\
# Do not print certain ssh key types to console
ssh_key_console_blacklist: [dsa, ssh-dss]
"""
),
dedent(
"""\
# Do not print specific ssh key fingerprints to console
ssh_fp_console_blacklist:
- E25451E0221B5773DEBFF178ECDACB160995AA89
- FE76292D55E8B28EE6DB2B34B2D8A784F8C0AAB0
"""
),
],
"frequency": PER_INSTANCE,
}
__doc__ = get_meta_doc(meta)


def _get_helper_tool_path(distro):
try:
Expand Down
110 changes: 63 additions & 47 deletions cloudinit/config/cc_landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,38 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
Landscape
---------
**Summary:** install and configure landscape client
"""install and configure landscape client"""

import os
from io import BytesIO
from textwrap import dedent

from configobj import ConfigObj

from cloudinit import subp, type_utils, util
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.settings import PER_INSTANCE

LSC_CLIENT_CFG_FILE = "/etc/landscape/client.conf"
LS_DEFAULT_FILE = "/etc/default/landscape-client"

# defaults taken from stock client.conf in landscape-client 11.07.1.1-0ubuntu2
LSC_BUILTIN_CFG = {
"client": {
"log_level": "info",
"url": "https://landscape.canonical.com/message-system",
"ping_url": "http://landscape.canonical.com/ping",
"data_path": "/var/lib/landscape/client",
}
}

MODULE_DESCRIPTION = """\
This module installs and configures ``landscape-client``. The landscape client
will only be installed if the key ``landscape`` is present in config. Landscape
client configuration is given under the ``client`` key under the main
``landscape`` config key. The config parameters are not interpreted by
cloud-init, but rather are converted into a ConfigObj formatted file and
written out to ``/etc/landscape/client.conf``.
written out to the `[client]` section in ``/etc/landscape/client.conf``.
The following default client config is provided, but can be overridden::
Expand All @@ -33,53 +54,47 @@
.. note::
if ``tags`` is defined, its contents should be a string delimited with
``,`` rather than a list
**Internal name:** ``cc_landscape``
**Module frequency:** per instance
**Supported distros:** ubuntu
**Config keys**::
landscape:
client:
url: "https://landscape.canonical.com/message-system"
ping_url: "http://landscape.canonical.com/ping"
data_path: "/var/lib/landscape/client"
http_proxy: "http://my.proxy.com/foobar"
https_proxy: "https://my.proxy.com/foobar"
tags: "server,cloud"
computer_title: "footitle"
registration_key: "fookey"
account_name: "fooaccount"
"""

import os
from io import BytesIO

from configobj import ConfigObj

from cloudinit import subp, type_utils, util
from cloudinit.settings import PER_INSTANCE

frequency = PER_INSTANCE

LSC_CLIENT_CFG_FILE = "/etc/landscape/client.conf"
LS_DEFAULT_FILE = "/etc/default/landscape-client"

distros = ["ubuntu"]

# defaults taken from stock client.conf in landscape-client 11.07.1.1-0ubuntu2
LSC_BUILTIN_CFG = {
"client": {
"log_level": "info",
"url": "https://landscape.canonical.com/message-system",
"ping_url": "http://landscape.canonical.com/ping",
"data_path": "/var/lib/landscape/client",
}
meta: MetaSchema = {
"id": "cc_landscape",
"name": "Landscape",
"title": "Install and configure landscape client",
"description": MODULE_DESCRIPTION,
"distros": distros,
"examples": [
dedent(
"""\
# To discover additional supported client keys, run
# man landscape-config.
landscape:
client:
url: "https://landscape.canonical.com/message-system"
ping_url: "http://landscape.canonical.com/ping"
data_path: "/var/lib/landscape/client"
http_proxy: "http://my.proxy.com/foobar"
https_proxy: "https://my.proxy.com/foobar"
tags: "server,cloud"
computer_title: "footitle"
registration_key: "fookey"
account_name: "fooaccount"
"""
),
dedent(
"""\
# Any keys below `client` are optional and the default values will
# be used.
landscape:
client: {}
"""
),
],
"frequency": PER_INSTANCE,
}

__doc__ = get_meta_doc(meta)


def handle(_name, cfg, cloud, log, _args):
"""
Expand All @@ -102,6 +117,7 @@ def handle(_name, cfg, cloud, log, _args):

cloud.distro.install_packages(("landscape-client",))

# Later order config values override earlier values
merge_data = [
LSC_BUILTIN_CFG,
LSC_CLIENT_CFG_FILE,
Expand Down
Loading

0 comments on commit 9343539

Please sign in to comment.