Example #1
0
def remove_sensu(mounted_path):
    try:
        prepare_chroot_env(mounted_path)
        run_command(["/usr/sbin/chroot", mounted_path, 'yum',
                     'remove', '-qy', 'sensu'])
    finally:
        remove_chroot_env(mounted_path)
Example #2
0
def remove_sensu(mounted_path):
    try:
        prepare_chroot_env(mounted_path)
        run_command(["/usr/sbin/chroot", mounted_path, 'yum',
                     'remove', '-qy', 'sensu'])
    finally:
        remove_chroot_env(mounted_path)
Example #3
0
def reset_root_password(mounted_path, new_password='******'):
    try:
        prepare_chroot_env(mounted_path)
        run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c",
                     "echo %s | passwd root --stdin" % new_password])
    finally:
        remove_chroot_env(mounted_path)
def reset_root_password(mounted_path, new_password='******'):
    try:
        prepare_chroot_env(mounted_path)
        run_command(["/usr/sbin/chroot", mounted_path, "/bin/bash", "-c",
                     "echo %s | passwd root --stdin" % new_password])
    finally:
        remove_chroot_env(mounted_path)
Example #5
0
def remove_vnc(mounted_path):
    try:
        prepare_chroot_env(mounted_path)
        run_command(["/usr/sbin/chroot", mounted_path, 'yum',
            'remove', '-qy', 'realvnc-vnc-server'])
        #remove rpmsave.. to get rid of vnc for good.
        #["/usr/sbin/chroot", mounted_path, 'find', '/',
        #'-type', 'f', '-name', '*.rpmsave', '-exec', 'rm', '-f',
        #'{}', ';']
    finally:
        remove_chroot_env(mounted_path)
Example #6
0
def apt_install(mounted_path, install_list):
    distro = check_distro(mounted_path)
    try:
        prepare_chroot_env(mounted_path)
        for install_item in install_list:
            run_command([
                "/usr/sbin/chroot", mounted_path, 'apt-get', '-qy', 'install',
                install_item
            ])
    finally:
        remove_chroot_env(mounted_path)
Example #7
0
def remove_vnc(mounted_path):
    try:
        prepare_chroot_env(mounted_path)
        run_command(["/usr/sbin/chroot", mounted_path, 'yum',
            'remove', '-qy', 'realvnc-vnc-server'])
        #remove rpmsave.. to get rid of vnc for good.
        #["/usr/sbin/chroot", mounted_path, 'find', '/',
        #'-type', 'f', '-name', '*.rpmsave', '-exec', 'rm', '-f',
        #'{}', ';']
    finally:
        remove_chroot_env(mounted_path)
Example #8
0
def apt_uninstall(mounted_path, uninstall_list):
    distro = check_distro(mounted_path)
    if 'ubuntu' not in distro.lower():
        return
    try:
        prepare_chroot_env(mounted_path)
        for uninstall_item in uninstall_list:
            run_command(["/usr/sbin/chroot", mounted_path,
                         'apt-get', '-qy', 'purge', uninstall_item])
    finally:
        remove_chroot_env(mounted_path)
Example #9
0
def apt_uninstall(mounted_path, uninstall_list):
    distro = check_distro(mounted_path)
    if 'ubuntu' not in distro.lower():
        return
    try:
        prepare_chroot_env(mounted_path)
        for uninstall_item in uninstall_list:
            run_command([
                "/usr/sbin/chroot", mounted_path, 'apt-get', '-qy', 'purge',
                uninstall_item
            ])
    finally:
        remove_chroot_env(mounted_path)
Example #10
0
def yum_uninstall(mounted_path, uninstall_list):
    distro = check_distro(mounted_path)
    if 'centos' not in distro.lower():
        return
    try:
        prepare_chroot_env(mounted_path)
        for uninstall_item in uninstall_list:
            run_command([
                "/usr/sbin/chroot", mounted_path, 'yum', '-qy', 'remove',
                uninstall_item
            ])
    finally:
        remove_chroot_env(mounted_path)
