Remove engine.Job from Start action.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-04-09 14:27:12 -07:00
parent 5395cdcae5
commit 610c436e07
5 changed files with 49 additions and 55 deletions

View file

@ -926,7 +926,7 @@ func postContainersStart(eng *engine.Engine, version version.Version, w http.Res
}
var (
name = vars["name"]
job = eng.Job("start", name)
env = new(engine.Env)
)
// If contentLength is -1, we can assumed chunked encoding
@ -940,12 +940,12 @@ func postContainersStart(eng *engine.Engine, version version.Version, w http.Res
return err
}
if err := job.DecodeEnv(r.Body); err != nil {
if err := env.Decode(r.Body); err != nil {
return err
}
}
if err := job.Run(); err != nil {
if err := getDaemon(eng).ContainerStart(name, env); err != nil {
if err.Error() == "Container already started" {
w.WriteHeader(http.StatusNotModified)
return nil

View file

@ -21,7 +21,7 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) error {
}
config := runconfig.ContainerConfigFromJob(job)
hostConfig := runconfig.ContainerHostConfigFromJob(job)
hostConfig := runconfig.ContainerHostConfigFromJob(job.env)
if len(hostConfig.LxcConf) > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") {
return fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())

View file

@ -122,7 +122,8 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
"create": daemon.ContainerCreate,
"info": daemon.CmdInfo,
"restart": daemon.ContainerRestart,
"start": daemon.ContainerStart,
"stop": daemon.ContainerStop,
"wait": daemon.ContainerWait,
"execCreate": daemon.ContainerExecCreate,
"execStart": daemon.ContainerExecStart,
} {

View file

@ -7,14 +7,7 @@ import (
"github.com/docker/docker/runconfig"
)
func (daemon *Daemon) ContainerStart(job *engine.Job) error {
if len(job.Args) < 1 {
return fmt.Errorf("Usage: %s container_id", job.Name)
}
var (
name = job.Args[0]
)
func (daemon *Daemon) ContainerStart(name string, env *engine.Env) error {
container, err := daemon.Get(name)
if err != nil {
return err
@ -31,8 +24,8 @@ func (daemon *Daemon) ContainerStart(job *engine.Job) error {
// If no environment was set, then no hostconfig was passed.
// This is kept for backward compatibility - hostconfig should be passed when
// creating a container, not during start.
if len(job.Environ()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if len(env.Map()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(env)
if err := daemon.setHostConfig(container, hostConfig); err != nil {
return err
}

View file

@ -152,80 +152,80 @@ func MergeConfigs(config *Config, hostConfig *HostConfig) *ConfigAndHostConfig {
}
}
func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
if job.EnvExists("HostConfig") {
func ContainerHostConfigFromJob(env *engine.Env) *HostConfig {
if env.Exists("HostConfig") {
hostConfig := HostConfig{}
job.GetenvJson("HostConfig", &hostConfig)
env.GetJson("HostConfig", &hostConfig)
// FIXME: These are for backward compatibility, if people use these
// options with `HostConfig`, we should still make them workable.
if job.EnvExists("Memory") && hostConfig.Memory == 0 {
hostConfig.Memory = job.GetenvInt64("Memory")
if env.Exists("Memory") && hostConfig.Memory == 0 {
hostConfig.Memory = env.GetInt64("Memory")
}
if job.EnvExists("MemorySwap") && hostConfig.MemorySwap == 0 {
hostConfig.MemorySwap = job.GetenvInt64("MemorySwap")
if env.Exists("MemorySwap") && hostConfig.MemorySwap == 0 {
hostConfig.MemorySwap = env.GetInt64("MemorySwap")
}
if job.EnvExists("CpuShares") && hostConfig.CpuShares == 0 {
hostConfig.CpuShares = job.GetenvInt64("CpuShares")
if env.Exists("CpuShares") && hostConfig.CpuShares == 0 {
hostConfig.CpuShares = env.GetInt64("CpuShares")
}
if job.EnvExists("Cpuset") && hostConfig.CpusetCpus == "" {
hostConfig.CpusetCpus = job.Getenv("Cpuset")
if env.Exists("Cpuset") && hostConfig.CpusetCpus == "" {
hostConfig.CpusetCpus = env.Get("Cpuset")
}
return &hostConfig
}
hostConfig := &HostConfig{
ContainerIDFile: job.Getenv("ContainerIDFile"),
Memory: job.GetenvInt64("Memory"),
MemorySwap: job.GetenvInt64("MemorySwap"),
CpuShares: job.GetenvInt64("CpuShares"),
CpusetCpus: job.Getenv("CpusetCpus"),
Privileged: job.GetenvBool("Privileged"),
PublishAllPorts: job.GetenvBool("PublishAllPorts"),
NetworkMode: NetworkMode(job.Getenv("NetworkMode")),
IpcMode: IpcMode(job.Getenv("IpcMode")),
PidMode: PidMode(job.Getenv("PidMode")),
ReadonlyRootfs: job.GetenvBool("ReadonlyRootfs"),
CgroupParent: job.Getenv("CgroupParent"),
ContainerIDFile: env.Get("ContainerIDFile"),
Memory: env.GetInt64("Memory"),
MemorySwap: env.GetInt64("MemorySwap"),
CpuShares: env.GetInt64("CpuShares"),
CpusetCpus: env.Get("CpusetCpus"),
Privileged: env.GetBool("Privileged"),
PublishAllPorts: env.GetBool("PublishAllPorts"),
NetworkMode: NetworkMode(env.Get("NetworkMode")),
IpcMode: IpcMode(env.Get("IpcMode")),
PidMode: PidMode(env.Get("PidMode")),
ReadonlyRootfs: env.GetBool("ReadonlyRootfs"),
CgroupParent: env.Get("CgroupParent"),
}
// FIXME: This is for backward compatibility, if people use `Cpuset`
// in json, make it workable, we will only pass hostConfig.CpusetCpus
// to execDriver.
if job.EnvExists("Cpuset") && hostConfig.CpusetCpus == "" {
hostConfig.CpusetCpus = job.Getenv("Cpuset")
if env.Exists("Cpuset") && hostConfig.CpusetCpus == "" {
hostConfig.CpusetCpus = env.Get("Cpuset")
}
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
job.GetenvJson("Devices", &hostConfig.Devices)
job.GetenvJson("RestartPolicy", &hostConfig.RestartPolicy)
job.GetenvJson("Ulimits", &hostConfig.Ulimits)
job.GetenvJson("LogConfig", &hostConfig.LogConfig)
hostConfig.SecurityOpt = job.GetenvList("SecurityOpt")
if Binds := job.GetenvList("Binds"); Binds != nil {
env.GetJson("LxcConf", &hostConfig.LxcConf)
env.GetJson("PortBindings", &hostConfig.PortBindings)
env.GetJson("Devices", &hostConfig.Devices)
env.GetJson("RestartPolicy", &hostConfig.RestartPolicy)
env.GetJson("Ulimits", &hostConfig.Ulimits)
env.GetJson("LogConfig", &hostConfig.LogConfig)
hostConfig.SecurityOpt = env.GetList("SecurityOpt")
if Binds := env.GetList("Binds"); Binds != nil {
hostConfig.Binds = Binds
}
if Links := job.GetenvList("Links"); Links != nil {
if Links := env.GetList("Links"); Links != nil {
hostConfig.Links = Links
}
if Dns := job.GetenvList("Dns"); Dns != nil {
if Dns := env.GetList("Dns"); Dns != nil {
hostConfig.Dns = Dns
}
if DnsSearch := job.GetenvList("DnsSearch"); DnsSearch != nil {
if DnsSearch := env.GetList("DnsSearch"); DnsSearch != nil {
hostConfig.DnsSearch = DnsSearch
}
if ExtraHosts := job.GetenvList("ExtraHosts"); ExtraHosts != nil {
if ExtraHosts := env.GetList("ExtraHosts"); ExtraHosts != nil {
hostConfig.ExtraHosts = ExtraHosts
}
if VolumesFrom := job.GetenvList("VolumesFrom"); VolumesFrom != nil {
if VolumesFrom := env.GetList("VolumesFrom"); VolumesFrom != nil {
hostConfig.VolumesFrom = VolumesFrom
}
if CapAdd := job.GetenvList("CapAdd"); CapAdd != nil {
if CapAdd := env.GetList("CapAdd"); CapAdd != nil {
hostConfig.CapAdd = CapAdd
}
if CapDrop := job.GetenvList("CapDrop"); CapDrop != nil {
if CapDrop := env.GetList("CapDrop"); CapDrop != nil {
hostConfig.CapDrop = CapDrop
}