2013-01-19 00:13:39 +00:00
|
|
|
package docker
|
|
|
|
|
2013-07-15 13:12:33 +00:00
|
|
|
import (
|
2013-11-08 00:35:26 +00:00
|
|
|
"github.com/dotcloud/docker/archive"
|
2014-02-12 00:48:44 +00:00
|
|
|
"github.com/dotcloud/docker/nat"
|
2013-12-23 23:45:18 +00:00
|
|
|
"github.com/dotcloud/docker/pkg/namesgenerator"
|
2014-02-12 04:04:39 +00:00
|
|
|
"github.com/dotcloud/docker/runconfig"
|
2013-10-05 02:25:15 +00:00
|
|
|
"github.com/dotcloud/docker/utils"
|
2013-07-15 13:12:33 +00:00
|
|
|
)
|
|
|
|
|
2013-11-08 00:35:26 +00:00
|
|
|
type Change struct {
|
|
|
|
archive.Change
|
|
|
|
}
|
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
|
2013-10-05 02:25:15 +00:00
|
|
|
if config.PortSpecs != nil {
|
2014-02-12 00:48:44 +00:00
|
|
|
ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
|
2013-10-05 02:25:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
config.PortSpecs = nil
|
2013-10-30 15:15:12 +00:00
|
|
|
if len(bindings) > 0 {
|
|
|
|
if hostConfig == nil {
|
2014-02-12 04:04:39 +00:00
|
|
|
hostConfig = &runconfig.HostConfig{}
|
2013-10-30 15:15:12 +00:00
|
|
|
}
|
|
|
|
hostConfig.PortBindings = bindings
|
|
|
|
}
|
2013-10-05 02:25:15 +00:00
|
|
|
|
|
|
|
if config.ExposedPorts == nil {
|
2014-02-12 00:48:44 +00:00
|
|
|
config.ExposedPorts = make(nat.PortSet, len(ports))
|
2013-10-05 02:25:15 +00: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-28 23:58:59 +00: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 01:26:01 +00:00
|
|
|
func generateRandomName(runtime *Runtime) (string, error) {
|
|
|
|
return namesgenerator.GenerateRandomName(&checker{runtime})
|
2013-10-28 23:58:59 +00:00
|
|
|
}
|