config.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package daemonconfig
  2. import (
  3. "github.com/dotcloud/docker/daemon/networkdriver"
  4. "github.com/dotcloud/docker/engine"
  5. "net"
  6. )
  7. const (
  8. defaultNetworkMtu = 1500
  9. DisableNetworkBridge = "none"
  10. )
  11. // FIXME: separate runtime configuration from http api configuration
  12. type Config struct {
  13. Pidfile string
  14. Root string
  15. AutoRestart bool
  16. Dns []string
  17. DnsSearch []string
  18. EnableIptables bool
  19. EnableIpForward bool
  20. DefaultIp net.IP
  21. BridgeIface string
  22. BridgeIP string
  23. InterContainerCommunication bool
  24. GraphDriver string
  25. ExecDriver string
  26. Mtu int
  27. DisableNetwork bool
  28. EnableSelinuxSupport bool
  29. Context map[string][]string
  30. }
  31. // ConfigFromJob creates and returns a new DaemonConfig object
  32. // by parsing the contents of a job's environment.
  33. func ConfigFromJob(job *engine.Job) *Config {
  34. config := &Config{
  35. Pidfile: job.Getenv("Pidfile"),
  36. Root: job.Getenv("Root"),
  37. AutoRestart: job.GetenvBool("AutoRestart"),
  38. EnableIptables: job.GetenvBool("EnableIptables"),
  39. EnableIpForward: job.GetenvBool("EnableIpForward"),
  40. BridgeIP: job.Getenv("BridgeIP"),
  41. BridgeIface: job.Getenv("BridgeIface"),
  42. DefaultIp: net.ParseIP(job.Getenv("DefaultIp")),
  43. InterContainerCommunication: job.GetenvBool("InterContainerCommunication"),
  44. GraphDriver: job.Getenv("GraphDriver"),
  45. ExecDriver: job.Getenv("ExecDriver"),
  46. EnableSelinuxSupport: job.GetenvBool("EnableSelinuxSupport"),
  47. }
  48. if dns := job.GetenvList("Dns"); dns != nil {
  49. config.Dns = dns
  50. }
  51. if dnsSearch := job.GetenvList("DnsSearch"); dnsSearch != nil {
  52. config.DnsSearch = dnsSearch
  53. }
  54. if mtu := job.GetenvInt("Mtu"); mtu != 0 {
  55. config.Mtu = mtu
  56. } else {
  57. config.Mtu = GetDefaultNetworkMtu()
  58. }
  59. config.DisableNetwork = config.BridgeIface == DisableNetworkBridge
  60. return config
  61. }
  62. func GetDefaultNetworkMtu() int {
  63. if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
  64. return iface.MTU
  65. }
  66. return defaultNetworkMtu
  67. }