commit
59df776469
3 changed files with 73 additions and 37 deletions
55
api.go
55
api.go
|
@ -751,8 +751,18 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
|
|||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
|
||||
c, err := srv.ContainerInspect(vars["name"])
|
||||
if err != nil {
|
||||
// TODO: replace the buffer by job.AddEnv()
|
||||
var (
|
||||
job = srv.Eng.Job("inspect", vars["name"], "container")
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
c Container
|
||||
)
|
||||
job.Stdout.Add(buffer)
|
||||
if err := job.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(buffer.Bytes(), &c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -786,7 +796,7 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
|
|||
errStream = outStream
|
||||
}
|
||||
|
||||
job := srv.Eng.Job("attach", vars["name"])
|
||||
job = srv.Eng.Job("attach", vars["name"])
|
||||
job.Setenv("logs", r.Form.Get("logs"))
|
||||
job.Setenv("stream", r.Form.Get("stream"))
|
||||
job.Setenv("stdin", r.Form.Get("stdin"))
|
||||
|
@ -810,7 +820,7 @@ func wsContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *
|
|||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
|
||||
if _, err := srv.ContainerInspect(vars["name"]); err != nil {
|
||||
if err := srv.Eng.Job("inspect", vars["name"], "container").Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -838,41 +848,20 @@ func getContainersByName(srv *Server, version float64, w http.ResponseWriter, r
|
|||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
name := vars["name"]
|
||||
|
||||
container, err := srv.ContainerInspect(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = srv.ImageInspect(name)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Conflict between containers and images")
|
||||
}
|
||||
|
||||
container.readHostConfig()
|
||||
c := APIContainer{container, container.hostConfig}
|
||||
|
||||
return writeJSON(w, http.StatusOK, c)
|
||||
var job = srv.Eng.Job("inspect", vars["name"], "container")
|
||||
job.Stdout.Add(w)
|
||||
job.SetenvBool("conflict", true) //conflict=true to detect conflict between containers and images in the job
|
||||
return job.Run()
|
||||
}
|
||||
|
||||
func getImagesByName(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
name := vars["name"]
|
||||
|
||||
image, err := srv.ImageInspect(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = srv.ContainerInspect(name)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Conflict between containers and images")
|
||||
}
|
||||
|
||||
return writeJSON(w, http.StatusOK, image)
|
||||
var job = srv.Eng.Job("inspect", vars["name"], "image")
|
||||
job.Stdout.Add(w)
|
||||
job.SetenvBool("conflict", true) //conflict=true to detect conflict between containers and images in the job
|
||||
return job.Run()
|
||||
}
|
||||
|
||||
func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
|
|
@ -67,10 +67,6 @@ type (
|
|||
Resource string
|
||||
HostPath string
|
||||
}
|
||||
APIContainer struct {
|
||||
*Container
|
||||
HostConfig *HostConfig
|
||||
}
|
||||
)
|
||||
|
||||
func (api APIContainers) ToLegacy() *APIContainersOld {
|
||||
|
|
51
server.go
51
server.go
|
@ -100,6 +100,7 @@ func jobInitApi(job *engine.Job) engine.Status {
|
|||
"pull": srv.ImagePull,
|
||||
"import": srv.ImageImport,
|
||||
"image_delete": srv.ImageDelete,
|
||||
"inspect": srv.JobInspect,
|
||||
} {
|
||||
if err := job.Eng.Register(name, handler); err != nil {
|
||||
job.Error(err)
|
||||
|
@ -2310,6 +2311,56 @@ func (srv *Server) ImageInspect(name string) (*Image, error) {
|
|||
return nil, fmt.Errorf("No such image: %s", name)
|
||||
}
|
||||
|
||||
func (srv *Server) JobInspect(job *engine.Job) engine.Status {
|
||||
// TODO: deprecate KIND/conflict
|
||||
if n := len(job.Args); n != 2 {
|
||||
job.Errorf("Usage: %s CONTAINER|IMAGE KIND", job.Name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
var (
|
||||
name = job.Args[0]
|
||||
kind = job.Args[1]
|
||||
object interface{}
|
||||
conflict = job.GetenvBool("conflict") //should the job detect conflict between containers and images
|
||||
image, errImage = srv.ImageInspect(name)
|
||||
container, errContainer = srv.ContainerInspect(name)
|
||||
)
|
||||
|
||||
if conflict && image != nil && container != nil {
|
||||
job.Errorf("Conflict between containers and images")
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
||||
switch kind {
|
||||
case "image":
|
||||
if errImage != nil {
|
||||
job.Error(errImage)
|
||||
return engine.StatusErr
|
||||
}
|
||||
object = image
|
||||
case "container":
|
||||
if errContainer != nil {
|
||||
job.Error(errContainer)
|
||||
return engine.StatusErr
|
||||
}
|
||||
object = &struct {
|
||||
*Container
|
||||
HostConfig *HostConfig
|
||||
}{container, container.hostConfig}
|
||||
default:
|
||||
job.Errorf("Unknown kind: %s", kind)
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
||||
b, err := json.Marshal(object)
|
||||
if err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
job.Stdout.Write(b)
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) ContainerCopy(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 2 {
|
||||
job.Errorf("Usage: %s CONTAINER RESOURCE\n", job.Name)
|
||||
|
|
Loading…
Reference in a new issue