1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/volume/drivers/proxy.go
David Calavera 30448166de Fix volume plugin serialization.
Unmarshal errors into strings.
Fix `omit` typos.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-06-09 10:39:46 -07:00

74 lines
2 KiB
Go

package volumedrivers
import "fmt"
// currently created by hand. generation tool would generate this like:
// $ rpc-gen volume/drivers/api.go VolumeDriver > volume/drivers/proxy.go
type volumeDriverRequest struct {
Name string
}
type volumeDriverResponse struct {
Mountpoint string `json:",omitempty"`
Err string `json:",omitempty"`
}
type volumeDriverProxy struct {
c client
}
func (pp *volumeDriverProxy) Create(name string) error {
args := volumeDriverRequest{name}
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 {
args := volumeDriverRequest{name}
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) {
args := volumeDriverRequest{name}
var ret volumeDriverResponse
if err := pp.c.Call("VolumeDriver.Path", args, &ret); err != nil {
return "", pp.fmtError(name, err.Error())
}
return ret.Mountpoint, pp.fmtError(name, ret.Err)
}
func (pp *volumeDriverProxy) Mount(name string) (string, error) {
args := volumeDriverRequest{name}
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 {
args := volumeDriverRequest{name}
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 {
if len(err) == 0 {
return nil
}
return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
}