mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove engine.Job from Start action.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
5395cdcae5
commit
610c436e07
5 changed files with 49 additions and 55 deletions
|
@ -926,7 +926,7 @@ func postContainersStart(eng *engine.Engine, version version.Version, w http.Res
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
name = vars["name"]
|
name = vars["name"]
|
||||||
job = eng.Job("start", name)
|
env = new(engine.Env)
|
||||||
)
|
)
|
||||||
|
|
||||||
// If contentLength is -1, we can assumed chunked encoding
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := job.DecodeEnv(r.Body); err != nil {
|
if err := env.Decode(r.Body); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := job.Run(); err != nil {
|
if err := getDaemon(eng).ContainerStart(name, env); err != nil {
|
||||||
if err.Error() == "Container already started" {
|
if err.Error() == "Container already started" {
|
||||||
w.WriteHeader(http.StatusNotModified)
|
w.WriteHeader(http.StatusNotModified)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -21,7 +21,7 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
config := runconfig.ContainerConfigFromJob(job)
|
config := runconfig.ContainerConfigFromJob(job)
|
||||||
hostConfig := runconfig.ContainerHostConfigFromJob(job)
|
hostConfig := runconfig.ContainerHostConfigFromJob(job.env)
|
||||||
|
|
||||||
if len(hostConfig.LxcConf) > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") {
|
if len(hostConfig.LxcConf) > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") {
|
||||||
return fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())
|
return fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())
|
||||||
|
|
|
@ -122,7 +122,8 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
||||||
"create": daemon.ContainerCreate,
|
"create": daemon.ContainerCreate,
|
||||||
"info": daemon.CmdInfo,
|
"info": daemon.CmdInfo,
|
||||||
"restart": daemon.ContainerRestart,
|
"restart": daemon.ContainerRestart,
|
||||||
"start": daemon.ContainerStart,
|
"stop": daemon.ContainerStop,
|
||||||
|
"wait": daemon.ContainerWait,
|
||||||
"execCreate": daemon.ContainerExecCreate,
|
"execCreate": daemon.ContainerExecCreate,
|
||||||
"execStart": daemon.ContainerExecStart,
|
"execStart": daemon.ContainerExecStart,
|
||||||
} {
|
} {
|
||||||
|
|
|
@ -7,14 +7,7 @@ import (
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (daemon *Daemon) ContainerStart(job *engine.Job) error {
|
func (daemon *Daemon) ContainerStart(name string, env *engine.Env) error {
|
||||||
if len(job.Args) < 1 {
|
|
||||||
return fmt.Errorf("Usage: %s container_id", job.Name)
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
name = job.Args[0]
|
|
||||||
)
|
|
||||||
|
|
||||||
container, err := daemon.Get(name)
|
container, err := daemon.Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -31,8 +24,8 @@ func (daemon *Daemon) ContainerStart(job *engine.Job) error {
|
||||||
// If no environment was set, then no hostconfig was passed.
|
// If no environment was set, then no hostconfig was passed.
|
||||||
// This is kept for backward compatibility - hostconfig should be passed when
|
// This is kept for backward compatibility - hostconfig should be passed when
|
||||||
// creating a container, not during start.
|
// creating a container, not during start.
|
||||||
if len(job.Environ()) > 0 {
|
if len(env.Map()) > 0 {
|
||||||
hostConfig := runconfig.ContainerHostConfigFromJob(job)
|
hostConfig := runconfig.ContainerHostConfigFromJob(env)
|
||||||
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,80 +152,80 @@ func MergeConfigs(config *Config, hostConfig *HostConfig) *ConfigAndHostConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
func ContainerHostConfigFromJob(env *engine.Env) *HostConfig {
|
||||||
if job.EnvExists("HostConfig") {
|
if env.Exists("HostConfig") {
|
||||||
hostConfig := HostConfig{}
|
hostConfig := HostConfig{}
|
||||||
job.GetenvJson("HostConfig", &hostConfig)
|
env.GetJson("HostConfig", &hostConfig)
|
||||||
|
|
||||||
// FIXME: These are for backward compatibility, if people use these
|
// FIXME: These are for backward compatibility, if people use these
|
||||||
// options with `HostConfig`, we should still make them workable.
|
// options with `HostConfig`, we should still make them workable.
|
||||||
if job.EnvExists("Memory") && hostConfig.Memory == 0 {
|
if env.Exists("Memory") && hostConfig.Memory == 0 {
|
||||||
hostConfig.Memory = job.GetenvInt64("Memory")
|
hostConfig.Memory = env.GetInt64("Memory")
|
||||||
}
|
}
|
||||||
if job.EnvExists("MemorySwap") && hostConfig.MemorySwap == 0 {
|
if env.Exists("MemorySwap") && hostConfig.MemorySwap == 0 {
|
||||||
hostConfig.MemorySwap = job.GetenvInt64("MemorySwap")
|
hostConfig.MemorySwap = env.GetInt64("MemorySwap")
|
||||||
}
|
}
|
||||||
if job.EnvExists("CpuShares") && hostConfig.CpuShares == 0 {
|
if env.Exists("CpuShares") && hostConfig.CpuShares == 0 {
|
||||||
hostConfig.CpuShares = job.GetenvInt64("CpuShares")
|
hostConfig.CpuShares = env.GetInt64("CpuShares")
|
||||||
}
|
}
|
||||||
if job.EnvExists("Cpuset") && hostConfig.CpusetCpus == "" {
|
if env.Exists("Cpuset") && hostConfig.CpusetCpus == "" {
|
||||||
hostConfig.CpusetCpus = job.Getenv("Cpuset")
|
hostConfig.CpusetCpus = env.Get("Cpuset")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &hostConfig
|
return &hostConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig := &HostConfig{
|
hostConfig := &HostConfig{
|
||||||
ContainerIDFile: job.Getenv("ContainerIDFile"),
|
ContainerIDFile: env.Get("ContainerIDFile"),
|
||||||
Memory: job.GetenvInt64("Memory"),
|
Memory: env.GetInt64("Memory"),
|
||||||
MemorySwap: job.GetenvInt64("MemorySwap"),
|
MemorySwap: env.GetInt64("MemorySwap"),
|
||||||
CpuShares: job.GetenvInt64("CpuShares"),
|
CpuShares: env.GetInt64("CpuShares"),
|
||||||
CpusetCpus: job.Getenv("CpusetCpus"),
|
CpusetCpus: env.Get("CpusetCpus"),
|
||||||
Privileged: job.GetenvBool("Privileged"),
|
Privileged: env.GetBool("Privileged"),
|
||||||
PublishAllPorts: job.GetenvBool("PublishAllPorts"),
|
PublishAllPorts: env.GetBool("PublishAllPorts"),
|
||||||
NetworkMode: NetworkMode(job.Getenv("NetworkMode")),
|
NetworkMode: NetworkMode(env.Get("NetworkMode")),
|
||||||
IpcMode: IpcMode(job.Getenv("IpcMode")),
|
IpcMode: IpcMode(env.Get("IpcMode")),
|
||||||
PidMode: PidMode(job.Getenv("PidMode")),
|
PidMode: PidMode(env.Get("PidMode")),
|
||||||
ReadonlyRootfs: job.GetenvBool("ReadonlyRootfs"),
|
ReadonlyRootfs: env.GetBool("ReadonlyRootfs"),
|
||||||
CgroupParent: job.Getenv("CgroupParent"),
|
CgroupParent: env.Get("CgroupParent"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This is for backward compatibility, if people use `Cpuset`
|
// FIXME: This is for backward compatibility, if people use `Cpuset`
|
||||||
// in json, make it workable, we will only pass hostConfig.CpusetCpus
|
// in json, make it workable, we will only pass hostConfig.CpusetCpus
|
||||||
// to execDriver.
|
// to execDriver.
|
||||||
if job.EnvExists("Cpuset") && hostConfig.CpusetCpus == "" {
|
if env.Exists("Cpuset") && hostConfig.CpusetCpus == "" {
|
||||||
hostConfig.CpusetCpus = job.Getenv("Cpuset")
|
hostConfig.CpusetCpus = env.Get("Cpuset")
|
||||||
}
|
}
|
||||||
|
|
||||||
job.GetenvJson("LxcConf", &hostConfig.LxcConf)
|
env.GetJson("LxcConf", &hostConfig.LxcConf)
|
||||||
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
env.GetJson("PortBindings", &hostConfig.PortBindings)
|
||||||
job.GetenvJson("Devices", &hostConfig.Devices)
|
env.GetJson("Devices", &hostConfig.Devices)
|
||||||
job.GetenvJson("RestartPolicy", &hostConfig.RestartPolicy)
|
env.GetJson("RestartPolicy", &hostConfig.RestartPolicy)
|
||||||
job.GetenvJson("Ulimits", &hostConfig.Ulimits)
|
env.GetJson("Ulimits", &hostConfig.Ulimits)
|
||||||
job.GetenvJson("LogConfig", &hostConfig.LogConfig)
|
env.GetJson("LogConfig", &hostConfig.LogConfig)
|
||||||
hostConfig.SecurityOpt = job.GetenvList("SecurityOpt")
|
hostConfig.SecurityOpt = env.GetList("SecurityOpt")
|
||||||
if Binds := job.GetenvList("Binds"); Binds != nil {
|
if Binds := env.GetList("Binds"); Binds != nil {
|
||||||
hostConfig.Binds = Binds
|
hostConfig.Binds = Binds
|
||||||
}
|
}
|
||||||
if Links := job.GetenvList("Links"); Links != nil {
|
if Links := env.GetList("Links"); Links != nil {
|
||||||
hostConfig.Links = Links
|
hostConfig.Links = Links
|
||||||
}
|
}
|
||||||
if Dns := job.GetenvList("Dns"); Dns != nil {
|
if Dns := env.GetList("Dns"); Dns != nil {
|
||||||
hostConfig.Dns = Dns
|
hostConfig.Dns = Dns
|
||||||
}
|
}
|
||||||
if DnsSearch := job.GetenvList("DnsSearch"); DnsSearch != nil {
|
if DnsSearch := env.GetList("DnsSearch"); DnsSearch != nil {
|
||||||
hostConfig.DnsSearch = DnsSearch
|
hostConfig.DnsSearch = DnsSearch
|
||||||
}
|
}
|
||||||
if ExtraHosts := job.GetenvList("ExtraHosts"); ExtraHosts != nil {
|
if ExtraHosts := env.GetList("ExtraHosts"); ExtraHosts != nil {
|
||||||
hostConfig.ExtraHosts = ExtraHosts
|
hostConfig.ExtraHosts = ExtraHosts
|
||||||
}
|
}
|
||||||
if VolumesFrom := job.GetenvList("VolumesFrom"); VolumesFrom != nil {
|
if VolumesFrom := env.GetList("VolumesFrom"); VolumesFrom != nil {
|
||||||
hostConfig.VolumesFrom = VolumesFrom
|
hostConfig.VolumesFrom = VolumesFrom
|
||||||
}
|
}
|
||||||
if CapAdd := job.GetenvList("CapAdd"); CapAdd != nil {
|
if CapAdd := env.GetList("CapAdd"); CapAdd != nil {
|
||||||
hostConfig.CapAdd = CapAdd
|
hostConfig.CapAdd = CapAdd
|
||||||
}
|
}
|
||||||
if CapDrop := job.GetenvList("CapDrop"); CapDrop != nil {
|
if CapDrop := env.GetList("CapDrop"); CapDrop != nil {
|
||||||
hostConfig.CapDrop = CapDrop
|
hostConfig.CapDrop = CapDrop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue