Пример #1
0
def _perform_cleaning(mounted_path, rm_files=None,
                      remove_line_files=None, overwrite_list=None,
                      replace_line_files=None, multiline_delete_files=None,
                      dry_run=False):
    """
    Runs the commands to perform all cleaning operations.
    For more information see the specific function
    """
    apt_uninstall(mounted_path, ['avahi-daemon'])
    remove_files(rm_files, mounted_path, dry_run)
    overwrite_files(overwrite_list, mounted_path, dry_run)
    remove_line_in_files(remove_line_files, mounted_path, dry_run)
    replace_line_in_files(replace_line_files, mounted_path, dry_run)
    remove_multiline_in_files(multiline_delete_files, mounted_path, dry_run)
Пример #2
0
    def debian_mount(self, image_path, mounted_path):
        """
        Convert the disk image at <image_path>, mounted at <mounted_path>,
        from XEN to KVM
        """
        #This list will add a single line to an already-existing file
        append_line_file_list = [
            #("line to add", "file_to_append")
            ("exec /sbin/getty -L 38400 ttyS0 vt102", "etc/init/getty.conf"),
            ("exec /sbin/getty -L 38400 ttyS1 vt102", "etc/init/getty.conf"),
        ]

        #If etc/init/getty.conf doesn't exist, use this template to create it
        kvm_getty_script = """# getty - ttyS*
# This service maintains a getty on ttyS0/S1
# from the point the system is started until
# it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 38400 ttyS0 vt102
exec /sbin/getty -L 38400 ttyS1 vt102
"""

        #This list removes lines matching the pattern from an existing file
        remove_line_file_list = [
            #("pattern_match", "file_to_test")
            ("atmo_boot", "etc/rc.local"),
            # Save /dev/sda1, /dev/vda, /dev/xvda
            # Delete all other partitions in etc/fstab
            ("sda[2-9]", "etc/fstab"),
            ("sda1[0-9]", "etc/fstab"),
            ("vd[b-z]", "etc/fstab"),
        ]

        # This list contains all files that should be deleted
        remove_file_list = ['etc/init/hvc0.conf']

        remove_line_in_files(remove_line_file_list, mounted_path)
        remove_files(remove_file_list, mounted_path)
        if not create_file("etc/init/getty.conf", mounted_path,
                           kvm_getty_script):
            #Didn't need to create the file, but we still need to append our
            # new lines
            append_line_in_files(append_line_file_list, mounted_path)
        return
    def debian_mount(self, image_path, mounted_path):
        """
        Convert the disk image at <image_path>, mounted at <mounted_path>,
        from XEN to KVM
        """
        #This list will add a single line to an already-existing file
        append_line_file_list = [
                #("line to add", "file_to_append")
                ("exec /sbin/getty -L 38400 ttyS0 vt102", "etc/init/getty.conf"),
                ("exec /sbin/getty -L 38400 ttyS1 vt102", "etc/init/getty.conf"),
        ]
    
        #If etc/init/getty.conf doesn't exist, use this template to create it
        kvm_getty_script = """# getty - ttyS*
# This service maintains a getty on ttyS0/S1
# from the point the system is started until
# it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 38400 ttyS0 vt102
exec /sbin/getty -L 38400 ttyS1 vt102
"""
    
        #This list removes lines matching the pattern from an existing file
        remove_line_file_list = [
                #("pattern_match", "file_to_test")
                ("atmo_boot",  "etc/rc.local"),
                # Save /dev/sda1, /dev/vda, /dev/xvda
                # Delete all other partitions in etc/fstab
                ("sda[2-9]", "etc/fstab"),
                ("sda1[0-9]", "etc/fstab"),
                ("vd[b-z]",  "etc/fstab"),
                ]
    
        # This list contains all files that should be deleted
        remove_file_list = [
                'etc/init/hvc0.conf']
    
        remove_line_in_files(remove_line_file_list, mounted_path)
        remove_files(remove_file_list, mounted_path)
        if not create_file("etc/init/getty.conf", mounted_path, kvm_getty_script):
            #Didn't need to create the file, but we still need to append our
            # new lines
            append_line_in_files(append_line_file_list, mounted_path)
        return
Пример #4
0
    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)
Пример #6
0
def _perform_cleaning(mounted_path,
                      rm_files=None,
                      remove_line_files=None,
                      overwrite_list=None,
                      replace_line_files=None,
                      multiline_delete_files=None,
                      append_line_files=None,
                      execute_lines=None,
                      dry_run=False):
    """
    Runs the commands to perform all cleaning operations.
    For more information see the specific function
    """
    remove_files(rm_files, mounted_path, dry_run)
    overwrite_files(overwrite_list, mounted_path, dry_run)
    remove_line_in_files(remove_line_files, mounted_path, dry_run)
    replace_line_in_files(replace_line_files, mounted_path, dry_run)
    remove_multiline_in_files(multiline_delete_files, mounted_path, dry_run)
    append_line_in_files(append_line_files, mounted_path, dry_run)
    execute_chroot_commands(execute_lines, mounted_path, dry_run)