def create_from_instance(request, uuid):
    logger.debug('Creating new image from instance')
    domain = libvirtUtils.get_domain_by_uuid(uuid)
    logger.debug(('got domain ' + domain.name()))
    domain_image = libvirtUtils.get_image_for_domain(uuid)
    logger.debug(('got domain_image: ' + domain_image))
    if osUtils.is_image_thin_provisioned(domain_image):
        logger.error('Cannot clone disk that is thinly provisioned! Please perform a block pull before continuing')
        context = {'error': 'Cannot Clone thinly provisioned disk! Please perform a block pull!'}
        return render(request, 'error.html', context)
    domain_name = domain.name()
    media_root = settings.MEDIA_ROOT
    media_root_array = media_root.split('/')
    len_media_root = len(media_root_array)
    full_path_array = domain_image.split('/')
    full_path = '/'.join(full_path_array[:full_path_array.index('instances')])
    file_path_array = domain_image.split('/')[len_media_root:]
    images_dir = '/'.join(file_path_array[:file_path_array.index('instances')])
    new_relative_image_path = (((images_dir + '/image_') + str(domain.UUIDString())) + '.img')
    new_full_image_path = (((full_path + '/image_') + str(domain.UUIDString())) + '.img')
    if osUtils.check_path(new_full_image_path):
        logger.info('Image has already been cloned')
        context = {'error': 'Instance has already been cloned!'}
        return render(request, 'error.html', context)
    logger.debug(('Copying image from ' + domain_image))
    logger.debug(('To ' + new_full_image_path))
    osUtils.copy_image_to_clone(domain_image, new_full_image_path)
    image = Image()
    image.name = ('image_' + str(domain.UUIDString()))
    image.description = ('Clone of ' + domain_name)
    image.filePath = new_relative_image_path
    image.save()
    return HttpResponseRedirect('/images/')
def create_from_instance(request, uuid):
    logger.debug('Creating new image from instance')
    domain = libvirtUtils.get_domain_by_uuid(uuid)
    logger.debug(('got domain ' + domain.name()))
    domain_image = libvirtUtils.get_image_for_domain(uuid)
    logger.debug(('got domain_image: ' + domain_image))
    if osUtils.is_image_thin_provisioned(domain_image):
        logger.error('Cannot clone disk that is thinly provisioned! Please perform a block pull before continuing')
        context = {'error': 'Cannot Clone thinly provisioned disk! Please perform a block pull!'}
        return render(request, 'error.html', context)
    domain_name = domain.name()
    media_root = settings.MEDIA_ROOT
    media_root_array = media_root.split('/')
    len_media_root = len(media_root_array)
    full_path_array = domain_image.split('/')
    full_path = '/'.join(full_path_array[:full_path_array.index('instances')])
    file_path_array = domain_image.split('/')[len_media_root:]
    images_dir = '/'.join(file_path_array[:file_path_array.index('instances')])
    new_relative_image_path = (((images_dir + '/image_') + str(domain.UUIDString())) + '.img')
    new_full_image_path = (((full_path + '/image_') + str(domain.UUIDString())) + '.img')
    if osUtils.check_path(new_full_image_path):
        logger.info('Image has already been cloned')
        context = {'error': 'Instance has already been cloned!'}
        return render(request, 'error.html', context)
    logger.debug(('Copying image from ' + domain_image))
    logger.debug(('To ' + new_full_image_path))
    osUtils.copy_image_to_clone(domain_image, new_full_image_path)
    image = Image()
    image.name = ('image_' + str(domain.UUIDString()))
    image.description = ('Clone of ' + domain_name)
    image.filePath = new_relative_image_path
    image.save()
    return HttpResponseRedirect('/images/')