utils.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package daemon
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/docker/docker/nat"
  6. "github.com/docker/docker/runconfig"
  7. )
  8. func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
  9. if config.PortSpecs != nil {
  10. ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
  11. if err != nil {
  12. return err
  13. }
  14. config.PortSpecs = nil
  15. if len(bindings) > 0 {
  16. if hostConfig == nil {
  17. hostConfig = &runconfig.HostConfig{}
  18. }
  19. hostConfig.PortBindings = bindings
  20. }
  21. if config.ExposedPorts == nil {
  22. config.ExposedPorts = make(nat.PortSet, len(ports))
  23. }
  24. for k, v := range ports {
  25. config.ExposedPorts[k] = v
  26. }
  27. }
  28. return nil
  29. }
  30. func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig, driverConfig map[string][]string) {
  31. if hostConfig == nil {
  32. return
  33. }
  34. // merge in the lxc conf options into the generic config map
  35. if lxcConf := hostConfig.LxcConf; lxcConf != nil {
  36. lxc := driverConfig["lxc"]
  37. for _, pair := range lxcConf {
  38. // because lxc conf gets the driver name lxc.XXXX we need to trim it off
  39. // and let the lxc driver add it back later if needed
  40. parts := strings.SplitN(pair.Key, ".", 2)
  41. lxc = append(lxc, fmt.Sprintf("%s=%s", parts[1], pair.Value))
  42. }
  43. driverConfig["lxc"] = lxc
  44. }
  45. }