refactor all *FromJob functions

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-01-30 20:45:32 +00:00
parent 187646127f
commit 9261511aa5
3 changed files with 46 additions and 41 deletions

View file

@ -23,29 +23,31 @@ type DaemonConfig struct {
// ConfigFromJob creates and returns a new DaemonConfig object
// by parsing the contents of a job's environment.
func ConfigFromJob(job *engine.Job) *DaemonConfig {
var config DaemonConfig
config.Pidfile = job.Getenv("Pidfile")
config.Root = job.Getenv("Root")
config.AutoRestart = job.GetenvBool("AutoRestart")
func DaemonConfigFromJob(job *engine.Job) *DaemonConfig {
config := &DaemonConfig{
Pidfile: job.Getenv("Pidfile"),
Root: job.Getenv("Root"),
AutoRestart: job.GetenvBool("AutoRestart"),
EnableIptables: job.GetenvBool("EnableIptables"),
EnableIpForward: job.GetenvBool("EnableIpForward"),
BridgeIp: job.Getenv("BridgeIp"),
DefaultIp: net.ParseIP(job.Getenv("DefaultIp")),
InterContainerCommunication: job.GetenvBool("InterContainerCommunication"),
GraphDriver: job.Getenv("GraphDriver"),
}
if dns := job.GetenvList("Dns"); dns != nil {
config.Dns = dns
}
config.EnableIptables = job.GetenvBool("EnableIptables")
config.EnableIpForward = job.GetenvBool("EnableIpForward")
if br := job.Getenv("BridgeIface"); br != "" {
config.BridgeIface = br
} else {
config.BridgeIface = DefaultNetworkBridge
}
config.BridgeIp = job.Getenv("BridgeIp")
config.DefaultIp = net.ParseIP(job.Getenv("DefaultIp"))
config.InterContainerCommunication = job.GetenvBool("InterContainerCommunication")
config.GraphDriver = job.Getenv("GraphDriver")
if mtu := job.GetenvInt("Mtu"); mtu != -1 {
config.Mtu = mtu
} else {
config.Mtu = DefaultNetworkMtu
}
return &config
return config
}

View file

@ -105,23 +105,29 @@ type Config struct {
}
func ContainerConfigFromJob(job *engine.Job) *Config {
var config Config
config.Hostname = job.Getenv("Hostname")
config.Domainname = job.Getenv("Domainname")
config.User = job.Getenv("User")
config.Memory = job.GetenvInt64("Memory")
config.MemorySwap = job.GetenvInt64("MemorySwap")
config.CpuShares = job.GetenvInt64("CpuShares")
config.AttachStdin = job.GetenvBool("AttachStdin")
config.AttachStdout = job.GetenvBool("AttachStdout")
config.AttachStderr = job.GetenvBool("AttachStderr")
config := &Config{
Hostname: job.Getenv("Hostname"),
Domainname: job.Getenv("Domainname"),
User: job.Getenv("User"),
Memory: job.GetenvInt64("Memory"),
MemorySwap: job.GetenvInt64("MemorySwap"),
CpuShares: job.GetenvInt64("CpuShares"),
AttachStdin: job.GetenvBool("AttachStdin"),
AttachStdout: job.GetenvBool("AttachStdout"),
AttachStderr: job.GetenvBool("AttachStderr"),
Tty: job.GetenvBool("Tty"),
OpenStdin: job.GetenvBool("OpenStdin"),
StdinOnce: job.GetenvBool("StdinOnce"),
Image: job.Getenv("Image"),
VolumesFrom: job.Getenv("VolumesFrom"),
WorkingDir: job.Getenv("WorkingDir"),
NetworkDisabled: job.GetenvBool("NetworkDisabled"),
}
job.GetenvJson("ExposedPorts", &config.ExposedPorts)
job.GetenvJson("Volumes", &config.Volumes)
if PortSpecs := job.GetenvList("PortSpecs"); PortSpecs != nil {
config.PortSpecs = PortSpecs
}
job.GetenvJson("ExposedPorts", &config.ExposedPorts)
config.Tty = job.GetenvBool("Tty")
config.OpenStdin = job.GetenvBool("OpenStdin")
config.StdinOnce = job.GetenvBool("StdinOnce")
if Env := job.GetenvList("Env"); Env != nil {
config.Env = Env
}
@ -131,15 +137,11 @@ func ContainerConfigFromJob(job *engine.Job) *Config {
if Dns := job.GetenvList("Dns"); Dns != nil {
config.Dns = Dns
}
config.Image = job.Getenv("Image")
job.GetenvJson("Volumes", &config.Volumes)
config.VolumesFrom = job.Getenv("VolumesFrom")
config.WorkingDir = job.Getenv("WorkingDir")
if Entrypoint := job.GetenvList("Entrypoint"); Entrypoint != nil {
config.Entrypoint = Entrypoint
}
config.NetworkDisabled = job.GetenvBool("NetworkDisabled")
return &config
return config
}
type HostConfig struct {
@ -153,19 +155,21 @@ type HostConfig struct {
}
func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
var hostConfig HostConfig
hostConfig := &HostConfig{
ContainerIDFile: job.Getenv("ContainerIDFile"),
Privileged: job.GetenvBool("Privileged"),
PublishAllPorts: job.GetenvBool("PublishAllPorts"),
}
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
if Binds := job.GetenvList("Binds"); Binds != nil {
hostConfig.Binds = Binds
}
hostConfig.ContainerIDFile = job.Getenv("ContainerIDFile")
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
hostConfig.Privileged = job.GetenvBool("Privileged")
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
if Links := job.GetenvList("Links"); Links != nil {
hostConfig.Links = Links
}
hostConfig.PublishAllPorts = job.GetenvBool("PublishAllPorts")
return &hostConfig
return hostConfig
}
type BindMap struct {

View file

@ -42,8 +42,7 @@ func init() {
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
func jobInitApi(job *engine.Job) engine.Status {
job.Logf("Creating server")
// FIXME: ImportEnv deprecates ConfigFromJob
srv, err := NewServer(job.Eng, ConfigFromJob(job))
srv, err := NewServer(job.Eng, DaemonConfigFromJob(job))
if err != nil {
job.Error(err)
return engine.StatusErr