human
Complete this python program:
def create_lvm_image(vg, lv, size, sparse=False):
assistant
#Here is the Python code you requested.

    """Create LVM image.
    Creates a LVM image with given size.
    :param vg: existing volume group which should hold this image
    :param lv: name for this image (logical volume)
    :size: size of image in bytes
    :sparse: create sparse logical volume
    """
    vg_info = get_volume_group_info(vg)
    free_space = vg_info['free']
    def check_size(vg, lv, size):
        if (size > free_space):
            raise RuntimeError((_('Insufficient    Space    on    Volume    Group    %(vg)s.    Only    %(free_space)db    available,    but    %(size)db    required    by    volume    %(lv)s.') % locals()))
    if sparse:
        preallocated_space = ((64 * 1024) * 1024)
        check_size(vg, lv, preallocated_space)
        if (free_space < size):
            LOG.warning((_('Volume    group    %(vg)s    will    not    be    able    to    hold    sparse    volume    %(lv)s.    Virtual    volume    size    is    %(size)db,    but    free    space    on    volume    group    is    only    %(free_space)db.') % locals()))
        cmd = ('lvcreate', '-L', ('%db' % preallocated_space), '--virtualsize', ('%db' % size), '-n', lv, vg)
    else:
        check_size(vg, lv, size)
        cmd = ('lvcreate', '-L', ('%db' % size), '-n', lv, vg)
    execute(run_as_root=True, attempts=3, *cmd)