Beispiel #1
0
def edit(caller_id, storage_image_id, name, description, disk_controller):
    """
    Sets Image's new attributes. Those should be get by src.cm.manager.image.get_by_id().
    @cmview_admin_cm

    @parameter{system_image_id,string} new Image name
    @parameter{name,string} new Image name
    @parameter{description,string} new Image description
    @parameter{disk_controller} new Image controller optional
    @parameter{video_device} new video device optional
    @parameter{network_device} new network device optional
    @parameter{platform} optional
    """

    image = StorageImage.admin_get(storage_image_id)

    if image.state != image_states['ok']:
        raise CMException('image_edit')

    image.name = name
    image.description = description
    image.disk_controller = disk_controller

    try:
        image.save()
    except:
        raise CMException('image_edit')
Beispiel #2
0
def get_by_id(caller_id, storage_image_id):
    """
    Fetch requested StorageImage.

    @cmview_admin_cm
    @param_post{storage_image_id,int} id of the requested StorageImage

    @response{dict} StorageImages.dict property for requested StorageImage
    """
    return StorageImage.admin_get(storage_image_id).dict
Beispiel #3
0
def get_by_id(caller_id, storage_image_id):
    """
    @cmview_admin_cm

    @parameter{image_id,int} id of the Image to get
    @parameter{type,image_types} type of image, automatically set, type is in the URL requested

    @response{dict} extended information about specified Image
    """
    return StorageImage.admin_get(storage_image_id).dict
Beispiel #4
0
def delete(caller_id, storage_image_id):
    """
    Deletes given Image
    @cmview_admin_cm

    @parameter{system_image_id} id of the Image to delete
    @parameter{type,image_types} type of image, automatically set, type is in the URL requested
    """
    image = StorageImage.admin_get(storage_image_id)

    image.check_attached()
    image.state = image_states['locked']
    image.save()
Beispiel #5
0
def delete(caller_id, storage_image_id):
    """
    Sets StorageImage state as @val{locked}.

    @cmview_admin_cm
    @param_post{storage_image_id} id of the Image to delete

    @todo Should rather delete StorageImage and set its state to 'deleted'.
    """
    image = StorageImage.admin_get(storage_image_id)

    image.check_attached()
    image.state = image_states['locked']
    image.save()
Beispiel #6
0
def copy(caller_id, src_image_id, dest_user_id):
    """
    Copy selected StorageImage to user's StorageImages

    @cmview_admin_cm
    @param_post{src_image_id,int}
    @param_post{dest_user_id,int}
    """
    src_image = StorageImage.admin_get(src_image_id)
    dest_user = User.get(dest_user_id)
    dest_image = StorageImage.create(name=src_image.name, description=src_image.description, user=dest_user,
                                    disk_controller=src_image.disk_controller, size=src_image.size)

    try:
        dest_image.save()
    except Exception, e:
        log.error(caller_id, "Unable to commit: %s" % str(e))
        raise CMException('image_create')
Beispiel #7
0
def convert_to_system_image(caller_id, storage_image_id):
    """
    Converts specified StorageImage to SystemImage. After convertion it's not
    available as StorageImage anymore. File is moved and StorageImage entry is
    removed from database.

    @cmview_admin_cm
    @param_post{storage_image_id,int} ID of an StorageImage to convert
    """
    image = StorageImage.admin_get(storage_image_id)

    system_image = SystemImage.create(name=image.name, description=image.description, user=image.user, disk_controller=image.disk_controller)
    system_image.state = image_states['ok']
    system_image.size = image.size

    try:
        system_image.save()
        os.rename(image.path, system_image.path)
        image.delete()
    except Exception:
        raise CMException('image_change_type')
Beispiel #8
0
def convert_to_system_image(caller_id, storage_image_id):
    """
    Changes type of the given Image.
    @cmview_admin_cm

    @parameter{system_image_id,int} ID of an Image to change type of

    @response{None}
    """
    image = StorageImage.admin_get(storage_image_id)

    system_image = SystemImage.create(name=image.name, description=image.description, user=image.user, disk_controller=image.disk_controller)
    system_image.state = image_states['ok']
    system_image.size = image.size

    try:
        system_image.save()
        os.rename(image.path, system_image.path)
        image.delete()
    except Exception:
        raise CMException('image_change_type')
Beispiel #9
0
def edit(caller_id, storage_image_id, name, description, disk_controller):
    """
    Updates Image's attributes.

    @cmview_admin_cm
    @param_post{storage_image_id,string}
    @param_post{name,string} new Image name
    @param_post{description,string} new Image description
    @param_post{disk_controller} new Image controller optional
    """

    image = StorageImage.admin_get(storage_image_id)

    if image.state != image_states['ok']:
        raise CMException('image_edit')

    image.name = name
    image.description = description
    image.disk_controller = disk_controller

    try:
        image.save()
    except:
        raise CMException('image_edit')