def schedule_loadbalancer(conf, lb_ref):
    conf.register_opts(bind_opts)
    device_filters = [utils.import_class(foo) for foo in conf.device_filters]
    all_devices = db_api.device_get_all(conf)
    if not all_devices:
        raise exp.DeviceNotFound
    cost_functions = []
    for fullname in conf.device_cost_functions:
        conf_name = 'device_cost_%s_weight' % fullname.rpartition('.')[-1]
        try:
            weight = getattr(conf, conf_name)
        except cfg.NoSuchOptError:
            conf.register_opt(cfg.FloatOpt(conf_name, default=1.))
            weight = getattr(conf, conf_name)
        cost_functions.append((utils.import_class(fullname), weight))
    filtered_devices = [dev for dev in all_devices
                        if all(filt(conf, lb_ref, dev)
                        for filt in device_filters)]
    if not filtered_devices:
        raise exp.NoValidDevice
    costed = []
    for dev in filtered_devices:
        w = 0.
        for cost_func, weight in cost_functions:
            w += weight * cost_func(conf, lb_ref, dev)
        costed.append((w, dev))
    costed.sort()
    return costed[0][1]
示例#2
0
 def test_device_get_all(self):
     device_ref1 = db_api.device_create(self.conf, device_fake1)
     device_ref2 = db_api.device_create(self.conf, device_fake2)
     devices = db_api.device_get_all(self.conf)
     self.assertEqual([dict(dev.iteritems()) for dev in devices],
                      [dict(dev.iteritems()) for dev in [device_ref1,
                                                         device_ref2]])
示例#3
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]
示例#4
0
def device_show_protocols(conf):
    devices = db_api.device_get_all(conf)
    protocols = []
    for device in devices:
        device_driver = drivers.get_device_driver(conf, device['id'])
        capabilities = device_driver.get_capabilities()
        if capabilities is not None:
            protocols += [a for a in capabilities.get('protocols', [])
                    if a not in protocols]
    return protocols
示例#5
0
def device_show_algorithms(conf):
    devices = db_api.device_get_all(conf)
    algorithms = []
    for device in devices:
        device_driver = drivers.get_device_driver(conf, device['id'])
        capabilities = device_driver.get_capabilities()
        if capabilities is not None:
            algorithms += [a for a in capabilities.get('algorithms', [])
                    if a not in algorithms]
    return algorithms
示例#6
0
 def __init__(self, conf):
     self.conf = conf
     self._device_map = {}
     devices = db_api.device_get_all(conf)
     self._list = devices
     self._last_selected = 0
     self._device_count = 0
     self._lock = threading.RLock()
     for device in devices:
         self._device_map[device['id']] = device
         self._device_count += 1
示例#7
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
示例#8
0
def device_show_protocols(conf):
    devices = db_api.device_get_all(conf)
    protocols = []
    for device in devices:
        try:
            device_driver = drivers.get_device_driver(conf, device['id'])
            capabilities = device_driver.get_capabilities()
            if capabilities is not None:
                protocols += [a for a in capabilities.get('protocols', [])
                              if a not in protocols]
        except Exception:
            LOG.warn('Failed to get supported protocols of device %s',
                     device['name'], exc_info=True)
    return protocols
示例#9
0
def device_get_index(conf):
    devices = db_api.device_get_all(conf)
    devices = [db_api.unpack_extra(dev) for dev in devices]
    return devices
示例#10
0
 def test_device_get_all(self):
     device_ref1 = db_api.device_create(self.conf, device_fake1)
     device_ref2 = db_api.device_create(self.conf, device_fake2)
     devices = db_api.device_get_all(self.conf)
     self.assertEqual(len(devices), 2)