Skip to content

Instantly share code, notes, and snippets.

@tchellomello
Last active November 17, 2016 18:36
Show Gist options
  • Select an option

  • Save tchellomello/921794fdc9c8a8f4b920c3a8fc73a7a5 to your computer and use it in GitHub Desktop.

Select an option

Save tchellomello/921794fdc9c8a8f4b920c3a8fc73a7a5 to your computer and use it in GitHub Desktop.
IBM Power hook for Satellite 6
#!/usr/bin/env python
import os
import re
TFTP_PXELINUX_ROOT_CFG="/var/lib/tftpboot/pxelinux.cfg"
TFTP_GRUB_ROOT_CFG="/var/lib/tftpboot/boot/grub2/powerpc-ieee1275"
TFTP_GRUB_CFG_PREFIX="grub.cfg-"
GRUB2_TEMPLATE="""
set default=0
set timeout=5
menuentry 'Install Red Hat Enterprise Linux for Power' {
linux KERNEL_HERE BOOT_PARAM
initrd INITRD_HERE
}
"""
def grab_all_pxelinux_configs(directory=TFTP_PXELINUX_ROOT_CFG):
tftp_files = []
mac_format = re.compile(ur'((?:(\d{1,2}|[a-fA-F]{1,2}){2})(?::|-*)){6}')
for f in os.listdir(directory):
if re.findall(mac_format, f):
tftp_files.append(f)
return tftp_files
def file_exists(cfg_file):
if os.path.isfile(cfg_file):
return True
else:
return False
def process_pxelinux_cfg(tftp_files):
content = None
for f in tftp_files:
fpath = os.path.join(TFTP_PXELINUX_ROOT_CFG, f)
if file_exists(fpath):
with open(fpath, mode='ro') as fd:
content = fd.readlines()
if content:
for line in content:
if "KERNEL" in line:
kernel_arg = line.split()[-1]
grub_aux = GRUB2_TEMPLATE.replace("KERNEL_HERE", kernel_arg)
if "initrd" in line:
initrd_arg = line.split()[1].split('=')[-1]
boot_arg = line.split()[-3:]
grub_aux = grub_aux.replace("INITRD_HERE", initrd_arg)
grub_aux = grub_aux.replace("BOOT_PARAM", ' '.join(boot_arg))
#save file
filename = os.path.join(TFTP_GRUB_ROOT_CFG, str(TFTP_GRUB_CFG_PREFIX + f))
with open(filename, 'w') as grub_cfg:
grub_cfg.write(grub_aux)
print "PXELinux converted to GRUB2 format at %s" % (filename)
### script
pxefiles = grab_all_pxelinux_configs()
process_pxelinux_cfg(pxefiles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment