2014-04-17 17:43:01 -04:00
|
|
|
package daemon
|
2014-03-07 21:42:29 -05:00
|
|
|
|
|
|
|
import (
|
2014-03-13 12:03:09 -04:00
|
|
|
"fmt"
|
2014-03-07 21:42:29 -05:00
|
|
|
"github.com/dotcloud/docker/nat"
|
|
|
|
"github.com/dotcloud/docker/pkg/namesgenerator"
|
|
|
|
"github.com/dotcloud/docker/runconfig"
|
2014-03-13 12:03:09 -04:00
|
|
|
"strings"
|
2014-03-07 21:42:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
|
|
|
|
if config.PortSpecs != nil {
|
|
|
|
ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
config.PortSpecs = nil
|
|
|
|
if len(bindings) > 0 {
|
|
|
|
if hostConfig == nil {
|
|
|
|
hostConfig = &runconfig.HostConfig{}
|
|
|
|
}
|
|
|
|
hostConfig.PortBindings = bindings
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.ExposedPorts == nil {
|
|
|
|
config.ExposedPorts = make(nat.PortSet, len(ports))
|
|
|
|
}
|
|
|
|
for k, v := range ports {
|
|
|
|
config.ExposedPorts[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:03:09 -04:00
|
|
|
func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig, driverConfig map[string][]string) {
|
|
|
|
if hostConfig == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge in the lxc conf options into the generic config map
|
|
|
|
if lxcConf := hostConfig.LxcConf; lxcConf != nil {
|
|
|
|
lxc := driverConfig["lxc"]
|
|
|
|
for _, pair := range lxcConf {
|
|
|
|
// because lxc conf gets the driver name lxc.XXXX we need to trim it off
|
|
|
|
// and let the lxc driver add it back later if needed
|
|
|
|
parts := strings.SplitN(pair.Key, ".", 2)
|
|
|
|
lxc = append(lxc, fmt.Sprintf("%s=%s", parts[1], pair.Value))
|
|
|
|
}
|
|
|
|
driverConfig["lxc"] = lxc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-07 21:42:29 -05:00
|
|
|
type checker struct {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon *Daemon
|
2014-03-07 21:42:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *checker) Exists(name string) bool {
|
2014-04-17 17:43:01 -04:00
|
|
|
return c.daemon.containerGraph.Exists("/" + name)
|
2014-03-07 21:42:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a random and unique name
|
2014-04-17 17:43:01 -04:00
|
|
|
func generateRandomName(daemon *Daemon) (string, error) {
|
|
|
|
return namesgenerator.GenerateRandomName(&checker{daemon})
|
2014-03-07 21:42:29 -05:00
|
|
|
}
|