Example #11
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)
Example #12
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)
Example #13
0
    def convert(cls, image_path, upload_dir):
        (kernel_dir, ramdisk_dir,
         mount_point) = build_imaging_dirs(upload_dir, full_image=True)

        apply_label(image_path, label='root')  # TODO: Is this necessary?

        try:
            out, err = mount_image(image_path, mount_point)
            if err:
                raise Exception("Encountered errors mounting image:%s" % err)

            #Our mount_point is in use, the image is mounted at this path
            mounted_path = mount_point
            distro = check_distro(mounted_path)

            #Hooks for debian/rhel specific cleaning commands
            if distro == 'ubuntu':
                cls.debian_mount(image_path, mount_point)
            elif distro == 'centos':
                cls.rhel_mount(image_path, mount_point)

            try:
                prepare_chroot_env(mounted_path)
                #Hooks for debian/rhel specific chroot commands
                if distro == 'ubuntu':
                    cls.debian_chroot(image_path, mount_point)
                elif distro == 'centos':
                    cls.rhel_chroot(image_path, mount_point)
            finally:
                remove_chroot_env(mounted_path)

            (kernel_path,
             ramdisk_path) = cls.get_kernel_ramdisk(mount_point, kernel_dir,
                                                    ramdisk_dir)

            #Use the image, kernel, and ramdisk paths
            #to initialize any driver that implements 'upload_full_image'
            return (image_path, kernel_path, ramdisk_path)
        finally:
            run_command(["umount", mount_point])
    def convert(cls, image_path, upload_dir):
        (kernel_dir, ramdisk_dir, mount_point) = build_imaging_dirs(upload_dir,
                full_image=True)

        apply_label(image_path, label='root')  # TODO: Is this necessary?

        try:
            out, err = mount_image(image_path, mount_point)
            if err:
                raise Exception("Encountered errors mounting image:%s" % err)

            #Our mount_point is in use, the image is mounted at this path
            mounted_path = mount_point
            distro = check_distro(mounted_path)

            #Hooks for debian/rhel specific cleaning commands
            if distro == 'ubuntu':
                 cls.debian_mount(image_path, mount_point)
            elif distro == 'centos':
                 cls.rhel_mount(image_path, mount_point)

            try:
                prepare_chroot_env(mounted_path)
                #Hooks for debian/rhel specific chroot commands
                if distro == 'ubuntu':
                     cls.debian_chroot(image_path, mount_point)
                elif distro == 'centos':
                     cls.rhel_chroot(image_path, mount_point)
            finally:
                remove_chroot_env(mounted_path)

            (kernel_path, ramdisk_path) = cls.get_kernel_ramdisk(mount_point,
                                                    kernel_dir, ramdisk_dir)
    
            #Use the image, kernel, and ramdisk paths
            #to initialize any driver that implements 'upload_full_image'
            return (image_path, kernel_path, ramdisk_path)
        finally:
            run_command(["umount", mount_point])
Example #15
0
def file_hook_cleaning(mounted_path, **kwargs):
    """
    Look for a 'file_hook' on the actual filesystem (Mounted at
    mounted_path)

    If it exists, prepare a chroot and execute the file
    """
    #File hooks inside the local image
    clean_filename = kwargs.get('file_hook', "/etc/chromogenic/clean")
    #Ignore the lead / when doing path.join
    not_root_filename = clean_filename[1:]
    mounted_clean_path = os.path.join(mounted_path, not_root_filename)
    if not os.path.exists(mounted_clean_path):
        return False
    try:
        prepare_chroot_env(mounted_path)
        #Run this command in a prepared chroot
        run_command([
            "/usr/sbin/chroot", mounted_path, "/bin/bash", "-c", clean_filename
        ])
    except Exception, e:
        logger.exception(e)
        return False
Example #16
0
    def file_hook_cleaning(self, mounted_path, **kwargs):
        """
        Look for a 'file_hook' on the actual filesystem (Mounted at
        mounted_path)

        If it exists, prepare a chroot and execute the file
        """
        #File hooks inside the local image
        clean_filename = kwargs.get('file_hook',"/etc/chromogenic/clean")
        #Ignore the lead / when doing path.join
        not_root_filename = clean_filename[1:]
        mounted_clean_path = os.path.join(mounted_path,not_root_filename)
        if not os.path.exists(mounted_clean_path):
            return False
        try:
            prepare_chroot_env(mounted_path)
            #Run this command in a prepared chroot
            run_command(
                ["/usr/sbin/chroot", mounted_path,
                 "/bin/bash", "-c", clean_filename])
        except Exception, e:
            logger.exception(e)
            return False