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
33 changes: 7 additions & 26 deletions cloudinit/config/cc_resizefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@
from textwrap import dedent

from cloudinit import subp, util
from cloudinit.config.schema import (
MetaSchema,
get_meta_doc,
validate_cloudconfig_schema,
)
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.distros import ALL_DISTROS
from cloudinit.settings import PER_ALWAYS

NOBLOCK = "noblock"

frequency = PER_ALWAYS
distros = ["all"]

meta: MetaSchema = {
"id": "cc_resizefs",
"name": "Resizefs",
Expand All @@ -39,30 +33,18 @@
partition and will block the boot process while the resize command is
running. Optionally, the resize operation can be performed in the
background while cloud-init continues running modules. This can be
enabled by setting ``resize_rootfs`` to ``true``. This module can be
enabled by setting ``resize_rootfs`` to ``noblock``. This module can be
disabled altogether by setting ``resize_rootfs`` to ``false``."""
),
"distros": distros,
"distros": [ALL_DISTROS],
"examples": [
"resize_rootfs: false # disable root filesystem resize operation"
"resize_rootfs: false # disable root filesystem resize operation",
"resize_rootfs: noblock # runs resize operation in the background",
],
"frequency": PER_ALWAYS,
}

schema = {
"type": "object",
"properties": {
"resize_rootfs": {
"enum": [True, False, NOBLOCK],
"description": dedent(
"""\
Whether to resize the root partition. Default: 'true'"""
),
}
},
}

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


def _resize_btrfs(mount_point, devpth):
Expand Down Expand Up @@ -229,7 +211,6 @@ def handle(name, cfg, _cloud, log, args):
resize_root = args[0]
else:
resize_root = util.get_cfg_option_str(cfg, "resize_rootfs", True)
validate_cloudconfig_schema(cfg, schema)
if not util.translate_bool(resize_root, addons=[NOBLOCK]):
log.debug("Skipping module named %s, resizing disabled", name)
return
Expand Down
92 changes: 55 additions & 37 deletions cloudinit/config/cc_resolv_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,79 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
Resolv Conf
-----------
**Summary:** configure resolv.conf
"""Resolv Conf: configure resolv.conf"""

from textwrap import dedent

from cloudinit import log as logging
from cloudinit import templater, util
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.settings import PER_INSTANCE

LOG = logging.getLogger(__name__)

RESOLVE_CONFIG_TEMPLATE_MAP = {
"/etc/resolv.conf": "resolv.conf",
"/etc/systemd/resolved.conf": "systemd.resolved.conf",
}

MODULE_DESCRIPTION = """\
This module is intended to manage resolv.conf in environments where early
configuration of resolv.conf is necessary for further bootstrapping and/or
where configuration management such as puppet or chef own dns configuration.
where configuration management such as puppet or chef own DNS configuration.
As Debian/Ubuntu will, by default, utilize resolvconf, and similarly Red Hat
will use sysconfig, this module is likely to be of little use unless those
are configured correctly.

When using a :ref:`datasource_config_drive` and a RHEL-like system,
resolv.conf will also be managed automatically due to the available
information provided for DNS servers in the :ref:`network_config_v2` format.
For those that with to have different settings, use this module.

In order for the ``resolv_conf`` section to be applied, ``manage_resolv_conf``
must be set ``true``.

.. note::
For Red Hat with sysconfig, be sure to set PEERDNS=no for all DHCP
enabled NICs.

.. note::
And, in Ubuntu/Debian it is recommended that DNS be configured via the
standard /etc/network/interfaces configuration file.

**Internal name:** ``cc_resolv_conf``

**Module frequency:** per instance

**Supported distros:** alpine, fedora, photon, rhel, sles

**Config keys**::

manage_resolv_conf: <true/false>
resolv_conf:
nameservers: ['8.8.4.4', '8.8.8.8']
searchdomains:
- foo.example.com
- bar.example.com
domain: example.com
options:
rotate: <true/false>
timeout: 1
"""

from cloudinit import log as logging
from cloudinit import templater, util
from cloudinit.settings import PER_INSTANCE

LOG = logging.getLogger(__name__)

frequency = PER_INSTANCE

distros = ["alpine", "fedora", "opensuse", "photon", "rhel", "sles"]

RESOLVE_CONFIG_TEMPLATE_MAP = {
"/etc/resolv.conf": "resolv.conf",
"/etc/systemd/resolved.conf": "systemd.resolved.conf",
meta: MetaSchema = {
"id": "cc_resolv_conf",
"name": "Resolv Conf",
"title": "Configure resolv.conf",
"description": MODULE_DESCRIPTION,
"distros": ["alpine", "fedora", "opensuse", "photon", "rhel", "sles"],
"frequency": PER_INSTANCE,
"examples": [
dedent(
"""\
manage_resolv_conf: true
resolv_conf:
nameservers:
- 8.8.8.8
- 8.8.4.4
searchdomains:
- foo.example.com
- bar.example.com
domain: example.com
sortlist:
- 10.0.0.1/255
- 10.0.0.2
options:
rotate: true
timeout: 1
"""
)
],
}

__doc__ = get_meta_doc(meta)


def generate_resolv_conf(template_fn, params, target_fname):
flags = []
Expand Down
97 changes: 63 additions & 34 deletions cloudinit/config/cc_rh_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,76 @@
# Author: Brent Baude <bbaude@redhat.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
"""Red Hat Subscription: Register Red Hat Enterprise Linux based system"""

"""
Red Hat Subscription
--------------------
**Summary:** register red hat enterprise linux based system

Register a Red Hat system either by username and password *or* activation and
org. Following a sucessful registration, you can auto-attach subscriptions, set
the service level, add subscriptions based on pool id, enable/disable yum
repositories based on repo id, and alter the rhsm_baseurl and server-hostname
in ``/etc/rhsm/rhs.conf``. For more details, see the ``Register Red Hat
Subscription`` example config.

**Internal name:** ``cc_rh_subscription``

**Module frequency:** per instance

**Supported distros:** rhel, fedora

**Config keys**::

rh_subscription:
username: <username>
password: <password>
activation-key: <activation key>
org: <org number>
auto-attach: <true/false>
service-level: <service level>
add-pool: <list of pool ids>
enable-repo: <list of yum repo ids>
disable-repo: <list of yum repo ids>
rhsm-baseurl: <url>
server-hostname: <hostname>
"""
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.settings import PER_INSTANCE

LOG = logging.getLogger(__name__)

distros = ["fedora", "rhel"]
MODULE_DESCRIPTION = """\
Register a Red Hat system either by username and password *or* activation and
org. Following a sucessful registration, you can:
- auto-attach subscriptions
- set the service level
- add subscriptions based on pool id
- enable/disable yum repositories based on repo id
- alter the rhsm_baseurl and server-hostname in ``/etc/rhsm/rhs.conf``.
"""

meta: MetaSchema = {
"id": "cc_rh_subscription",
"name": "Red Hat Subscription",
"title": "Register Red Hat Enterprise Linux based system",
"description": MODULE_DESCRIPTION,
"distros": ["fedora", "rhel"],
"frequency": PER_INSTANCE,
"examples": [
dedent(
"""\
rh_subscription:
username: joe@foo.bar
## Quote your password if it has symbols to be safe
password: '1234abcd'
"""
),
dedent(
"""\
rh_subscription:
activation-key: foobar
org: 12345
"""
),
dedent(
"""\
rh_subscription:
activation-key: foobar
org: 12345
auto-attach: true
service-level: self-support
add-pool:
- 1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a
- 2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b
enable-repo:
- repo-id-to-enable
- other-repo-id-to-enable
disable-repo:
- repo-id-to-disable
- other-repo-id-to-disable
# Alter the baseurl in /etc/rhsm/rhsm.conf
rhsm-baseurl: http://url
# Alter the server hostname in /etc/rhsm/rhsm.conf
server-hostname: foo.bar.com
"""
),
],
}

__doc__ = get_meta_doc(meta)


def handle(name, cfg, _cloud, log, _args):
Expand Down
52 changes: 28 additions & 24 deletions cloudinit/config/cc_rightscale_userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
Rightscale Userdata
-------------------
**Summary:** support rightscale configuration hooks
import os
from urllib.parse import parse_qs

from cloudinit import url_helper as uhelp
from cloudinit import util
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.distros import ALL_DISTROS
from cloudinit.settings import PER_INSTANCE

MY_NAME = "cc_rightscale_userdata"
MY_HOOKNAME = "CLOUD_INIT_REMOTE_HOOK"

"""Rightscale Userdata: Support rightscale configuration hooks"""

MODULE_DESCRIPTION = """\
This module adds support for RightScale configuration hooks to cloud-init.
RightScale adds a entry in the format ``CLOUD_INIT_REMOTE_HOOK=http://...`` to
RightScale adds an entry in the format ``CLOUD_INIT_REMOTE_HOOK=http://...`` to
ec2 user-data. This module checks for this line in the raw userdata and
retrieves any scripts linked by the RightScale user data and places them in the
user scripts configuration directory, to be run later by ``cc_scripts_user``.
Expand All @@ -21,17 +31,23 @@
the ``CLOUD_INIT_REMOTE_HOOK`` config variable is present in the raw ec2
user data only, not in any cloud-config parts

**Internal name:** ``cc_rightscale_userdata``

**Module frequency:** per instance

**Supported distros:** all

**Config keys**::
**Raw user data schema**::

CLOUD_INIT_REMOTE_HOOK=<url>
"""

meta: MetaSchema = {
"id": "cc_rightscale_userdata",
"name": "RightScale Userdata",
"title": "Support rightscale configuration hooks",
"description": MODULE_DESCRIPTION,
"distros": [ALL_DISTROS],
"frequency": PER_INSTANCE,
"examples": [],
}

__doc__ = get_meta_doc(meta)

#
# The purpose of this script is to allow cloud-init to consume
# rightscale style userdata. rightscale user data is key-value pairs
Expand All @@ -49,18 +65,6 @@
#
#

import os
from urllib.parse import parse_qs

from cloudinit import url_helper as uhelp
from cloudinit import util
from cloudinit.settings import PER_INSTANCE

frequency = PER_INSTANCE

MY_NAME = "cc_rightscale_userdata"
MY_HOOKNAME = "CLOUD_INIT_REMOTE_HOOK"


def handle(name, _cfg, cloud, log, _args):
try:
Expand Down
Loading