utils.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package docker
  2. import (
  3. "github.com/dotcloud/docker/archive"
  4. "github.com/dotcloud/docker/nat"
  5. "github.com/dotcloud/docker/pkg/namesgenerator"
  6. "github.com/dotcloud/docker/runconfig"
  7. "github.com/dotcloud/docker/utils"
  8. )
  9. type Change struct {
  10. archive.Change
  11. }
  12. func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
  13. if config.PortSpecs != nil {
  14. ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
  15. if err != nil {
  16. return err
  17. }
  18. config.PortSpecs = nil
  19. if len(bindings) > 0 {
  20. if hostConfig == nil {
  21. hostConfig = &runconfig.HostConfig{}
  22. }
  23. hostConfig.PortBindings = bindings
  24. }
  25. if config.ExposedPorts == nil {
  26. config.ExposedPorts = make(nat.PortSet, len(ports))
  27. }
  28. for k, v := range ports {
  29. config.ExposedPorts[k] = v
  30. }
  31. }
  32. return nil
  33. }
  34. // Links come in the format of
  35. // name:alias
  36. func parseLink(rawLink string) (map[string]string, error) {
  37. return utils.PartParser("name:alias", rawLink)
  38. }
  39. type checker struct {
  40. runtime *Runtime
  41. }
  42. func (c *checker) Exists(name string) bool {
  43. return c.runtime.containerGraph.Exists("/" + name)
  44. }
  45. // Generate a random and unique name
  46. func generateRandomName(runtime *Runtime) (string, error) {
  47. return namesgenerator.GenerateRandomName(&checker{runtime})
  48. }