Move the canonical run configuration objects to a sub-package

* Config is now runconfig.Config
    * HostConfig is now runconfig.HostConfig
    * MergeConfig is now runconfig.Merge
    * CompareConfig is now runconfig.Compare
    * ParseRun is now runconfig.Parse
    * ContainerConfigFromJob is now runconfig.ContainerConfigFromJob
    * ContainerHostConfigFromJob is now runconfig.ContainerHostConfigFromJob

This facilitates refactoring commands.go and shrinks the core.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes
2014-02-11 20:18:46 -08:00
parent 9a9690360c
commit 6393c38339
23 changed files with 731 additions and 674 deletions
+9 -8
View File
@@ -10,6 +10,7 @@ import (
"github.com/dotcloud/docker/engine"
"github.com/dotcloud/docker/pkg/graphdb"
"github.com/dotcloud/docker/registry"
"github.com/dotcloud/docker/runconfig"
"github.com/dotcloud/docker/utils"
"io"
"io/ioutil"
@@ -662,7 +663,7 @@ func (srv *Server) ImageInsert(job *engine.Job) engine.Status {
}
defer file.Body.Close()
config, _, _, err := ParseRun([]string{img.ID, "echo", "insert", url, path}, srv.runtime.sysInfo)
config, _, _, err := runconfig.Parse([]string{img.ID, "echo", "insert", url, path}, srv.runtime.sysInfo)
if err != nil {
return job.Error(err)
}
@@ -1043,7 +1044,7 @@ func (srv *Server) ContainerCommit(job *engine.Job) engine.Status {
if container == nil {
return job.Errorf("No such container: %s", name)
}
var config Config
var config runconfig.Config
if err := job.GetenvJson("config", &config); err != nil {
return job.Error(err)
}
@@ -1623,7 +1624,7 @@ func (srv *Server) ContainerCreate(job *engine.Job) engine.Status {
} else if len(job.Args) > 1 {
return job.Errorf("Usage: %s", job.Name)
}
config := ContainerConfigFromJob(job)
config := runconfig.ContainerConfigFromJob(job)
if config.Memory != 0 && config.Memory < 524288 {
return job.Errorf("Minimum memory limit allowed is 512k")
}
@@ -1989,7 +1990,7 @@ func (srv *Server) canDeleteImage(imgID string) error {
return nil
}
func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error) {
func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*Image, error) {
// Retrieve all images
images, err := srv.runtime.graph.Map()
@@ -2013,7 +2014,7 @@ func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error)
if err != nil {
return nil, err
}
if CompareConfig(&img.ContainerConfig, config) {
if runconfig.Compare(&img.ContainerConfig, config) {
if match == nil || match.Created.Before(img.Created) {
match = img
}
@@ -2022,7 +2023,7 @@ func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error)
return match, nil
}
func (srv *Server) RegisterLinks(container *Container, hostConfig *HostConfig) error {
func (srv *Server) RegisterLinks(container *Container, hostConfig *runconfig.HostConfig) error {
runtime := srv.runtime
if hostConfig != nil && hostConfig.Links != nil {
@@ -2066,7 +2067,7 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
}
// If no environment was set, then no hostconfig was passed.
if len(job.Environ()) > 0 {
hostConfig := ContainerHostConfigFromJob(job)
hostConfig := runconfig.ContainerHostConfigFromJob(job)
// Validate the HostConfig binds. Make sure that:
// 1) the source of a bind mount isn't /
// The bind mount "/:/foo" isn't allowed.
@@ -2310,7 +2311,7 @@ func (srv *Server) JobInspect(job *engine.Job) engine.Status {
}
object = &struct {
*Container
HostConfig *HostConfig
HostConfig *runconfig.HostConfig
}{container, container.hostConfig}
default:
return job.Errorf("Unknown kind: %s", kind)