mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Refactor server to use daemon as the service layer in controllers
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
parent
e1df16b3a3
commit
c7cfdb65aa
6 changed files with 82 additions and 46 deletions
|
@ -306,17 +306,10 @@ func (s *Server) postContainersPause(version version.Version, w http.ResponseWri
|
|||
return err
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
cont, err := s.daemon.Get(name)
|
||||
if err != nil {
|
||||
if err := s.daemon.ContainerPause(vars["name"]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cont.Pause(); err != nil {
|
||||
return fmt.Errorf("Cannot pause container %s: %s", name, err)
|
||||
}
|
||||
cont.LogEvent("pause")
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
return nil
|
||||
|
@ -330,17 +323,10 @@ func (s *Server) postContainersUnpause(version version.Version, w http.ResponseW
|
|||
return err
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
cont, err := s.daemon.Get(name)
|
||||
if err != nil {
|
||||
if err := s.daemon.ContainerUnpause(vars["name"]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cont.Unpause(); err != nil {
|
||||
return fmt.Errorf("Cannot unpause container %s: %s", name, err)
|
||||
}
|
||||
cont.LogEvent("unpause")
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
return nil
|
||||
|
@ -529,13 +515,7 @@ func (s *Server) getContainersChanges(version version.Version, w http.ResponseWr
|
|||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
cont, err := s.daemon.Get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
changes, err := cont.Changes()
|
||||
changes, err := s.daemon.ContainerChanges(vars["name"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1112,12 +1092,7 @@ func (s *Server) postContainersResize(version version.Version, w http.ResponseWr
|
|||
return err
|
||||
}
|
||||
|
||||
cont, err := s.daemon.Get(vars["name"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cont.Resize(height, width)
|
||||
return s.daemon.ContainerResize(vars["name"], height, width)
|
||||
}
|
||||
|
||||
func (s *Server) postContainersAttach(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
@ -1371,30 +1346,19 @@ func (s *Server) postContainersCopy(version version.Version, w http.ResponseWrit
|
|||
return fmt.Errorf("Path cannot be empty")
|
||||
}
|
||||
|
||||
res := cfg.Resource
|
||||
|
||||
if res[0] == '/' {
|
||||
res = res[1:]
|
||||
}
|
||||
|
||||
cont, err := s.daemon.Get(vars["name"])
|
||||
data, err := s.daemon.ContainerCopy(vars["name"], cfg.Resource)
|
||||
if err != nil {
|
||||
logrus.Errorf("%v", err)
|
||||
if strings.Contains(strings.ToLower(err.Error()), "no such id") {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
data, err := cont.Copy(res)
|
||||
if err != nil {
|
||||
logrus.Errorf("%v", err)
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("Could not find the file %s in container %s", cfg.Resource, vars["name"])
|
||||
}
|
||||
return err
|
||||
}
|
||||
defer data.Close()
|
||||
|
||||
w.Header().Set("Content-Type", "application/x-tar")
|
||||
if _, err := io.Copy(w, data); err != nil {
|
||||
return err
|
||||
|
|
13
daemon/changes.go
Normal file
13
daemon/changes.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package daemon
|
||||
|
||||
import "github.com/docker/docker/pkg/archive"
|
||||
|
||||
// ContainerChanges returns a list of container fs changes
|
||||
func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return container.Changes()
|
||||
}
|
16
daemon/copy.go
Normal file
16
daemon/copy.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package daemon
|
||||
|
||||
import "io"
|
||||
|
||||
func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res[0] == '/' {
|
||||
res = res[1:]
|
||||
}
|
||||
|
||||
return container.Copy(res)
|
||||
}
|
18
daemon/pause.go
Normal file
18
daemon/pause.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package daemon
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ContainerPause pauses a container
|
||||
func (daemon *Daemon) ContainerPause(name string) error {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Pause(); err != nil {
|
||||
return fmt.Errorf("Cannot pause container %s: %s", name, err)
|
||||
}
|
||||
container.LogEvent("pause")
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,12 +1,19 @@
|
|||
package daemon
|
||||
|
||||
func (daemon *Daemon) ContainerResize(name string, height, width int) error {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return container.Resize(height, width)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) ContainerExecResize(name string, height, width int) error {
|
||||
execConfig, err := daemon.getExecConfig(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := execConfig.Resize(height, width); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
return execConfig.Resize(height, width)
|
||||
}
|
||||
|
|
18
daemon/unpause.go
Normal file
18
daemon/unpause.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package daemon
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ContainerUnpause unpauses a container
|
||||
func (daemon *Daemon) ContainerUnpause(name string) error {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Unpause(); err != nil {
|
||||
return fmt.Errorf("Cannot unpause container %s: %s", name, err)
|
||||
}
|
||||
container.LogEvent("unpause")
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue