forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
74 lines (63 loc) · 1.92 KB
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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:",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 {
return pp.fmtError(name, err)
}
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)
}
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)
}
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)
}
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)
}
return pp.fmtError(name, ret.Err)
}
func (pp *volumeDriverProxy) fmtError(name string, err error) error {
if err == nil {
return nil
}
return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
}