Exemplo n.º 1
0
def detail(request, image_id):
    image = get_object_or_404(Image, pk=image_id)

    vm_type = "N/A"
    for vt in configuration.vm_image_types:
        if vt["name"] == image.type:
            vm_type = vt["description"]
            break

    glance_id = ""
    image_state = ""

    if configuration.deployment_backend == "openstack":
        openstackUtils.connect_to_openstack()
        glance_id = openstackUtils.get_image_id_for_name(image.name)
    elif configuration.deployment_backend == "kvm" and image.filePath != "":
        image_state = osUtils.is_image_thin_provisioned(image.filePath.path)

    return render(
        request, 'images/details.html', {
            'image': image,
            'state': image_state,
            "vm_type": vm_type,
            "settings": settings,
            "glance_id": glance_id,
            "use_openstack": configuration.use_openstack,
            "openstack_host": configuration.openstack_host
        })
Exemplo n.º 2
0
def block_pull(request, uuid):
    domain = libvirtUtils.get_domain_by_uuid(uuid)
    domain_name = domain.name()
    image_path = libvirtUtils.get_image_for_domain(domain.UUIDString())

    if osUtils.is_image_thin_provisioned(image_path):
        logger.debug("Found thinly provisioned image, promoting...")
        rv = libvirtUtils.promote_instance_to_image(domain_name)

        if rv is None:
            messages.info(
                request,
                "Image already promoted. Shut down the instance to perform a clone."
            )
        elif rv:
            messages.info(request, "Promoting thinly provisioned image")
        else:
            messages.info(request, "Error Promoting image!")

    else:
        messages.info(
            request,
            "Image is already promoted. You may now shutdown the image and perform a Clone"
        )
        logger.debug("Image is already promoted")

    return HttpResponseRedirect('/ajax/manageHypervisor/')
Exemplo n.º 3
0
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()

    # FIXME - make these variable names a bit more clear about their meaning
    # we need to get the path of the image relative to the MEDIA_ROOT
    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')])

    # grab the file path of the domain image without the MEDIA_ROOT prepended
    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/')