config.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package docker
  2. import (
  3. "github.com/dotcloud/docker/engine"
  4. "net"
  5. )
  6. // FIXME: separate runtime configuration from http api configuration
  7. type DaemonConfig struct {
  8. Pidfile string
  9. Root string
  10. AutoRestart bool
  11. EnableCors bool
  12. Dns []string
  13. EnableIptables bool
  14. BridgeIface string
  15. BridgeIp string
  16. DefaultIp net.IP
  17. InterContainerCommunication bool
  18. GraphDriver string
  19. Mtu int
  20. }
  21. // ConfigFromJob creates and returns a new DaemonConfig object
  22. // by parsing the contents of a job's environment.
  23. func ConfigFromJob(job *engine.Job) *DaemonConfig {
  24. var config DaemonConfig
  25. config.Pidfile = job.Getenv("Pidfile")
  26. config.Root = job.Getenv("Root")
  27. config.AutoRestart = job.GetenvBool("AutoRestart")
  28. config.EnableCors = job.GetenvBool("EnableCors")
  29. if dns := job.GetenvList("Dns"); dns != nil {
  30. config.Dns = dns
  31. }
  32. config.EnableIptables = job.GetenvBool("EnableIptables")
  33. if br := job.Getenv("BridgeIface"); br != "" {
  34. config.BridgeIface = br
  35. } else {
  36. config.BridgeIface = DefaultNetworkBridge
  37. }
  38. config.BridgeIp = job.Getenv("BridgeIp")
  39. config.DefaultIp = net.ParseIP(job.Getenv("DefaultIp"))
  40. config.InterContainerCommunication = job.GetenvBool("InterContainerCommunication")
  41. config.GraphDriver = job.Getenv("GraphDriver")
  42. if mtu := job.GetenvInt("Mtu"); mtu != -1 {
  43. config.Mtu = mtu
  44. } else {
  45. config.Mtu = DefaultNetworkMtu
  46. }
  47. return &config
  48. }