2013-01-19 04:13:39 +04:00
|
|
|
package docker
|
|
|
|
|
2013-07-15 17:12:33 +04:00
|
|
|
import (
|
2013-11-08 04:35:26 +04:00
|
|
|
"github.com/dotcloud/docker/archive"
|
2014-02-12 04:48:44 +04:00
|
|
|
"github.com/dotcloud/docker/nat"
|
2013-12-24 03:45:18 +04:00
|
|
|
"github.com/dotcloud/docker/pkg/namesgenerator"
|
2014-02-12 08:04:39 +04:00
|
|
|
"github.com/dotcloud/docker/runconfig"
|
2013-10-05 06:25:15 +04:00
|
|
|
"github.com/dotcloud/docker/utils"
|
2013-07-15 17:12:33 +04:00
|
|
|
)
|
|
|
|
|
2013-11-08 04:35:26 +04:00
|
|
|
type Change struct {
|
|
|
|
archive.Change
|
|
|
|
}
|
|
|
|
|
2014-02-12 08:04:39 +04:00
|
|
|
func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
|
2013-10-05 06:25:15 +04:00
|
|
|
if config.PortSpecs != nil {
|
2014-02-12 04:48:44 +04:00
|
|
|
ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
|
2013-10-05 06:25:15 +04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
config.PortSpecs = nil
|
2013-10-30 19:15:12 +04:00
|
|
|
if len(bindings) > 0 {
|
|
|
|
if hostConfig == nil {
|
2014-02-12 08:04:39 +04:00
|
|
|
hostConfig = &runconfig.HostConfig{}
|
2013-10-30 19:15:12 +04:00
|
|
|
}
|
|
|
|
hostConfig.PortBindings = bindings
|
|
|
|
}
|
2013-10-05 06:25:15 +04:00
|
|
|
|
|
|
|
if config.ExposedPorts == nil {
|
2014-02-12 04:48:44 +04:00
|
|
|
config.ExposedPorts = make(nat.PortSet, len(ports))
|
2013-10-05 06:25:15 +04:00
|
|
|
}
|
|
|
|
for k, v := range ports {
|
|
|
|
config.ExposedPorts[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Links come in the format of
|
|
|
|
// name:alias
|
|
|
|
func parseLink(rawLink string) (map[string]string, error) {
|
|
|
|
return utils.PartParser("name:alias", rawLink)
|
|
|
|
}
|
2013-10-29 03:58:59 +04:00
|
|
|
|
|
|
|
type checker struct {
|
|
|
|
runtime *Runtime
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *checker) Exists(name string) bool {
|
|
|
|
return c.runtime.containerGraph.Exists("/" + name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a random and unique name
|
2013-10-31 05:26:01 +04:00
|
|
|
func generateRandomName(runtime *Runtime) (string, error) {
|
|
|
|
return namesgenerator.GenerateRandomName(&checker{runtime})
|
2013-10-29 03:58:59 +04:00
|
|
|
}
|