Method to generate PXE options for Neutron ports

Add a new method to generate the structure containing the PXE
bootfile-name, server-ip-address, and tftp-server information.
This information will be used to provide Neutron DHCP options
to set up the PXE booting of nodes. This patch does not actually pass
the data to Neutron, however.

Change-Id: Iadf5b803bb5a5465fc2adcb94fa3fd2a756340be
This commit is contained in:
dekehn
2013-12-10 17:11:53 -07:00
parent 62b04a8a2e
commit 5c3bb2f752
3 changed files with 37 additions and 3 deletions

View File

@ -711,4 +711,7 @@
# (string value)
#instance_master_path=/var/lib/ironic/master_images
# Neutron bootfile DHCP parameter. (string value)
#pxe_bootfile_name=pxelinux.0

View File

@ -59,8 +59,6 @@ pxe_opts = [
cfg.IntOpt('pxe_deploy_timeout',
help='Timeout for PXE deployments. Default: 0 (unlimited)',
default=0),
# TODO(sjing): when adding neutron-port configuration, use this option
# instead of assuming tftp server is on $my_ip
cfg.StrOpt('tftp_server',
default='$my_ip',
help='IP address of Ironic compute node\'s tftp server'),
@ -75,7 +73,12 @@ pxe_opts = [
help='Directory where master tftp images are stored on disk'),
cfg.StrOpt('instance_master_path',
default='/var/lib/ironic/master_images',
help='Directory where master tftp images are stored on disk')
help='Directory where master tftp images are stored on disk'),
# NOTE(dekehn): Additional boot files options may be created in the event
# other architectures require different boot files.
cfg.StrOpt('pxe_bootfile_name',
default='pxelinux.0',
help='Neutron bootfile DHCP parameter.'),
]
LOG = logging.getLogger(__name__)
@ -205,6 +208,11 @@ def _get_pxe_config_file_path(instance_uuid):
return os.path.join(CONF.pxe.tftp_root, instance_uuid, 'config')
def _get_pxe_bootfile_name():
"""Returns the pxe_bootfile_name option."""
return CONF.pxe.pxe_bootfile_name
def _get_image_dir_path(d_info):
"""Generate the dir for an instances disk."""
return os.path.join(CONF.pxe.images_path, d_info['instance_name'])
@ -438,6 +446,17 @@ def _destroy_token_file(node):
utils.unlink_without_raise(token_file_path)
def _dhcp_options_for_instance():
"""Retrives the DHCP PXE boot options."""
return [{'opt_name': 'bootfile-name',
'opt_value': _get_pxe_bootfile_name()},
{'opt_name': 'server-ip-address',
'opt_value': CONF.pxe.tftp_server},
{'opt_name': 'tftp-server',
'opt_value': CONF.pxe.tftp_server}
]
def _create_pxe_config(task, node, pxe_info):
"""Generate pxe configuration file and link mac ports to it for
tftp booting.

View File

@ -280,6 +280,18 @@ class PXEPrivateMethodsTestCase(base.TestCase):
db_key = db_node['driver_info'].get('pxe_deploy_key')
self.assertEqual(db_key, fake_key)
def test__dhcp_options_for_instance(self):
CONF.set_default('pxe_bootfile_name', 'test_pxe_bootfile', group='pxe')
CONF.set_default('tftp_server', '192.0.2.1', group='pxe')
expected_info = [{'opt_name': 'bootfile-name',
'opt_value': 'test_pxe_bootfile'},
{'opt_name': 'server-ip-address',
'opt_value': '192.0.2.1'},
{'opt_name': 'tftp-server',
'opt_value': '192.0.2.1'}
]
self.assertEqual(expected_info, pxe._dhcp_options_for_instance())
def test__get_pxe_config_file_path(self):
self.assertEqual('/tftpboot/instance_uuid_123/config',
pxe._get_pxe_config_file_path('instance_uuid_123'))