Difference between revisions of "Ironic-boot-kernel-parameters"
(Created page with "#!/usr/bin/env python import os grub_file = '/etc/default/grub' kernel_parameters = ['quiet', 'splash'] grub_cmd = 'GRUB_CMDLINE_LINUX' old_grub_file = grub_file+'~' os.rena...") |
Julia Kreger (talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
− | #!/usr/bin/env python | + | '''Note:''' This content is likely out of date. Ironic has supported local boot of Bare metal nodes for quite some time, and this page was likely posted when that work was still under development. For the latest ironic documentation, see https://docs.openstack.org/ironic/latest |
− | import os | + | |
+ | This is a reference script to passing kernel paramters to ironic localboot instance using configdrive. | ||
+ | This only works with ubuntu image, so users should modify this script by their own use case: | ||
+ | |||
+ | #!/usr/bin/env python | ||
+ | import os | ||
− | grub_file = '/etc/default/grub' | + | # Default grub2 config file in Ubuntu |
− | kernel_parameters = ['quiet', 'splash'] | + | grub_file = '/etc/default/grub' |
− | grub_cmd = 'GRUB_CMDLINE_LINUX' | + | # Add parameters here to pass to instance. |
− | old_grub_file = grub_file+'~' | + | kernel_parameters = ['quiet', 'splash'] |
− | os.rename(grub_file, old_grub_file) | + | grub_cmd = 'GRUB_CMDLINE_LINUX' |
− | cmdline_existed = False | + | old_grub_file = grub_file+'~' |
− | with open(grub_file, 'w') as writer, \ | + | os.rename(grub_file, old_grub_file) |
− | + | cmdline_existed = False | |
− | + | with open(grub_file, 'w') as writer, \ | |
− | + | open(old_grub_file, 'r') as reader: | |
− | + | for line in reader: | |
− | + | key = line.split('=')[0] | |
− | + | if key == grub_cmd: | |
− | + | #If there is already some value: | |
− | + | if line.strip()[-1] == '"': | |
− | + | line = line.strip()[:-1] + ' ' + ' '.join(kernel_parameters) + '"' | |
− | + | cmdline_existed = True | |
− | + | writer.write(line) | |
− | + | if not cmdline_existed: | |
+ | line = grub_cmd + '=' + '"' + ' '.join(kernel_parameters) + '"' | ||
+ | writer.write(line) | ||
− | os.remove(old_grub_file) | + | os.remove(old_grub_file) |
− | os.system('update-grub') | + | os.system('update-grub') |
− | os.system('reboot') | + | os.system('reboot') |
Latest revision as of 17:21, 3 May 2021
Note: This content is likely out of date. Ironic has supported local boot of Bare metal nodes for quite some time, and this page was likely posted when that work was still under development. For the latest ironic documentation, see https://docs.openstack.org/ironic/latest
This is a reference script to passing kernel paramters to ironic localboot instance using configdrive. This only works with ubuntu image, so users should modify this script by their own use case:
#!/usr/bin/env python import os # Default grub2 config file in Ubuntu grub_file = '/etc/default/grub' # Add parameters here to pass to instance. kernel_parameters = ['quiet', 'splash'] grub_cmd = 'GRUB_CMDLINE_LINUX' old_grub_file = grub_file+'~' os.rename(grub_file, old_grub_file) cmdline_existed = False with open(grub_file, 'w') as writer, \ open(old_grub_file, 'r') as reader: for line in reader: key = line.split('=')[0] if key == grub_cmd: #If there is already some value: if line.strip()[-1] == '"': line = line.strip()[:-1] + ' ' + ' '.join(kernel_parameters) + '"' cmdline_existed = True writer.write(line) if not cmdline_existed: line = grub_cmd + '=' + '"' + ' '.join(kernel_parameters) + '"' writer.write(line) os.remove(old_grub_file) os.system('update-grub') os.system('reboot')