Ejemplo n.º 1
0
def add_grub(mounted_path, image_path):
    """
    Defines the order of sub-functions needed to install
    grub onto a VM without the use of a LiveCD/Floppy/Existing Grub install
    """
    distro = check_distro(mounted_path)
    _get_stage_files(mounted_path, distro)
    _rewrite_grub_conf(mounted_path, distro)
    _install_grub(image_path)
Ejemplo n.º 2
0
def add_grub(mounted_path, image_path):
    """
    Defines the order of sub-functions needed to install
    grub onto a VM without the use of a LiveCD/Floppy/Existing Grub install
    """
    distro = check_distro(mounted_path)
    _get_stage_files(mounted_path, distro)
    _rewrite_grub_conf(mounted_path, distro)
    _install_grub(image_path)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def remove_user_data(mounted_path, author=None, dry_run=False):
    """
    Remove user data from an image that has already been mounted
    NOTE: This will also include removing *CLOUD* user data.
    """
    if not check_mounted(mounted_path):
        raise Exception("Expected a mounted path at %s" % mounted_path)
    distro = check_distro(mounted_path)
    if 'ubuntu' in distro:
        cloud_user = '******'
        remove_user_cmd = '/usr/sbin/userdel'
    elif 'centos' in distro:
        cloud_user = '******'
        remove_user_cmd = '/usr/sbin/userdel'
    else:
        cloud_user = ''
        remove_user_cmd = ''
        raise Exception(
            "Encountered unknown distro %s -- Cannot guarantee removal of the cloud-user"
            % distro)

    remove_files = [
        'home/*',
    ]
    overwrite_files = []
    remove_line_files = []
    replace_line_files = [
        #('replace_pattern','replace_with','in_file'),
        ("users:x:100:.*", "users:x:100:", "etc/group"),
        #TODO: Check this should not be 'AllowGroups users core-services root'
        ("AllowGroups users root.*", "", "etc/ssh/sshd_config"),
    ]
    execute_lines = []
    if remove_user_cmd and cloud_user:
        execute_lines.append([remove_user_cmd, '-r', cloud_user])
    if remove_user_cmd and author:
        execute_lines.append([remove_user_cmd, '-r', author])

    multiline_delete_files = [
        #('delete_from', 'delete_to', 'replace_where')
    ]
    _perform_cleaning(mounted_path,
                      rm_files=remove_files,
                      remove_line_files=remove_line_files,
                      overwrite_list=overwrite_files,
                      replace_line_files=replace_line_files,
                      multiline_delete_files=multiline_delete_files,
                      execute_lines=execute_lines,
                      dry_run=dry_run)
Ejemplo n.º 7
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])
Ejemplo n.º 9
0
def package_install(mounted_path, package_list):
    distro = check_distro(mounted_path)
    if 'centos' in distro.lower():
        return yum_install(mounted_path, package_list)
    elif 'ubuntu' in distro.lower():
        return apt_install(mounted_path, package_list)