Beispiel #1
0
def virt_builder(base_image, dst_image, commands_file, fail_on_error=True):
    """
    Generates an uncompressed disk image

    Args:
        commands_file (str): Path to the commands file to use
        dst_image (str): Path for the newly generated disk image
        base_image (str): virt-builder specification, for example 'fedora23',
            see virt-builder --list

    Returns:
        None
    """
    cmd = [
        'virt-builder',
        '--commands-from-file=' + commands_file,
        '--output=' + dst_image,
        '--format=qcow2',
        '-v',
        base_image,
    ]

    with LogTask('Running virt-builder on {}'.format(base_image)):
        return run_command_with_validation(cmd,
                                           fail_on_error,
                                           msg='Failed to run virt-builder')
Beispiel #2
0
def gzip_compress(dst, fail_on_error=True):
    cmd = ['gzip', '--best', dst]

    with LogTask('Compressing {} with gzip'.format(dst)):
        return run_command_with_validation(cmd,
                                           fail_on_error,
                                           msg='Failed to compress with gzip')
Beispiel #3
0
def create_layered_image(dst_image, base_image, fail_on_error=True):
    """
    Generates an uncompressed layered disk image from the given base one

    Args:
        dst_image (str): Path for the newly generated disk image
        base_image (str): path to the backing file to use

    Returns:
        None
    """
    cmd = [
        'qemu-img',
        'create',
        '-f',
        'qcow2',
        '-v',
        '-b',
        base_image,
        dst_image,
    ]

    with LogTask('Creating layered image of {}'.format(base_image)):
        return run_command_with_validation(
            cmd,
            fail_on_error,
            msg='Failed to create layered image from {}'.format(base_image))
Beispiel #4
0
def xz_decompress(dst, fail_on_error=True):
    cmd = ['xz', '--threads=0', '--decompress', dst]

    with LogTask('Decompressing {} with xz'.format(dst)):
        return run_command_with_validation(
            cmd,
            fail_on_error,
            msg='Failed to decompress {} with xz'.format(dst))
Beispiel #5
0
def virt_customize(dst_image, commands_file, fail_on_error=True):
    cmd = [
        'virt-customize',
        '--commands-from-file=' + commands_file,
        '--format=qcow2',
        '-v',
        '--add=' + dst_image,
    ]

    with LogTask('Running virt-customize on {}'.format(dst_image)):
        return run_command_with_validation(
            cmd,
            fail_on_error,
            msg='Failed to run virt-customize on {}'.format(dst_image))
Beispiel #6
0
def virt_sprsify(dst_image, dst_image_format='qcow2', fail_on_error=True):
    cmd = [
        'virt-sparsify',
        '-v',
        '-x',
        '--format',
        dst_image_format,
        '--in-place',
        dst_image,
    ]

    with LogTask('Running virt-sparsipy on {}'.format(dst_image)):
        return run_command_with_validation(
            cmd,
            fail_on_error,
            msg='Failed to run virt-sparsify on {}'.format(dst_image))
Beispiel #7
0
def virt_sysprep(dst_image, commands_file=None, fail_on_error=True):
    cmd = [
        'virt-sysprep',
        '--format=qcow2',
        '--selinux-relabel',
        '-v',
        '--add=' + dst_image,
    ]

    if commands_file:
        cmd.append('--commands-from-file='.format(commands_file))

    with LogTask('Running virt-sysprep on {}'.format(dst_image)):
        return run_command_with_validation(
            cmd,
            fail_on_error,
            msg='Failed to run virt-sysprep on {}'.format(dst_image))
Beispiel #8
0
def gzip_decompress(dst, fail_on_error=True):
    cmd = ['gzip', '--decompress', dst]

    with LogTask('Decompressing {} with gzip'):
        return run_command_with_validation(
            cmd, fail_on_error, msg='Failed to decompress with gzip')