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}
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}
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}
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}
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 } }