def rhel_mount(cls, image_path, mounted_path): """ Migrate RHEL systems from XEN to KVM Returns: ("/path/to/img", "/path/to/kvm_kernel", "/path/to/kvm_ramdisk") """ #This list will append a single line to an already-existing file append_line_file_list = [ #("line to add", "file_to_append") ("S0:2345:respawn:/sbin/agetty ttyS0 115200", "etc/inittab"), ("S1:2345:respawn:/sbin/agetty ttyS1 115200", "etc/inittab"), ] #TODO: This etc/fstab line may need some more customization #This list will prepend a single line to an already-existing file prepend_line_list = [ #("line to prepend", "file_to_prepend") ("LABEL=root\t\t/\t\t\text3\tdefaults,errors=remount-ro 0 0", "etc/fstab"), ] #This list removes lines matching the pattern from an existing file remove_line_file_list = [ #("pattern_match", "file_to_test") ("alias scsi", "etc/modprobe.conf"), ("atmo_boot", "etc/rc.local") ] # This list replaces lines matching a pattern from an existing file replace_line_file_list = [ #(pattern_match, pattern_replace, file_to_match) ("^\/dev\/sda", "\#\/dev\/sda", "etc/fstab"), ("^xvc0", "\#xvc0", "etc/inittab"), ("xenblk", "ata_piix", "etc/modprobe.conf"), ("xennet", "8139cp", "etc/modprobe.conf") ] #This list removes ALL lines between <pattern_1> and <pattern_2> from an # existing file multiline_delete_files = [ #("delete_from","delete_to","file_to_match") ("depmod -a", "\/usr\/bin\/ruby \/usr\/sbin\/atmo_boot", "etc/rc.local"), ("depmod -a", "\/usr\/bin\/ruby \/usr\/sbin\/atmo_boot", "etc/rc.d/rc.local") ] append_line_in_files(append_line_file_list, mounted_path) prepend_line_in_files(prepend_line_list, mounted_path) remove_line_in_files(remove_line_file_list, mounted_path) replace_line_in_files(replace_line_file_list, mounted_path) remove_multiline_in_files(multiline_delete_files, mounted_path)
def rhel_mount(cls, image_path, mounted_path): """ Migrate RHEL systems from XEN to KVM Returns: ("/path/to/img", "/path/to/kvm_kernel", "/path/to/kvm_ramdisk") """ #This list will append a single line to an already-existing file append_line_file_list = [ #("line to add", "file_to_append") ("S0:2345:respawn:/sbin/agetty ttyS0 115200", "etc/inittab"), ("S1:2345:respawn:/sbin/agetty ttyS1 115200", "etc/inittab"), ] #TODO: This etc/fstab line may need some more customization #This list will prepend a single line to an already-existing file prepend_line_list = [ #("line to prepend", "file_to_prepend") ("LABEL=root\t\t/\t\t\text3\tdefaults,errors=remount-ro 0 0", "etc/fstab"), ] #This list removes lines matching the pattern from an existing file remove_line_file_list = [#("pattern_match", "file_to_test") ("alias scsi", "etc/modprobe.conf"), ("atmo_boot", "etc/rc.local")] # This list replaces lines matching a pattern from an existing file replace_line_file_list = [#(pattern_match, pattern_replace, file_to_match) ("^\/dev\/sda", "\#\/dev\/sda", "etc/fstab"), ("^xvc0", "\#xvc0", "etc/inittab"), ("xenblk", "ata_piix", "etc/modprobe.conf"), ("xennet", "8139cp", "etc/modprobe.conf")] #This list removes ALL lines between <pattern_1> and <pattern_2> from an # existing file multiline_delete_files = [ #("delete_from","delete_to","file_to_match") ("depmod -a","\/usr\/bin\/ruby \/usr\/sbin\/atmo_boot", "etc/rc.local"), ("depmod -a","\/usr\/bin\/ruby \/usr\/sbin\/atmo_boot", "etc/rc.d/rc.local") ] append_line_in_files(append_line_file_list, mounted_path) prepend_line_in_files(prepend_line_list, mounted_path) remove_line_in_files(remove_line_file_list, mounted_path) replace_line_in_files(replace_line_file_list, mounted_path) remove_multiline_in_files(multiline_delete_files, mounted_path)
def add_eth0_module(mounted_path): prepend_line_list = [ ("alias eth0 e1000", "etc/modprobe.d/virtualbox"), ] prepend_line_in_files(prepend_line_list, mounted_path)