From a6d7d3a8537215d0315a8dad66565ba26294b8b8 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Tue, 24 Feb 2015 14:58:57 +0000 Subject: pxeboot: support u-boot pxe configuration file lookup u-boot will look for a pxelinux configuration file on the TFTP server whose name corresponds to the normalized MAC address of the NIC prefixed with '01-' (Leading 01 means Ethernet). This support is only being added to remote deployments for now. --- pxeboot.write | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/pxeboot.write b/pxeboot.write index c2148081..3fdda5f2 100755 --- a/pxeboot.write +++ b/pxeboot.write @@ -330,6 +330,16 @@ class PXEBoot(morphlib.writeexts.WriteExtension): finally: cliapp.ssh_runcmd(hostname, ['rm', dst]) + @contextlib.contextmanager + def _remote_symlink(self, hostname, src, dst): + cliapp.ssh_runcmd(hostname, + ['ln', '-s', '-f', src, dst], + stdin=None, stdout=None, stderr=None) + try: + yield + finally: + cliapp.ssh_runcmd(hostname, ['rm', '-f', dst]) + @contextlib.contextmanager def remote_kernel(self, rootfs, tftp_url, macaddr): for name in ('vmlinuz', 'zImage', 'uImage'): @@ -408,14 +418,21 @@ class PXEBoot(morphlib.writeexts.WriteExtension): kernel_tftp_url = '{}/{}'.format(kernel_tftproot, kernel_subpath) pxe_cfg_filename = _normalise_macaddr(macaddr) url = urlparse.urlsplit(tftproot) - inst_cfg_path = os.path.join(url.path, 'pxelinux.cfg', - pxe_cfg_filename) + inst_cfg_path = os.path.join(url.path, 'pxelinux.cfg') with tempfile.NamedTemporaryFile() as f: - self._write_pxe_config(fh=f, kernel_tftp_url=kernel_tftp_url, - rootfs_nfs_url=rootfs_nfs_url, - extra_args=os.environ.get('KERNEL_ARGS','')) - with self._remote_copy(hostname=url.hostname, src=f.name, - dst=inst_cfg_path): + self._write_pxe_config( + fh=f, kernel_tftp_url=kernel_tftp_url, + rootfs_nfs_url=rootfs_nfs_url, + extra_args=os.environ.get('KERNEL_ARGS','')) + with self._remote_copy( + hostname=url.hostname, src=f.name, + dst=os.path.join(inst_cfg_path, + pxe_cfg_filename)), \ + self._remote_symlink( + hostname=url.hostname, + src=pxe_cfg_filename, + dst=os.path.join(inst_cfg_path, + '01-' + pxe_cfg_filename)): yield @contextlib.contextmanager -- cgit v1.2.1