2015-05-19 16:05:25 -04:00
|
|
|
package volumedrivers
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
import "fmt"
|
|
|
|
|
2015-05-19 16:05:25 -04:00
|
|
|
// 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:",ommitempty"`
|
|
|
|
Err error `json:",ommitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-05-22 13:37:00 -04:00
|
|
|
return pp.fmtError(name, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-05-22 13:37:00 -04:00
|
|
|
return pp.fmtError(name, ret.Err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pp *volumeDriverProxy) Remove(name string) error {
|
|
|
|
args := volumeDriverRequest{name}
|
|
|
|
var ret volumeDriverResponse
|
|
|
|
err := pp.c.Call("VolumeDriver.Remove", args, &ret)
|
|
|
|
if err != nil {
|
2015-05-22 13:37:00 -04:00
|
|
|
return pp.fmtError(name, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-05-22 13:37:00 -04:00
|
|
|
return pp.fmtError(name, ret.Err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-05-22 13:37:00 -04:00
|
|
|
return "", pp.fmtError(name, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-05-22 13:37:00 -04:00
|
|
|
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-05-22 13:37:00 -04:00
|
|
|
return "", pp.fmtError(name, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-05-22 13:37:00 -04:00
|
|
|
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pp *volumeDriverProxy) Unmount(name string) error {
|
|
|
|
args := volumeDriverRequest{name}
|
|
|
|
var ret volumeDriverResponse
|
|
|
|
err := pp.c.Call("VolumeDriver.Unmount", args, &ret)
|
|
|
|
if err != nil {
|
2015-05-22 13:37:00 -04:00
|
|
|
return pp.fmtError(name, err)
|
|
|
|
}
|
|
|
|
return pp.fmtError(name, ret.Err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pp *volumeDriverProxy) fmtError(name string, err error) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-05-22 13:37:00 -04:00
|
|
|
return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|