summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_seed_random.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config/cc_seed_random.py')
-rw-r--r--cloudinit/config/cc_seed_random.py103
1 files changed, 51 insertions, 52 deletions
diff --git a/cloudinit/config/cc_seed_random.py b/cloudinit/config/cc_seed_random.py
index 67ba8ef5..b0ffdd15 100644
--- a/cloudinit/config/cc_seed_random.py
+++ b/cloudinit/config/cc_seed_random.py
@@ -6,73 +6,72 @@
# Author: Scott Moser <scott.moser@canonical.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
+"""Seed Random: Provide random seed data"""
-"""
-Seed Random
------------
-**Summary:** provide random seed data
+import base64
+import os
+from io import BytesIO
+from textwrap import dedent
+
+from cloudinit import log as logging
+from cloudinit import subp, util
+from cloudinit.config.schema import MetaSchema, get_meta_doc
+from cloudinit.distros import ALL_DISTROS
+from cloudinit.settings import PER_INSTANCE
+
+LOG = logging.getLogger(__name__)
-Since all cloud instances started from the same image will produce very similar
-data when they are first booted, as they are all starting with the same seed
+MODULE_DESCRIPTION = """\
+All cloud instances started from the same image will produce very similar
+data when they are first booted as they are all starting with the same seed
for the kernel's entropy keyring. To avoid this, random seed data can be
provided to the instance either as a string or by specifying a command to run
to generate the data.
-Configuration for this module is under the ``random_seed`` config key. The
-``file`` key specifies the path to write the data to, defaulting to
-``/dev/urandom``. Data can be passed in directly with ``data``, and may
-optionally be specified in encoded form, with the encoding specified in
-``encoding``.
-
-If the cloud provides its own random seed data, it will be appended to ``data``
+Configuration for this module is under the ``random_seed`` config key. If
+the cloud provides its own random seed data, it will be appended to ``data``
before it is written to ``file``.
-.. note::
- when using a multiline value for ``data`` or specifying binary data, be
- sure to follow yaml syntax and use the ``|`` and ``!binary`` yaml format
- specifiers when appropriate
-
If the ``command`` key is specified, the given command will be executed. This
will happen after ``file`` has been populated. That command's environment will
contain the value of the ``file`` key as ``RANDOM_SEED_FILE``. If a command is
specified that cannot be run, no error will be reported unless
``command_required`` is set to true.
-
-For example, to use ``pollinate`` to gather data from a
-remote entropy server and write it to ``/dev/urandom``, the following could be
-used::
-
- random_seed:
- file: /dev/urandom
- command: ["pollinate", "--server=http://local.polinate.server"]
- command_required: true
-
-**Internal name:** ``cc_seed_random``
-
-**Module frequency:** per instance
-
-**Supported distros:** all
-
-**Config keys**::
-
- random_seed:
- file: <file>
- data: <random string>
- encoding: <raw/base64/b64/gzip/gz>
- command: [<cmd name>, <arg1>, <arg2>...]
- command_required: <true/false>
"""
-import base64
-import os
-from io import BytesIO
-
-from cloudinit import log as logging
-from cloudinit import subp, util
-from cloudinit.settings import PER_INSTANCE
-
-frequency = PER_INSTANCE
-LOG = logging.getLogger(__name__)
+meta: MetaSchema = {
+ "id": "cc_seed_random",
+ "name": "Seed Random",
+ "title": "Provide random seed data",
+ "description": MODULE_DESCRIPTION,
+ "distros": [ALL_DISTROS],
+ "frequency": PER_INSTANCE,
+ "examples": [
+ dedent(
+ """\
+ random_seed:
+ file: /dev/urandom
+ data: my random string
+ encoding: raw
+ command: ['sh', '-c', 'dd if=/dev/urandom of=$RANDOM_SEED_FILE']
+ command_required: true
+ """
+ ),
+ dedent(
+ """\
+ # To use 'pollinate' to gather data from a remote entropy
+ # server and write it to '/dev/urandom', the following
+ # could be used:
+ random_seed:
+ file: /dev/urandom
+ command: ["pollinate", "--server=http://local.polinate.server"]
+ command_required: true
+ """
+ ),
+ ],
+}
+
+__doc__ = get_meta_doc(meta)
def _decode(data, encoding=None):