~lutostag/ubuntu/utopic/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/provisioningserver/pxe/config.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Andres Rodriguez, Julian Edwards, Dustin Kirkland
  • Date: 2014-03-28 10:43:53 UTC
  • mfrom: (1.2.26)
  • Revision ID: package-import@ubuntu.com-20140328104353-9hj74f1nvl7xis5z
Tags: 1.5+bzr2204-0ubuntu1
* New upstream release (LP: #1281881)

[ Andres Rodriguez ]
* debian/maas-region-controller-min.templates: Set installation note to false
  by default.
* Check rabbitmqctl is present before running commands:
  - debian/maas-region-controller-min.maas-region-celery.upstart.
  - debian/maas-region-controller-min.maas-txlongpoll.upstart.
* make sure maas_longpoll rabbitmq user is created/with correct password on
  a package reconfigure.
* debian/maas-dns.postinst: Fix upgrade setup of named.conf.options.
* debian/maas-cluster-controller.install: Install UEFI templates (LP: #1299143)

[ Julian Edwards ]
* debian/extas/maas: Echo warning to stderr so json stdout is not polluted
* debian/maas-cluster-controller.postinst: Run upgrade-cluster on each
  upgrade
* debian/maas-dns.postinst: Call edit_named_options to add a line in
  /etc/bind/named.conf.options that includes the
  /etc/named/maas/named.conf.options.inside.maas file.
* debian/control:
  - maas-dns depends on python-iscpy
  - maas-cluster-controller depends on python-seamicroclient
* debian/maas-cluster-controller.install: Install bootresources.yaml

[ Dustin Kirkland ]
* debian/control: LP: #1297097
  - clean up package descriptions, modernize, and more clearly/simply
    explain what each package does
  - drop "Ubuntu" in front of MAAS, clean up command line/API description

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012-2013 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Generating PXE configuration files.
5
 
 
6
 
For more about the format of these files:
7
 
 
8
 
http://www.syslinux.org/wiki/index.php/SYSLINUX#How_do_I_Configure_SYSLINUX.3F
9
 
"""
10
 
 
11
 
from __future__ import (
12
 
    absolute_import,
13
 
    print_function,
14
 
    unicode_literals,
15
 
    )
16
 
 
17
 
str = None
18
 
 
19
 
__metaclass__ = type
20
 
__all__ = [
21
 
    'render_pxe_config',
22
 
    ]
23
 
 
24
 
 
25
 
from errno import ENOENT
26
 
from os import path
27
 
 
28
 
from provisioningserver.kernel_opts import compose_kernel_command_line
29
 
from provisioningserver.pxe.tftppath import compose_image_path
30
 
from provisioningserver.utils import locate_config
31
 
import tempita
32
 
 
33
 
# Location of PXE templates, relative to the configuration directory.
34
 
TEMPLATES_DIR = 'templates/pxe'
35
 
 
36
 
 
37
 
def gen_pxe_template_filenames(purpose, arch, subarch):
38
 
    """List possible PXE template filenames.
39
 
 
40
 
    :param purpose: The boot purpose, e.g. "local".
41
 
    :param arch: Main machine architecture.
42
 
    :param subarch: Sub-architecture, or "generic" if there is none.
43
 
    :param release: The Ubuntu release to be used.
44
 
 
45
 
    Returns a list of possible PXE template filenames using the following
46
 
    lookup order:
47
 
 
48
 
      config.{purpose}.{arch}.{subarch}.template
49
 
      config.{purpose}.{arch}.template
50
 
      config.{purpose}.template
51
 
      config.template
52
 
 
53
 
    """
54
 
    elements = [purpose, arch, subarch]
55
 
    while len(elements) >= 1:
56
 
        yield "config.%s.template" % ".".join(elements)
57
 
        elements.pop()
58
 
    yield "config.template"
59
 
 
60
 
 
61
 
def get_pxe_template(purpose, arch, subarch):
62
 
    pxe_templates_dir = locate_config(TEMPLATES_DIR)
63
 
    # Templates are loaded each time here so that they can be changed on
64
 
    # the fly without restarting the provisioning server.
65
 
    for filename in gen_pxe_template_filenames(purpose, arch, subarch):
66
 
        template_name = path.join(pxe_templates_dir, filename)
67
 
        try:
68
 
            return tempita.Template.from_filename(
69
 
                template_name, encoding="UTF-8")
70
 
        except IOError as error:
71
 
            if error.errno != ENOENT:
72
 
                raise
73
 
    else:
74
 
        error = (
75
 
            "No PXE template found in %r for:\n"
76
 
            "  Purpose: %r, Arch: %r, Subarch: %r\n"
77
 
            "This can happen if you manually power up a node when its "
78
 
            "state is not one that allows it. Is the node in the 'Declared' "
79
 
            "or 'Ready' states? It needs to be Enlisting, Commissioning or "
80
 
            "Allocated." % (
81
 
                pxe_templates_dir, purpose, arch, subarch))
82
 
 
83
 
        raise AssertionError(error)
84
 
 
85
 
 
86
 
def render_pxe_config(kernel_params, **extra):
87
 
    """Render a PXE configuration file as a unicode string.
88
 
 
89
 
    :param kernel_params: An instance of `KernelParameters`.
90
 
    :param extra: Allow for other arguments. This is a safety valve;
91
 
        parameters generated in another component (for example, see
92
 
        `TFTPBackend.get_config_reader`) won't cause this to break.
93
 
    """
94
 
    template = get_pxe_template(
95
 
        kernel_params.purpose, kernel_params.arch,
96
 
        kernel_params.subarch)
97
 
 
98
 
    # The locations of the kernel image and the initrd are defined by
99
 
    # update_install_files(), in scripts/maas-import-pxe-files.
100
 
 
101
 
    def image_dir(params):
102
 
        return compose_image_path(
103
 
            params.arch, params.subarch,
104
 
            params.release, params.purpose)
105
 
 
106
 
    def initrd_path(params):
107
 
        return "%s/initrd.gz" % image_dir(params)
108
 
 
109
 
    def kernel_path(params):
110
 
        return "%s/linux" % image_dir(params)
111
 
 
112
 
    def kernel_command(params):
113
 
        return compose_kernel_command_line(params)
114
 
 
115
 
    namespace = {
116
 
        "initrd_path": initrd_path,
117
 
        "kernel_command": kernel_command,
118
 
        "kernel_params": kernel_params,
119
 
        "kernel_path": kernel_path,
120
 
        }
121
 
    return template.substitute(namespace)