This file is indexed.

/usr/lib/python3/dist-packages/provisioningserver/dhcp/config.py is in python3-maas-provisioningserver 2.0.0~beta3+bzr4941-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright 2012-2016 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Write config output for ISC DHCPD."""

__all__ = [
    "DHCPConfigError",
    "get_config",
]


from itertools import (
    chain,
    repeat,
)
from platform import linux_distribution

from provisioningserver.boot import BootMethodRegistry
from provisioningserver.utils import locate_template
import tempita

# Used to generate the conditional bootloader behaviour
CONDITIONAL_BOOTLOADER = """
{{behaviour}} option arch = {{arch_octet}} {
    filename \"{{bootloader}}\";
    {{if path_prefix}}
    option path-prefix \"{{path_prefix}}\";
    {{endif}}
}
"""

# Used to generate the PXEBootLoader special case
PXE_BOOTLOADER = """
else {
    filename \"{{bootloader}}\";
    {{if path_prefix}}
    option path-prefix \"{{path_prefix}}\";
    {{endif}}
}
"""


class DHCPConfigError(Exception):
    """Exception raised for errors processing the DHCP config."""


def compose_conditional_bootloader():
    output = ""
    behaviour = chain(["if"], repeat("elsif"))
    for name, method in BootMethodRegistry:
        if name != "pxe" and method.arch_octet is not None:
            output += tempita.sub(
                CONDITIONAL_BOOTLOADER,
                behaviour=next(behaviour),
                arch_octet=method.arch_octet,
                bootloader=method.bootloader_path,
                path_prefix=method.path_prefix,
                ).strip() + ' '

    # The PXEBootMethod is used in an else statement for the generated
    # dhcpd config. This ensures that a booting node that does not
    # provide an architecture octet, or architectures that emulate
    # pxelinux can still boot.
    pxe_method = BootMethodRegistry.get_item('pxe')
    if pxe_method is not None:
        output += tempita.sub(
            PXE_BOOTLOADER,
            bootloader=pxe_method.bootloader_path,
            path_prefix=pxe_method.path_prefix,
            ).strip()
    return output.strip()


def get_config(template_name, **params):
    """Return a DHCP config file based on the supplied parameters.

    :param template_name: Template file name: `dhcpd.conf.template` for the
        IPv4 template, `dhcpd6.conf.template` for the IPv6 template.
    :param **params: Variables to be substituted into the template.
    :return: A full configuration, as unicode text.
    """
    template_file = locate_template('dhcp', template_name)
    params['bootloader'] = compose_conditional_bootloader()
    params['platform_codename'] = linux_distribution()[2]
    params.setdefault("ntp_server")
    try:
        template = tempita.Template.from_filename(
            template_file, encoding="UTF-8")
        return template.substitute(**params)
    except (KeyError, NameError) as error:
        raise DHCPConfigError(
            "Failed to render DHCP configuration.") from error