hostconfig.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package runconfig
  2. import (
  3. "strings"
  4. "github.com/dotcloud/docker/engine"
  5. "github.com/dotcloud/docker/nat"
  6. "github.com/dotcloud/docker/utils"
  7. )
  8. type NetworkMode string
  9. func (n NetworkMode) IsHost() bool {
  10. return n == "host"
  11. }
  12. func (n NetworkMode) IsContainer() bool {
  13. parts := strings.SplitN(string(n), ":", 2)
  14. return len(parts) > 1 && parts[0] == "container"
  15. }
  16. type HostConfig struct {
  17. Binds []string
  18. ContainerIDFile string
  19. LxcConf []utils.KeyValuePair
  20. Privileged bool
  21. PortBindings nat.PortMap
  22. Links []string
  23. PublishAllPorts bool
  24. Dns []string
  25. DnsSearch []string
  26. VolumesFrom []string
  27. NetworkMode NetworkMode
  28. }
  29. func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
  30. hostConfig := &HostConfig{
  31. ContainerIDFile: job.Getenv("ContainerIDFile"),
  32. Privileged: job.GetenvBool("Privileged"),
  33. PublishAllPorts: job.GetenvBool("PublishAllPorts"),
  34. NetworkMode: NetworkMode(job.Getenv("NetworkMode")),
  35. }
  36. job.GetenvJson("LxcConf", &hostConfig.LxcConf)
  37. job.GetenvJson("PortBindings", &hostConfig.PortBindings)
  38. if Binds := job.GetenvList("Binds"); Binds != nil {
  39. hostConfig.Binds = Binds
  40. }
  41. if Links := job.GetenvList("Links"); Links != nil {
  42. hostConfig.Links = Links
  43. }
  44. if Dns := job.GetenvList("Dns"); Dns != nil {
  45. hostConfig.Dns = Dns
  46. }
  47. if DnsSearch := job.GetenvList("DnsSearch"); DnsSearch != nil {
  48. hostConfig.DnsSearch = DnsSearch
  49. }
  50. if VolumesFrom := job.GetenvList("VolumesFrom"); VolumesFrom != nil {
  51. hostConfig.VolumesFrom = VolumesFrom
  52. }
  53. return hostConfig
  54. }