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 {
|
2015-06-09 13:23:01 -04:00
|
|
|
Mountpoint string `json:",omitempty"`
|
|
|
|
Err string `json:",omitempty"`
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-09 13:23:01 -04:00
|
|
|
return pp.fmtError(name, err.Error())
|
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-06-09 13:23:01 -04:00
|
|
|
return pp.fmtError(name, err.Error())
|
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-06-09 13:23:01 -04:00
|
|
|
return "", pp.fmtError(name, err.Error())
|
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-06-09 13:23:01 -04:00
|
|
|
return "", pp.fmtError(name, err.Error())
|
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-06-09 13:23:01 -04:00
|
|
|
return pp.fmtError(name, err.Error())
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
return pp.fmtError(name, ret.Err)
|
|
|
|
}
|
|
|
|
|
2015-06-09 13:23:01 -04:00
|
|
|
func (pp *volumeDriverProxy) fmtError(name string, err string) error {
|
|
|
|
if len(err) == 0 {
|
2015-05-22 13:37:00 -04:00
|
|
|
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
|
|
|
}
|