From bca42f14a057e36c5e23eed903697f4f3cd186c4 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 24 Apr 2015 17:09:32 +0000 Subject: pxeboot: add support for PXEBOOT_TARGET_INTERFACE This is to set the name of the interface of the target to pxeboot from. Some targets with more than one interface try to get the rootfs from a different interface than the interface from where the pxeboot server is reachable. Using this variable, the kernel arguments will be filled to include the device. Change-Id: I022bf6b17a66d63f7f9b8830e72ca4020158a80a --- pxeboot.write | 29 +++++++++++++++++++++-------- pxeboot.write.help | 12 ++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) mode change 100755 => 100644 pxeboot.write diff --git a/pxeboot.write b/pxeboot.write old mode 100755 new mode 100644 index c8d8bc4e..be884366 --- a/pxeboot.write +++ b/pxeboot.write @@ -407,29 +407,39 @@ class PXEBoot(morphlib.writeexts.WriteExtension): @staticmethod def _write_pxe_config(fh, kernel_tftp_url, rootfs_nfs_url, + host_ip=None, device=None, target_ip=None, fdt_subpath=None, extra_args=''): + + if device is None: + ip_cfg = "ip=dhcp" + else: + ip_cfg = "ip=:::::{device}:dhcp::".format( + device=device, host_ip=host_ip, target_ip=target_ip) + fh.write(textwrap.dedent('''\ DEFAULT default LABEL default LINUX {kernel_url} - APPEND root=/dev/nfs ip=dhcp nfsroot={rootfs_nfs_url} {extra_args} - ''').format(kernel_url=kernel_tftp_url, + APPEND root=/dev/nfs {ip_cfg} nfsroot={rootfs_nfs_url} {extra_args} + ''').format(kernel_url=kernel_tftp_url, ip_cfg=ip_cfg, rootfs_nfs_url=rootfs_nfs_url, extra_args=extra_args)) if fdt_subpath is not None: fh.write("FDT {}\n".format(fdt_subpath)) fh.flush() @contextlib.contextmanager - def local_pxeboot_config(self, tftproot, macaddr, ip, tftp_port, - nfsroot_dir): - kernel_tftp_url = 'tftp://{}:{}/kernel'.format(ip, tftp_port) - rootfs_nfs_url = '{}:{}'.format(ip, nfsroot_dir) + def local_pxeboot_config(self, tftproot, macaddr, host_ip, tftp_port, + nfsroot_dir, device=None, target_ip=None): + kernel_tftp_url = 'tftp://{}:{}/kernel'.format(host_ip, tftp_port) + rootfs_nfs_url = '{}:{}'.format(host_ip, nfsroot_dir) pxe_cfg_filename = _normalise_macaddr(macaddr) pxe_cfg_path = os.path.join(tftproot, 'pxelinux.cfg', pxe_cfg_filename) os.makedirs(os.path.dirname(pxe_cfg_path)) with open(pxe_cfg_path, 'w') as f: self._write_pxe_config(fh=f, kernel_tftp_url=kernel_tftp_url, rootfs_nfs_url=rootfs_nfs_url, + host_ip=host_ip, device=device, + target_ip=target_ip, extra_args=os.environ.get('KERNEL_ARGS','')) pxe_cfg_link_path = os.path.join (tftproot, @@ -631,6 +641,7 @@ class PXEBoot(morphlib.writeexts.WriteExtension): def process_args(self, (temp_root, macaddr)): interface = os.environ.get('PXEBOOT_DEPLOYER_INTERFACE', None) + target_interface = os.environ.get('PXEBOOT_TARGET_INTERFACE', None) vlan = os.environ.get('PXEBOOT_VLAN') if vlan is not None: vlan = int(vlan) mode = os.environ.get('PXEBOOT_MODE') @@ -656,7 +667,8 @@ class PXEBoot(morphlib.writeexts.WriteExtension): self.local_kernel(rootfs=temp_root, tftproot=tftproot), \ self.local_nfsroot(rootfs=temp_root, target_ip=target_ip), \ self.local_pxeboot_config(tftproot=tftproot, macaddr=macaddr, - ip=host_ip, tftp_port=tftp_port, + device=target_interface, target_ip=target_ip, + host_ip=host_ip, tftp_port=tftp_port, nfsroot_dir=temp_root), \ self.dhcp_server(interface=interface, host_ip=host_ip, target_ip=target_ip, @@ -676,7 +688,8 @@ class PXEBoot(morphlib.writeexts.WriteExtension): self.local_kernel(rootfs=temp_root, tftproot=tftproot), \ self.local_nfsroot(rootfs=temp_root, target_ip=target_ip), \ self.local_pxeboot_config(tftproot=tftproot, macaddr=macaddr, - ip=host_ip, tftp_port=tftp_port, + device=target_interface, target_ip=target_ip, + host_ip=host_ip, tftp_port=tftp_port, nfsroot_dir=temp_root), \ self.dhcp_server(interface=interface, host_ip=host_ip, target_ip=target_ip, diff --git a/pxeboot.write.help b/pxeboot.write.help index 3aefe75e..7cb78bce 100644 --- a/pxeboot.write.help +++ b/pxeboot.write.help @@ -152,3 +152,15 @@ help: > device tree blob if specified, will not be removed after the deployment finishes. This variable is only meanful on the `existing-server` mode. + + + ## PXEBOOT_TARGET_INTERFACE + + Name of the interface of the target to pxeboot from. Some targets + with more than one interface try to get the rootfs from a different + interface than the interface from where the pxeboot server is + reachable. Using this variable, the kernel arguments will be filled + to include the device. + + Note that the name of this interface is the kernel's default name, + usually called ethX, and is non-determinisic. -- cgit v1.2.1