From 8031c23b0f492b6f62dfc226dbf9b3d051d9546a Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 31 Jul 2014 20:29:38 +0000 Subject: [PATCH] Move "export" to daemon/export.go This is part of an effort to break apart the deprecated server/ package Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- daemon/daemon.go | 3 +++ daemon/export.go | 30 ++++++++++++++++++++++++++++++ server/container.go | 23 ----------------------- server/init.go | 1 - 4 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 daemon/export.go diff --git a/daemon/daemon.go b/daemon/daemon.go index 3876027ca6..39c2eec15b 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -120,6 +120,9 @@ func (daemon *Daemon) Install(eng *engine.Engine) error { if err := eng.Register("kill", daemon.ContainerKill); err != nil { return err } + if err := eng.Register("export", daemon.ContainerExport); err != nil { + return err + } return nil } diff --git a/daemon/export.go b/daemon/export.go new file mode 100644 index 0000000000..204e862d5c --- /dev/null +++ b/daemon/export.go @@ -0,0 +1,30 @@ +package daemon + +import ( + "io" + + "github.com/docker/docker/engine" +) + +func (daemon *Daemon) ContainerExport(job *engine.Job) engine.Status { + if len(job.Args) != 1 { + return job.Errorf("Usage: %s container_id", job.Name) + } + name := job.Args[0] + if container := daemon.Get(name); container != nil { + data, err := container.Export() + if err != nil { + return job.Errorf("%s: %s", name, err) + } + defer data.Close() + + // Stream the entire contents of the container (basically a volatile snapshot) + if _, err := io.Copy(job.Stdout, data); err != nil { + return job.Errorf("%s: %s", name, err) + } + // FIXME: factor job-specific LogEvent to engine.Job.Run() + job.Eng.Job("log", "export", container.ID, daemon.Repositories().ImageName(container.Image)).Run() + return engine.StatusOK + } + return job.Errorf("No such container: %s", name) +} diff --git a/server/container.go b/server/container.go index a5ab85b2a7..cef405387c 100644 --- a/server/container.go +++ b/server/container.go @@ -29,29 +29,6 @@ import ( "github.com/docker/docker/utils" ) -func (srv *Server) ContainerExport(job *engine.Job) engine.Status { - if len(job.Args) != 1 { - return job.Errorf("Usage: %s container_id", job.Name) - } - name := job.Args[0] - if container := srv.daemon.Get(name); container != nil { - data, err := container.Export() - if err != nil { - return job.Errorf("%s: %s", name, err) - } - defer data.Close() - - // Stream the entire contents of the container (basically a volatile snapshot) - if _, err := io.Copy(job.Stdout, data); err != nil { - return job.Errorf("%s: %s", name, err) - } - // FIXME: factor job-specific LogEvent to engine.Job.Run() - srv.LogEvent("export", container.ID, srv.daemon.Repositories().ImageName(container.Image)) - return engine.StatusOK - } - return job.Errorf("No such container: %s", name) -} - func (srv *Server) ContainerTop(job *engine.Job) engine.Status { if len(job.Args) != 1 && len(job.Args) != 2 { return job.Errorf("Not enough arguments. Usage: %s CONTAINER [PS_ARGS]\n", job.Name) diff --git a/server/init.go b/server/init.go index 5fdc542fe6..a172d55c68 100644 --- a/server/init.go +++ b/server/init.go @@ -86,7 +86,6 @@ func InitServer(job *engine.Job) engine.Status { job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon) for name, handler := range map[string]engine.Handler{ - "export": srv.ContainerExport, "create": srv.ContainerCreate, "stop": srv.ContainerStop, "restart": srv.ContainerRestart,