mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
create generic backend to cut dependency on daemon
- create a volume-specific interface that for the methods of daemon
that are used
- remove dependency on daemon package by volume package of server
- like 5087977fc1
Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
This commit is contained in:
parent
6d5e47a690
commit
836df9c446
3 changed files with 24 additions and 9 deletions
16
api/server/router/volume/backend.go
Normal file
16
api/server/router/volume/backend.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue