Beispiel #1
0
def set_remark(args):
    api = VolumeAPI()

    volume = api.get_volume_by_id(args['volume_id'])
    if not volume.managed_by(args['req_user']):
        return {'res': False, 'err': ERR_AUTH_PERM}

    res = api.set_remark(args['volume_id'], args['remarks'])
    if res:
        return {'res': True}
    return {'res': False, 'err': ERR_VOLUME_REMARKS}
Beispiel #2
0
def resize(args):
    api = VolumeAPI()

    volume = api.get_volume_by_id(args['volume_id'])
    if not volume.managed_by(args['req_user']):
        return {'res': False, 'err': ERR_AUTH_PERM}

    res = api.resize(args['volume_id'], args['size'])
    if res:
        return {'res': True}
    return {'res': False, 'err': ERR_VOLUME_RESIZE}
Beispiel #3
0
def delete(args):
    api = VolumeAPI()

    volume = api.get_volume_by_id(args['volume_id'])
    if not volume.managed_by(args['req_user']):
        return {'res': False, 'err': ERR_AUTH_PERM}

    del_success = api.delete(args['volume_id'])
    if del_success:
        return {'res': True}
    else:
        return {'res': False, 'err': ERR_VOLUME_DELETE_DB}
Beispiel #4
0
def mount(args):
    api = VolumeAPI()
    vm_api = VmAPI()
    vm = vm_api.get_vm_by_uuid(args['vm_uuid'])
    if not vm.can_operate_by(args['req_user']):
        return {'res': False, 'err': ERR_AUTH_PERM}
    if vm.is_running():
        return {'res': False, 'err': ERR_MOUNT_RUNNING}

    volume = api.get_volume_by_id(args['volume_id'])
    if not volume.managed_by(args['req_user']):
        return {'res': False, 'err': ERR_AUTH_PERM}
    res = api.mount(args['vm_uuid'], args['volume_id'])
    if res:
        return {'res': True}
    return {'res': False, 'err': ERR_VOLUME_MOUNT}
Beispiel #5
0
def get(args):
    api = VolumeAPI()
    volume = api.get_volume_by_id(args['volume_id'])
    if not volume.managed_by(args['req_user']):
        return {'res': False, 'err': ERR_AUTH_PERM}
    return {
        'res': True,
        'info': {
            'id': volume.id,
            'user_id': volume.user_id,
            'user_name': volume.user_name,
            'group_id': volume.group_id,
            'create_time': volume.create_time,
            'size': volume.size,
            'remarks': volume.remarks,
            'vm': volume.vm,
            'attach_time': volume.attach_time,
            'dev': volume.dev,
            'enable': volume.enable,
            'cephpool_id': volume.cephpool_id
        }
    }