Skip to content

Commit

Permalink
schema: add json defs for modules e-install
Browse files Browse the repository at this point in the history
* cc_emit_upstart (removal)
* cc_fan
* cc_final_message
* cc_foo
* cc_growpart
* cc_grub_dpkg
* cc_install_hotplug
  • Loading branch information
TheRealFalcon committed Apr 3, 2022
1 parent 58ff2cd commit cc21bf5
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 293 deletions.
78 changes: 0 additions & 78 deletions cloudinit/config/cc_emit_upstart.py

This file was deleted.

59 changes: 33 additions & 26 deletions cloudinit/config/cc_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# Author: Scott Moser <scott.moser@canonical.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
"""Fan: Configure ubuntu fan networking"""

"""
Fan
---
**Summary:** configure ubuntu fan networking
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

MODULE_DESCRIPTION = """\
This module installs, configures and starts the ubuntu fan network system. For
more information about Ubuntu Fan, see:
``https://wiki.ubuntu.com/FanNetworking``.
Expand All @@ -18,32 +22,35 @@
- write ``config_path`` with the contents of the ``config`` key
- install the package ``ubuntu-fan`` if it is not installed
- ensure the service is started (or restarted if was previously running)
**Internal name:** ``cc_fan``
**Module frequency:** per instance
**Supported distros:** ubuntu
**Config keys**::
fan:
config: |
# fan 240
10.0.0.0/8 eth0/16 dhcp
10.0.0.0/8 eth1/16 dhcp off
# fan 241
241.0.0.0/8 eth0/16 dhcp
config_path: /etc/network/fan
"""

from cloudinit import log as logging
from cloudinit import subp, util
from cloudinit.settings import PER_INSTANCE
distros = ["ubuntu"]
meta: MetaSchema = {
"id": "cc_fan",
"name": "Fan",
"title": "Configure ubuntu fan networking",
"description": MODULE_DESCRIPTION,
"distros": distros,
"frequency": PER_INSTANCE,
"examples": [
dedent(
"""\
fan:
config: |
# fan 240
10.0.0.0/8 eth0/16 dhcp
10.0.0.0/8 eth1/16 dhcp off
# fan 241
241.0.0.0/8 eth0/16 dhcp
config_path: /etc/network/fan
"""
)
],
}

LOG = logging.getLogger(__name__)
__doc__ = get_meta_doc(meta)

frequency = PER_INSTANCE
LOG = logging.getLogger(__name__)

BUILTIN_CFG = {
"config": None,
Expand Down
49 changes: 30 additions & 19 deletions cloudinit/config/cc_final_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,47 @@
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
"""Final Message: Output final message when cloud-init has finished"""

"""
Final Message
-------------
**Summary:** output final message when cloud-init has finished
from textwrap import dedent

from cloudinit import templater, util, version
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.distros import ALL_DISTROS
from cloudinit.settings import PER_ALWAYS

MODULE_DESCRIPTION = """\
This module configures the final message that cloud-init writes. The message is
specified as a jinja template with the following variables set:
- ``version``: cloud-init version
- ``timestamp``: time at cloud-init finish
- ``datasource``: cloud-init data source
- ``uptime``: system uptime
**Internal name:** ``cc_final_message``
**Module frequency:** always
**Supported distros:** all
**Config keys**::
final_message: <message>
"""

from cloudinit import templater, util, version
from cloudinit.settings import PER_ALWAYS

frequency = PER_ALWAYS
meta: MetaSchema = {
"id": "cc_final_message",
"name": "Final Message",
"title": "Output final message when cloud-init has finished",
"description": MODULE_DESCRIPTION,
"distros": [ALL_DISTROS],
"frequency": frequency,
"examples": [
dedent(
"""\
final_message: |
cloud-init has finished
version: $version
timestamp: $timestamp
datasource: $datasource
uptime: $uptime
"""
)
],
}

__doc__ = get_meta_doc(meta)

# Jinja formated default message
FINAL_MESSAGE_DEF = (
Expand Down
27 changes: 20 additions & 7 deletions cloudinit/config/cc_foo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
"""Foo: Example module"""

"""
Foo
---
**Summary:** example module
from typing import List

from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.settings import PER_ONCE

MODULE_DESCRIPTION = """\
Example to show module structure. Does not do anything.
**Internal name:** ``cc_foo``
Expand All @@ -20,7 +22,20 @@
**Supported distros:** all
"""

from cloudinit.settings import PER_INSTANCE
distros: List[str] = []
frequency = PER_ONCE
meta: MetaSchema = {
"id": "cc_foo",
"name": "Foo",
"title": "Example module",
"description": MODULE_DESCRIPTION,
"distros": distros,
"frequency": frequency,
"examples": [],
}

__doc__ = get_meta_doc(meta)


# Modules are expected to have the following attributes.
# 1. A required 'handle' method which takes the following params.
Expand All @@ -47,8 +62,6 @@
# informational purposes. If non existent all distros are assumed and
# no warning occurs.

frequency = PER_INSTANCE


def handle(name, _cfg, _cloud, log, _args):
log.debug("Hi from module %s", name)
Expand Down
Loading

0 comments on commit cc21bf5

Please sign in to comment.