Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
23 lines (19 sloc) 665 Bytes
package getaredis
import "errors"
// Returns the ip for the host which can hold this container
func (ctx *context) scheduleNewContainer() (publicIP, privateIP string, err error) {
hosts := ctx.ListHosts()
maximumNumberOfContainers := ctx.config.MaxContainersPerHost
maximumNumber := -1
chosenHost := -1
for i, host := range hosts {
if host.NumberOfContainers < maximumNumberOfContainers && maximumNumber < host.NumberOfContainers {
maximumNumber = host.NumberOfContainers
chosenHost = i
}
}
if chosenHost == -1 {
return "", "", errors.New("Cannot schedule container.")
}
return hosts[chosenHost].PublicIP, hosts[chosenHost].PrivateIP, nil
}