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