func()

in lib/config.go [238:273]


func (c *configSpec) algorithm(provider ConfigProvider) (DHCPBalancingAlgorithm, error) {
	// Balancing algorithms coming with the dhcplb source code
	modulo := new(modulo)
	rr := new(roundRobin)
	algorithms := map[string]DHCPBalancingAlgorithm{
		modulo.Name(): modulo,
		rr.Name():     rr,
	}
	// load other non default algorithms from the ConfigProvider
	providedAlgo, err := provider.NewDHCPBalancingAlgorithm(c.Version)
	if err != nil {
		glog.Fatalf("Provided load balancing implementation error: %s", err)
	}
	if providedAlgo != nil {
		if _, exists := algorithms[providedAlgo.Name()]; exists {
			glog.Fatalf("Algorithm name %s exists already, pick another name.", providedAlgo.Name())

		}
		algorithms[providedAlgo.Name()] = providedAlgo
	}
	lb, ok := algorithms[c.AlgorithmName]
	if !ok {
		supported := []string{}
		for k := range algorithms {
			supported = append(supported, k)
		}
		glog.Fatalf(
			"'%s' is not a supported balancing algorithm. "+
				"Supported balancing algorithms are: %v",
			c.AlgorithmName, supported)
		return nil, fmt.Errorf(
			"'%s' is not a supported balancing algorithm", c.AlgorithmName)
	}
	lb.SetRCRatio(c.RCRatio)
	return lb, nil
}