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