utils.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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) []string {
  31. if hostConfig == nil {
  32. return nil
  33. }
  34. out := []string{}
  35. // merge in the lxc conf options into the generic config map
  36. if lxcConf := hostConfig.LxcConf; lxcConf != nil {
  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. out = append(out, fmt.Sprintf("%s=%s", parts[1], pair.Value))
  42. }
  43. }
  44. return out
  45. }