diff --git a/api/server/router/volume/backend.go b/api/server/router/volume/backend.go new file mode 100644 index 0000000000..aa69972cfc --- /dev/null +++ b/api/server/router/volume/backend.go @@ -0,0 +1,16 @@ +package volume + +import ( + // TODO return types need to be refactored into pkg + "github.com/docker/docker/api/types" +) + +// Backend is the methods that need to be implemented to provide +// volume specific functionality +type Backend interface { + Volumes(filter string) ([]*types.Volume, error) + VolumeInspect(name string) (*types.Volume, error) + VolumeCreate(name, driverName string, + opts map[string]string) (*types.Volume, error) + VolumeRm(name string) error +} diff --git a/api/server/router/volume/volume.go b/api/server/router/volume/volume.go index ca1ea0e8ad..8ea757fad2 100644 --- a/api/server/router/volume/volume.go +++ b/api/server/router/volume/volume.go @@ -3,19 +3,18 @@ package volume import ( "github.com/docker/docker/api/server/router" "github.com/docker/docker/api/server/router/local" - "github.com/docker/docker/daemon" ) // volumesRouter is a router to talk with the volumes controller type volumeRouter struct { - daemon *daemon.Daemon - routes []router.Route + backend Backend + routes []router.Route } // NewRouter initializes a new volumes router -func NewRouter(d *daemon.Daemon) router.Router { +func NewRouter(b Backend) router.Router { r := &volumeRouter{ - daemon: d, + backend: b, } r.initRoutes() return r diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index 021b3fa5ca..5b0787c57a 100644 --- a/api/server/router/volume/volume_routes.go +++ b/api/server/router/volume/volume_routes.go @@ -14,7 +14,7 @@ func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter return err } - volumes, err := v.daemon.Volumes(r.Form.Get("filters")) + volumes, err := v.backend.Volumes(r.Form.Get("filters")) if err != nil { return err } @@ -26,7 +26,7 @@ func (v *volumeRouter) getVolumeByName(ctx context.Context, w http.ResponseWrite return err } - volume, err := v.daemon.VolumeInspect(vars["name"]) + volume, err := v.backend.VolumeInspect(vars["name"]) if err != nil { return err } @@ -47,7 +47,7 @@ func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWri return err } - volume, err := v.daemon.VolumeCreate(req.Name, req.Driver, req.DriverOpts) + volume, err := v.backend.VolumeCreate(req.Name, req.Driver, req.DriverOpts) if err != nil { return err } @@ -58,7 +58,7 @@ func (v *volumeRouter) deleteVolumes(ctx context.Context, w http.ResponseWriter, if err := httputils.ParseForm(r); err != nil { return err } - if err := v.daemon.VolumeRm(vars["name"]); err != nil { + if err := v.backend.VolumeRm(vars["name"]); err != nil { return err } w.WriteHeader(http.StatusNoContent)