2014-03-07 18:22:23 -05:00
|
|
|
package daemonconfig
|
2013-10-04 22:25:15 -04:00
|
|
|
|
|
|
|
import (
|
2014-02-01 06:38:39 -05:00
|
|
|
"github.com/dotcloud/docker/engine"
|
2014-03-14 17:03:23 -04:00
|
|
|
"github.com/dotcloud/docker/runtime/networkdriver"
|
2014-04-02 13:56:30 -04:00
|
|
|
"net"
|
2013-10-04 22:25:15 -04:00
|
|
|
)
|
|
|
|
|
2014-01-29 21:34:43 -05:00
|
|
|
const (
|
2014-02-01 06:38:39 -05:00
|
|
|
defaultNetworkMtu = 1500
|
2014-01-29 21:34:43 -05:00
|
|
|
DisableNetworkBridge = "none"
|
|
|
|
)
|
|
|
|
|
2013-10-21 12:04:42 -04:00
|
|
|
// FIXME: separate runtime configuration from http api configuration
|
2014-03-07 18:22:23 -05:00
|
|
|
type Config struct {
|
2013-10-10 16:48:22 -04:00
|
|
|
Pidfile string
|
2013-10-23 04:09:16 -04:00
|
|
|
Root string
|
2013-10-10 16:48:22 -04:00
|
|
|
AutoRestart bool
|
|
|
|
Dns []string
|
2014-02-07 11:48:14 -05:00
|
|
|
DnsSearch []string
|
2013-10-10 16:48:22 -04:00
|
|
|
EnableIptables bool
|
2014-01-27 23:35:05 -05:00
|
|
|
EnableIpForward bool
|
2013-10-10 16:48:22 -04:00
|
|
|
DefaultIp net.IP
|
2014-01-29 21:34:43 -05:00
|
|
|
BridgeIface string
|
|
|
|
BridgeIP string
|
2013-10-10 16:48:22 -04:00
|
|
|
InterContainerCommunication bool
|
2013-11-15 02:02:09 -05:00
|
|
|
GraphDriver string
|
2014-02-17 16:54:36 -05:00
|
|
|
ExecDriver string
|
2013-12-19 18:16:54 -05:00
|
|
|
Mtu int
|
2014-01-29 21:34:43 -05:00
|
|
|
DisableNetwork bool
|
2014-04-07 17:43:50 -04:00
|
|
|
EnableSelinuxSupport bool
|
2013-10-04 22:25:15 -04:00
|
|
|
}
|
2013-10-21 12:04:42 -04:00
|
|
|
|
2013-10-23 04:00:31 -04:00
|
|
|
// ConfigFromJob creates and returns a new DaemonConfig object
|
2013-10-21 12:04:42 -04:00
|
|
|
// by parsing the contents of a job's environment.
|
2014-03-07 18:22:23 -05:00
|
|
|
func ConfigFromJob(job *engine.Job) *Config {
|
|
|
|
config := &Config{
|
2014-01-30 15:45:32 -05:00
|
|
|
Pidfile: job.Getenv("Pidfile"),
|
|
|
|
Root: job.Getenv("Root"),
|
|
|
|
AutoRestart: job.GetenvBool("AutoRestart"),
|
|
|
|
EnableIptables: job.GetenvBool("EnableIptables"),
|
|
|
|
EnableIpForward: job.GetenvBool("EnableIpForward"),
|
2014-01-31 15:18:45 -05:00
|
|
|
BridgeIP: job.Getenv("BridgeIP"),
|
2014-02-05 14:19:48 -05:00
|
|
|
BridgeIface: job.Getenv("BridgeIface"),
|
2014-01-30 15:45:32 -05:00
|
|
|
DefaultIp: net.ParseIP(job.Getenv("DefaultIp")),
|
|
|
|
InterContainerCommunication: job.GetenvBool("InterContainerCommunication"),
|
|
|
|
GraphDriver: job.Getenv("GraphDriver"),
|
2014-02-17 16:54:36 -05:00
|
|
|
ExecDriver: job.Getenv("ExecDriver"),
|
2014-04-07 17:43:50 -04:00
|
|
|
EnableSelinuxSupport: false, // FIXME: hardcoded default to disable selinux for .10 release
|
2014-01-30 15:45:32 -05:00
|
|
|
}
|
2013-11-22 12:55:27 -05:00
|
|
|
if dns := job.GetenvList("Dns"); dns != nil {
|
|
|
|
config.Dns = dns
|
2013-10-21 12:04:42 -04:00
|
|
|
}
|
2014-02-07 11:48:14 -05:00
|
|
|
if dnsSearch := job.GetenvList("DnsSearch"); dnsSearch != nil {
|
|
|
|
config.DnsSearch = dnsSearch
|
|
|
|
}
|
2014-01-30 21:06:08 -05:00
|
|
|
if mtu := job.GetenvInt("Mtu"); mtu != 0 {
|
2013-12-19 18:16:54 -05:00
|
|
|
config.Mtu = mtu
|
|
|
|
} else {
|
2014-02-03 18:36:39 -05:00
|
|
|
config.Mtu = GetDefaultNetworkMtu()
|
2013-12-19 18:16:54 -05:00
|
|
|
}
|
2014-02-05 14:19:48 -05:00
|
|
|
config.DisableNetwork = config.BridgeIface == DisableNetworkBridge
|
2014-01-30 15:45:32 -05:00
|
|
|
|
|
|
|
return config
|
2013-10-21 12:04:42 -04:00
|
|
|
}
|
2014-02-01 06:38:39 -05:00
|
|
|
|
|
|
|
func GetDefaultNetworkMtu() int {
|
|
|
|
if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
|
|
|
|
return iface.MTU
|
|
|
|
}
|
|
|
|
return defaultNetworkMtu
|
|
|
|
}
|