This file is indexed.

/usr/lib/python2.7/dist-packages/provisioningserver/dhcp/config.py is in python-maas-provisioningserver 1.5.4+bzr2294-0ubuntu1.2.

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
93
94
95
96
97
# Copyright 2012-2014 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."""

from __future__ import (
    absolute_import,
    print_function,
    unicode_literals,
    )

str = None

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


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

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

# Location of DHCP templates, relative to the configuration directory.
TEMPLATES_DIR = "templates/dhcp"

# 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":
            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(**params):
    """Return a DHCP config file based on the supplied parameters."""
    template_file = locate_config(TEMPLATES_DIR, 'dhcpd.conf.template')
    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(*error.args)