b7daa2f3a4
Update traefik dependencies (docker/docker and related) - Update dependencies - Fix compilation problems - Remove vdemeester/docker-events (in docker api now) - Remove `integration/vendor` - Use `testImport` - update some deps. - regenerate the lock from scratch (after a `glide cc`)
40 lines
991 B
Go
40 lines
991 B
Go
package project
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
)
|
|
|
|
// Scale scales the specified services.
|
|
func (p *Project) Scale(ctx context.Context, timeout int, servicesScale map[string]int) error {
|
|
// This code is a bit verbose but I wanted to parse everything up front
|
|
order := make([]string, 0, 0)
|
|
services := make(map[string]Service)
|
|
|
|
for name := range servicesScale {
|
|
if !p.ServiceConfigs.Has(name) {
|
|
return fmt.Errorf("%s is not defined in the template", name)
|
|
}
|
|
|
|
service, err := p.CreateService(name)
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to lookup service: %s: %v", service, err)
|
|
}
|
|
|
|
order = append(order, name)
|
|
services[name] = service
|
|
}
|
|
|
|
for _, name := range order {
|
|
scale := servicesScale[name]
|
|
log.Infof("Setting scale %s=%d...", name, scale)
|
|
err := services[name].Scale(ctx, scale, timeout)
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to set the scale %s=%d: %v", name, scale, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|