This file is indexed.

/usr/lib/python3/dist-packages/provisioningserver/drivers/__init__.py is in python3-maas-provisioningserver 2.4.0~beta2-6865-gec43e47e6-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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Copyright 2014-2016 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Drivers."""

__all__ = [
    "Architecture",
    "ArchitectureRegistry",
    ]

from jsonschema import validate
from provisioningserver.utils import typed
from provisioningserver.utils.registry import Registry


class IP_EXTRACTOR_PATTERNS:
    """Commonly used patterns IP extractor patterns."""

    # Use the entire string as the value.
    IDENTITY = '^(?P<address>.+?)$'

    # The typical URL pattern. Extracts address field as the value.
    # The given URL has an address component that is one of:
    # (1) an IPv6 IP address surrounded by []
    # (2) an IPv4 IP address (no [])
    # (3) a name
    # (4) the empty string.
    # Cases 2 and 3 are processed in the regex by excluding all []/: from the
    # allowed values.  The need to verify the [] around the IPv6 IP address
    # introduces a goodly amount of complexity due to looking forward/backward
    # to determine if [] is ok/expected.
    # The resulting address is simply the IP address (v6 or v4), or a hostname.
    URL = (r'^'
           r'((?P<schema>.+?)://)?'
           r'((?P<user>.+?)(:(?P<password>.*?))?@)?'

           r'(?:\[(?=[0-9a-fA-F]*:[0-9a-fA-F.:]+\]))?'
           r'(?P<address>(?:(?:[^\[\]/:]*(?!\]))|'
           r'(?:(?<=\[)[0-9a-fA-F:.]+(?=\]))))\]?'

           r'(:(?P<port>\d+?))?'
           r'(?P<path>/.*?)?'
           r'(?P<query>[?].*?)?'
           r'$'
           )


# Python REGEX pattern for extracting IP address from parameter field.
# The field_name tells the extractor which power_parameter field to use.
# Name the address field 'address' in your Python regex pattern.
# The pattern will be used as in 're.match(pattern, field_value)'.
IP_EXTRACTOR_SCHEMA = {
    'title': "IP Extractor Configuration",
    'type': 'object',
    'properties': {
        'field_name': {
            'type': 'string',
        },
        'pattern': {
            'type': 'string',
        },
    },
    "dependencies": {
        "field_name": ["pattern"],
        "pattern": ["field_name"]
    },
}

# JSON schema representing the Django choices format as JSON; an array of
# 2-item arrays.
CHOICE_FIELD_SCHEMA = {
    'type': 'array',
    'items': {
        'title': "Setting parameter field choice",
        'type': 'array',
        'minItems': 2,
        'maxItems': 2,
        'uniqueItems': True,
        'items': {
            'type': 'string',
        }
    },
}

# JSON schema for what a settings field should look like.
SETTING_PARAMETER_FIELD_SCHEMA = {
    'title': "Setting parameter field",
    'type': 'object',
    'properties': {
        'name': {
            'type': 'string',
        },
        'field_type': {
            'type': 'string',
        },
        'label': {
            'type': 'string',
        },
        'required': {
            'type': 'boolean',
        },
        # 'bmc' or 'node': Whether value lives on bmc (global) or node/device.
        'scope': {
            'type': 'string',
        },
        'choices': CHOICE_FIELD_SCHEMA,
        'default': {
            'type': 'string',
        },
    },
    'required': ['field_type', 'label', 'required'],
}


def make_ip_extractor(field_name, pattern=IP_EXTRACTOR_PATTERNS.IDENTITY):
    return {
        'field_name': field_name,
        'pattern': pattern,
    }


class SETTING_SCOPE:
    BMC = "bmc"
    NODE = "node"


def make_setting_field(
        name, label, field_type=None, choices=None, default=None,
        required=False, scope=SETTING_SCOPE.BMC):
    """Helper function for building a JSON setting parameters field.

    :param name: The name of the field.
    :type name: string
    :param label: The label to be presented to the user for this field.
    :type label: string
    :param field_type: The type of field to create. Can be one of
        (string, choice, mac_address). Defaults to string.
    :type field_type: string.
    :param choices: The collection of choices to present to the user.
        Needs to be structured as a list of lists, otherwise
        make_setting_field() will raise a ValidationError.
    :type list:
    :param default: The default value for the field.
    :type default: string
    :param required: Whether or not a value for the field is required.
    :type required: boolean
    :param scope: 'bmc' or 'node' - Whether value is bmc or node specific.
        Defaults to 'bmc'.
    :type scope: string
    """
    if field_type not in ('string', 'mac_address', 'choice', 'password'):
        field_type = 'string'
    if choices is None:
        choices = []
    validate(choices, CHOICE_FIELD_SCHEMA)
    if default is None:
        default = ""
    if scope not in (SETTING_SCOPE.BMC, SETTING_SCOPE.NODE):
        scope = SETTING_SCOPE.BMC
    return {
        'name': name,
        'label': label,
        'required': required,
        'field_type': field_type,
        'choices': choices,
        'default': default,
        'scope': scope,
    }


class Architecture:

    def __init__(self, name, description, pxealiases=None,
                 kernel_options=None):
        """Represents an architecture in the driver context.

        :param name: The architecture name as used in MAAS.
            arch/subarch or just arch.
        :param description: The human-readable description for the
            architecture.
        :param pxealiases: The optional list of names used if the
            hardware uses a different name when requesting its bootloader.
        :param kernel_options: The optional list of kernel options for this
            architecture.  Anything supplied here supplements the options
            provided by MAAS core.
        """
        if pxealiases is None:
            pxealiases = ()
        self.name = name
        self.description = description
        self.pxealiases = pxealiases
        self.kernel_options = kernel_options


class ArchitectureRegistry(Registry):
    """Registry for architecture classes."""

    @classmethod
    @typed
    def get_by_pxealias(cls, alias: str):
        for _, arch in cls:
            if alias in arch.pxealiases:
                return arch
        return None


builtin_architectures = [
    Architecture(name="i386/generic", description="i386"),
    Architecture(name="amd64/generic", description="amd64"),
    Architecture(
        name="arm64/generic", description="arm64/generic",
        pxealiases=["arm"]),
    Architecture(
        name="arm64/xgene-uboot", description="arm64/xgene-uboot",
        pxealiases=["arm"]),
    Architecture(
        name="arm64/xgene-uboot-mustang",
        description="arm64/xgene-uboot-mustang", pxealiases=["arm"]),
    Architecture(
        name="armhf/highbank", description="armhf/highbank",
        pxealiases=["arm"], kernel_options=["console=ttyAMA0"]),
    Architecture(
        name="armhf/generic", description="armhf/generic",
        pxealiases=["arm"], kernel_options=["console=ttyAMA0"]),
    Architecture(
        name="armhf/keystone", description="armhf/keystone",
        pxealiases=["arm"]),
    # PPC64EL needs a rootdelay for PowerNV. The disk controller
    # in the hardware, takes a little bit longer to come up then
    # the initrd wants to wait. Set this to 60 seconds, just to
    # give the booting machine enough time. This doesn't slow down
    # the booting process, it just increases the timeout.
    Architecture(
        name="ppc64el/generic", description="ppc64el",
        kernel_options=['rootdelay=60']),
]
for arch in builtin_architectures:
    ArchitectureRegistry.register_item(arch.name, arch)