/usr/lib/python2.7/dist-packages/maasserver/third_party_drivers.py is in python-django-maas 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 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 | # Copyright 2014 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Third party driver support.
The current implementation is limited in a number of ways:
- Third party driver locations are currently hardcoded. Eventually,
they will be fetched from a stream.
- Only one third party driver can be matched per system.
- Only on module, package, and blacklisted module can be configured
per system.
- udeb fetching will only work if there is one driver per repository.
There can be multiple versions of the udeb, but not udebs for multiple
drivers.
- Third party drivers are only used for debian installer installations,
not for commissioning or fastpath installations.
"""
from __future__ import (
absolute_import,
print_function,
unicode_literals,
)
str = None
__metaclass__ = type
__all__ = [
'get_third_party_driver',
]
from copy import deepcopy
import fnmatch
from formencode import (
ForEach,
Schema,
)
from formencode.validators import String
from metadataserver.models import commissioningscript
from provisioningserver.config import (
ConfigBase,
ConfigMeta,
)
"""
Here's a description of fields for each entry for a third_party_driver.
blacklist - The name of a module to blacklist when using this driver.
The driver will be blacklisted via the kernel command line during
installation, and via a modprobe.d entry afterwards.
comment - A comment string that will be added to the sources.list file
on the target.
key_binary - The public key for the repository in binary. Starting with a
binary gpg key file (NOT ascii armored) containing the key for a repository,
you can generate the key binary string like this:
>>>> import yaml
>>>> key_text = open('my_key.gpg').read()
>>>> print yaml.dump(key_text)
NOTE: If you start off with an ascii armored key, you can convert it into
a binary key by importing it into a gpg keyring, then exporting it into
a file without using -a/--armor.
You can inspect a key from drivers.yaml by dumping it back into a file
and using gpg to manipulate it:
>>> import yaml
>>> drivers_config = yaml.load(open('etc/maas/drivers.yaml').read())
>>> drivers_list = drivers_config['drivers']
>>> first_driver = drivers_list[0]
>>> open('some_key.gpg', 'w').write(first_driver['key_binary'])
$ gpg --import -n some_key.gpg
gpg: key CF700356: "Launchpad PPA for Some Driver" not changed
gpg: Total number processed: 1
gpg: unchanged: 1
modaliases - The list of modaliases patterns to match when deciding when
to use this driver. MAAS collects modalias strings for nodes during
enlistment, and at install time, will compare those modalias strings to
the modalias patterns supplied for drivers.
module - The name of the kernel module to load on the target system.
repository - The URL of the repository to load packages from. The should
repository contain both deb and udeb packages for the driver.
packages - The name of the deb package to retrieve from the repository.
"""
class ConfigDriver(Schema):
"""Configuration validator for a driver."""
if_key_missing = None
blacklist = String()
comment = String()
key_binary = String()
modaliases = ForEach(String)
module = String()
package = String()
repository = String()
class DriversConfig(ConfigBase):
"""Configuration for third party drivers."""
class __metaclass__(ConfigMeta):
envvar = "MAAS_THIRD_PARTY_DRIVER_SETTINGS"
default = "drivers.yaml"
if_key_missing = None
drivers = ForEach(ConfigDriver)
def node_modaliases(node):
"""Return a list of modaliases from the node."""
name = commissioningscript.LIST_MODALIASES_OUTPUT_NAME
query = node.nodecommissionresult_set.filter(name__exact=name)
if len(query) == 0:
return []
results = query.first().data
return results.splitlines()
def match_aliases_to_driver(detected_aliases, drivers):
"""Find the first driver that matches any supplied modalias."""
for driver in drivers:
for alias in driver['modaliases']:
matches = fnmatch.filter(detected_aliases, alias)
if len(matches) > 0:
return driver
return None
def populate_kernel_opts(driver):
"""Create kernel option string from module blacklist."""
blacklist = driver.get('blacklist')
if blacklist is not None:
driver['kernel_opts'] = 'modprobe.blacklist=%s' % blacklist
return driver
def get_third_party_driver(node):
"""Determine which, if any, third party driver is required.
Use the node's modaliases strings to determine if a third party
driver is required.
"""
detected_aliases = node_modaliases(node)
third_party_drivers_config = DriversConfig.load_from_cache()
third_party_drivers = third_party_drivers_config['drivers']
matched_driver = match_aliases_to_driver(detected_aliases,
third_party_drivers)
if matched_driver is None:
return dict()
driver = deepcopy(matched_driver)
driver = populate_kernel_opts(driver)
return driver
|