orbiter/core/daemon.go
Gianluca Arbezzano db7f674976 Bootstrap autodetection and swarm zero conf
Fixed #9

This PR bootstrap the autodetection feature:

1. It works when the configuration file is not setup. Right know I am
not going to manage the merge of double sources (autodetection and
configuration file).

2. At the moment only Docker Swarm will support this feature.
2017-03-14 23:49:53 +00:00

31 lines
684 B
Go

package core
import (
"fmt"
"github.com/gianarb/orbiter/autoscaler"
"github.com/gianarb/orbiter/provider"
)
type Core struct {
Autoscalers autoscaler.Autoscalers
}
func NewCoreByConfig(c map[string]AutoscalerConf) (Core, error) {
scalers := autoscaler.Autoscalers{}
var core Core
for scalerName, scaler := range c {
p, err := provider.NewProvider(scaler.Provider, scaler.Parameters)
if err != nil {
return core, err
}
for serviceName, policy := range scaler.Policies {
scalers[fmt.Sprintf("%s/%s", scalerName, serviceName)] = autoscaler.NewAutoscaler(p, serviceName, policy.Up, policy.Down)
}
}
core = Core{
Autoscalers: scalers,
}
return core, nil
}