mirror of https://github.com/docker/docs.git
use go-generate to build volume/driver/proxy.go
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
4c81c9dddc
commit
88e4dff9a9
|
@ -1,20 +1,23 @@
|
||||||
|
//go:generate pluginrpc-gen -i $GOFILE -o proxy.go -type VolumeDriver -name VolumeDriver
|
||||||
|
|
||||||
package volumedrivers
|
package volumedrivers
|
||||||
|
|
||||||
import "github.com/docker/docker/volume"
|
import "github.com/docker/docker/volume"
|
||||||
|
|
||||||
type client interface {
|
|
||||||
Call(string, interface{}, interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewVolumeDriver(name string, c client) volume.Driver {
|
func NewVolumeDriver(name string, c client) volume.Driver {
|
||||||
proxy := &volumeDriverProxy{c}
|
proxy := &volumeDriverProxy{c}
|
||||||
return &volumeDriverAdapter{name, proxy}
|
return &volumeDriverAdapter{name, proxy}
|
||||||
}
|
}
|
||||||
|
|
||||||
type VolumeDriver interface {
|
type VolumeDriver interface {
|
||||||
|
// Create a volume with the given name
|
||||||
Create(name string) (err error)
|
Create(name string) (err error)
|
||||||
|
// Remove the volume with the given name
|
||||||
Remove(name string) (err error)
|
Remove(name string) (err error)
|
||||||
|
// Get the mountpoint of the given volume
|
||||||
Path(name string) (mountpoint string, err error)
|
Path(name string) (mountpoint string, err error)
|
||||||
|
// Mount the given volume and return the mountpoint
|
||||||
Mount(name string) (mountpoint string, err error)
|
Mount(name string) (mountpoint string, err error)
|
||||||
|
// Unmount the given volume
|
||||||
Unmount(name string) (err error)
|
Unmount(name string) (err error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,74 +1,149 @@
|
||||||
|
// generated code - DO NOT EDIT
|
||||||
|
|
||||||
package volumedrivers
|
package volumedrivers
|
||||||
|
|
||||||
import "fmt"
|
import "errors"
|
||||||
|
|
||||||
// currently created by hand. generation tool would generate this like:
|
type client interface {
|
||||||
// $ rpc-gen volume/drivers/api.go VolumeDriver > volume/drivers/proxy.go
|
Call(string, interface{}, interface{}) error
|
||||||
|
|
||||||
type volumeDriverRequest struct {
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
type volumeDriverResponse struct {
|
|
||||||
Mountpoint string `json:",omitempty"`
|
|
||||||
Err string `json:",omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type volumeDriverProxy struct {
|
type volumeDriverProxy struct {
|
||||||
c client
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) Create(name string) error {
|
type volumeDriverProxyCreateRequest struct {
|
||||||
args := volumeDriverRequest{name}
|
Name string
|
||||||
var ret volumeDriverResponse
|
|
||||||
err := pp.c.Call("VolumeDriver.Create", args, &ret)
|
|
||||||
if err != nil {
|
|
||||||
return pp.fmtError(name, err.Error())
|
|
||||||
}
|
|
||||||
return pp.fmtError(name, ret.Err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) Remove(name string) error {
|
type volumeDriverProxyCreateResponse struct {
|
||||||
args := volumeDriverRequest{name}
|
Err string
|
||||||
var ret volumeDriverResponse
|
|
||||||
err := pp.c.Call("VolumeDriver.Remove", args, &ret)
|
|
||||||
if err != nil {
|
|
||||||
return pp.fmtError(name, err.Error())
|
|
||||||
}
|
|
||||||
return pp.fmtError(name, ret.Err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) Path(name string) (string, error) {
|
func (pp *volumeDriverProxy) Create(name string) (err error) {
|
||||||
args := volumeDriverRequest{name}
|
var (
|
||||||
var ret volumeDriverResponse
|
req volumeDriverProxyCreateRequest
|
||||||
if err := pp.c.Call("VolumeDriver.Path", args, &ret); err != nil {
|
ret volumeDriverProxyCreateResponse
|
||||||
return "", pp.fmtError(name, err.Error())
|
)
|
||||||
|
|
||||||
|
req.Name = name
|
||||||
|
if err = pp.Call("VolumeDriver.Create", req, &ret); err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
|
||||||
|
if ret.Err != "" {
|
||||||
|
err = errors.New(ret.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) Mount(name string) (string, error) {
|
type volumeDriverProxyRemoveRequest struct {
|
||||||
args := volumeDriverRequest{name}
|
Name string
|
||||||
var ret volumeDriverResponse
|
|
||||||
if err := pp.c.Call("VolumeDriver.Mount", args, &ret); err != nil {
|
|
||||||
return "", pp.fmtError(name, err.Error())
|
|
||||||
}
|
|
||||||
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) Unmount(name string) error {
|
type volumeDriverProxyRemoveResponse struct {
|
||||||
args := volumeDriverRequest{name}
|
Err string
|
||||||
var ret volumeDriverResponse
|
|
||||||
err := pp.c.Call("VolumeDriver.Unmount", args, &ret)
|
|
||||||
if err != nil {
|
|
||||||
return pp.fmtError(name, err.Error())
|
|
||||||
}
|
|
||||||
return pp.fmtError(name, ret.Err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) fmtError(name string, err string) error {
|
func (pp *volumeDriverProxy) Remove(name string) (err error) {
|
||||||
if len(err) == 0 {
|
var (
|
||||||
return nil
|
req volumeDriverProxyRemoveRequest
|
||||||
|
ret volumeDriverProxyRemoveResponse
|
||||||
|
)
|
||||||
|
|
||||||
|
req.Name = name
|
||||||
|
if err = pp.Call("VolumeDriver.Remove", req, &ret); err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
|
|
||||||
|
if ret.Err != "" {
|
||||||
|
err = errors.New(ret.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeDriverProxyPathRequest struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeDriverProxyPathResponse struct {
|
||||||
|
Mountpoint string
|
||||||
|
Err string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pp *volumeDriverProxy) Path(name string) (mountpoint string, err error) {
|
||||||
|
var (
|
||||||
|
req volumeDriverProxyPathRequest
|
||||||
|
ret volumeDriverProxyPathResponse
|
||||||
|
)
|
||||||
|
|
||||||
|
req.Name = name
|
||||||
|
if err = pp.Call("VolumeDriver.Path", req, &ret); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mountpoint = ret.Mountpoint
|
||||||
|
|
||||||
|
if ret.Err != "" {
|
||||||
|
err = errors.New(ret.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeDriverProxyMountRequest struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeDriverProxyMountResponse struct {
|
||||||
|
Mountpoint string
|
||||||
|
Err string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pp *volumeDriverProxy) Mount(name string) (mountpoint string, err error) {
|
||||||
|
var (
|
||||||
|
req volumeDriverProxyMountRequest
|
||||||
|
ret volumeDriverProxyMountResponse
|
||||||
|
)
|
||||||
|
|
||||||
|
req.Name = name
|
||||||
|
if err = pp.Call("VolumeDriver.Mount", req, &ret); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mountpoint = ret.Mountpoint
|
||||||
|
|
||||||
|
if ret.Err != "" {
|
||||||
|
err = errors.New(ret.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeDriverProxyUnmountRequest struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeDriverProxyUnmountResponse struct {
|
||||||
|
Err string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pp *volumeDriverProxy) Unmount(name string) (err error) {
|
||||||
|
var (
|
||||||
|
req volumeDriverProxyUnmountRequest
|
||||||
|
ret volumeDriverProxyUnmountResponse
|
||||||
|
)
|
||||||
|
|
||||||
|
req.Name = name
|
||||||
|
if err = pp.Call("VolumeDriver.Unmount", req, &ret); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ret.Err != "" {
|
||||||
|
err = errors.New(ret.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue