Exemple #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)
Exemple #2
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)
Exemple #4
0
def add_gnome_support(mounted_path):
    """
    RHEL only at this point.
    TODO: Add ubuntu, then add deterine_distro code
    """
    prepare_chroot_env(mounted_path)
    run_command([
        "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "yum groupinstall"
        " -y \"X Window System\" \"GNOME Desktop Environment\""])
    #Selinux was enabled in the process. lets fix that:
    selinux_conf = os.path.join(mounted_path, 'etc/sysconfig/selinux')
    sed_replace("SELINUX=enforcing", "SELINUX=disabled", selinux_conf)
    remove_chroot_env(mounted_path)

    #Make it the default on boot
    replace_line_file_list = [
         (":[0-6]:initdefault",":5:initdefault",
             "etc/inittab"),
    ]
    replace_line_in_files(replace_line_file_list, mounted_path)
Exemple #5
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)
Exemple #6
0
def add_gnome_support(mounted_path):
    """
    RHEL only at this point.
    TODO: Add ubuntu, then add deterine_distro code
    """
    prepare_chroot_env(mounted_path)
    run_command([
        "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", "yum groupinstall"
        " -y \"X Window System\" \"GNOME Desktop Environment\""])
    #Selinux was enabled in the process. lets fix that:
    selinux_conf = os.path.join(mounted_path, 'etc/sysconfig/selinux')
    sed_replace("SELINUX=enforcing", "SELINUX=disabled", selinux_conf)
    remove_chroot_env(mounted_path)

    #Make it the default on boot
    replace_line_file_list = [
         (":[0-6]:initdefault",":5:initdefault",
             "etc/inittab"),
    ]
    replace_line_in_files(replace_line_file_list, mounted_path)