~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/common/pxe_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-04-17 09:28:31 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20150417092831-wu2awfbqomnzpeim
Tags: 2015.1~rc1-0ubuntu1
* New upstream milestone release:
  - d/control: Align with upstream dependencies
  - d/p/fix-requirements.patch: Dropped no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from ironic.common import exception
24
24
from ironic.common.i18n import _
25
25
from ironic.common import utils
 
26
from ironic.drivers.modules import deploy_utils
26
27
from ironic.drivers import utils as driver_utils
27
28
from ironic.openstack.common import fileutils
28
29
from ironic.openstack.common import log as logging
79
80
    :param task: A TaskManager instance.
80
81
 
81
82
    """
82
 
    pxe_config_file_path = get_pxe_config_file_path(task.node.uuid)
83
 
    for mac in driver_utils.get_node_mac_addresses(task):
84
 
        mac_path = _get_pxe_mac_path(mac)
 
83
 
 
84
    def create_link(mac_path):
85
85
        utils.unlink_without_raise(mac_path)
86
86
        utils.create_link_without_raise(pxe_config_file_path, mac_path)
87
87
 
 
88
    pxe_config_file_path = get_pxe_config_file_path(task.node.uuid)
 
89
    for mac in driver_utils.get_node_mac_addresses(task):
 
90
        create_link(_get_pxe_mac_path(mac))
 
91
        # TODO(lucasagomes): Backward compatibility with :hexraw,
 
92
        # to be removed in M.
 
93
        # see: https://bugs.launchpad.net/ironic/+bug/1441710
 
94
        if CONF.pxe.ipxe_enabled:
 
95
            create_link(_get_pxe_mac_path(mac, delimiter=''))
 
96
 
88
97
 
89
98
def _link_ip_address_pxe_configs(task):
90
99
    """Link each IP address with the PXE configuration file.
109
118
                                         ip_address_path)
110
119
 
111
120
 
112
 
def _get_pxe_mac_path(mac):
 
121
def _get_pxe_mac_path(mac, delimiter=None):
113
122
    """Convert a MAC address into a PXE config file name.
114
123
 
115
124
    :param mac: A MAC address string in the format xx:xx:xx:xx:xx:xx.
 
125
    :param delimiter: The MAC address delimiter. Defaults to dash ('-').
116
126
    :returns: the path to the config file.
117
127
 
118
128
    """
119
 
    if CONF.pxe.ipxe_enabled:
120
 
        mac_file_name = mac.replace(':', '').lower()
121
 
    else:
122
 
        mac_file_name = "01-" + mac.replace(":", "-").lower()
 
129
    if delimiter is None:
 
130
        delimiter = '-'
 
131
 
 
132
    mac_file_name = mac.replace(':', delimiter).lower()
 
133
    if not CONF.pxe.ipxe_enabled:
 
134
        mac_file_name = '01-' + mac_file_name
123
135
 
124
136
    return os.path.join(get_root_dir(), PXE_CFG_DIR_NAME, mac_file_name)
125
137
 
191
203
    pxe_config = _build_pxe_config(pxe_options, template)
192
204
    utils.write_to_file(pxe_config_file_path, pxe_config)
193
205
 
194
 
    if driver_utils.get_node_capability(task.node, 'boot_mode') == 'uefi':
 
206
    if deploy_utils.get_boot_mode_for_deploy(task.node) == 'uefi':
195
207
        _link_ip_address_pxe_configs(task)
196
208
    else:
197
209
        _link_mac_pxe_configs(task)
205
217
    """
206
218
    LOG.debug("Cleaning up PXE config for node %s", task.node.uuid)
207
219
 
208
 
    if driver_utils.get_node_capability(task.node, 'boot_mode') == 'uefi':
 
220
    if deploy_utils.get_boot_mode_for_deploy(task.node) == 'uefi':
209
221
        api = dhcp_factory.DHCPFactory().provider
210
222
        ip_addresses = api.get_ip_addresses(task)
211
223
        if not ip_addresses:
220
232
    else:
221
233
        for mac in driver_utils.get_node_mac_addresses(task):
222
234
            utils.unlink_without_raise(_get_pxe_mac_path(mac))
 
235
            # TODO(lucasagomes): Backward compatibility with :hexraw,
 
236
            # to be removed in M.
 
237
            # see: https://bugs.launchpad.net/ironic/+bug/1441710
 
238
            if CONF.pxe.ipxe_enabled:
 
239
                utils.unlink_without_raise(_get_pxe_mac_path(mac,
 
240
                                           delimiter=''))
223
241
 
224
242
    utils.rmtree_without_raise(os.path.join(get_root_dir(),
225
243
                                            task.node.uuid))
252
270
        dhcp_opts.append({'opt_name': 'bootfile-name',
253
271
                          'opt_value': ipxe_script_url})
254
272
    else:
255
 
        if driver_utils.get_node_capability(task.node, 'boot_mode') == 'uefi':
 
273
        if deploy_utils.get_boot_mode_for_deploy(task.node) == 'uefi':
256
274
            boot_file = CONF.pxe.uefi_pxe_bootfile_name
257
275
        else:
258
276
            boot_file = CONF.pxe.pxe_bootfile_name