示例#1
0
def schedule(conf, lb_ref):
    filters, cost_functions = _process_config(conf)
    devices = db_api.device_get_all(conf)
    if not devices:
        raise exp.DeviceNotFound
    filtered = _filter_devices(conf, lb_ref, devices, filters)
    weighted = _weight_devices(conf, lb_ref, filtered, cost_functions)
    return weighted[0][1]
示例#2
0
def reschedule(conf, lb_ref):
    filters, cost_functions = _process_config(conf)
    device_ref = db_api.device_get(conf, lb_ref['device_id'])
    try:
        _filter_devices(conf, lb_ref, [device_ref], filters)
    except exp.NoValidDevice:
        devices = db_api.device_get_all(conf)
        devices = [dev_ref for dev_ref in devices
                       if dev_ref['id'] != device_ref['id']]
        filtered = _filter_devices(conf, lb_ref, devices, filters)
        weighted = _weight_devices(conf, lb_ref, filtered, cost_functions)
        return weighted[0][1]
    else:
        return device_ref