-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdriver.go
92 lines (79 loc) · 2.6 KB
/
driver.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
"github.com/docker/go-plugins-helpers/volume"
"fmt"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"strings"
)
type ImagefsDriver struct {
cli *client.Client
}
func (d ImagefsDriver) Create(r volume.Request) volume.Response {
fmt.Printf("-> Create %+v\n", r)
response := volume.Response{Err: "Not implemented"}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) List(r volume.Request) volume.Response {
fmt.Printf("-> List %+v\n", r)
images, err := d.cli.ImageList(context.Background(), types.ImageListOptions{All: true})
if err != nil {
panic(err)
}
volumes := []*volume.Volume{}
for _, image := range images {
fmt.Printf("%s\n", image.ID)
volumes = append(volumes, &volume.Volume{Name: image.ID[7:]})
}
response := volume.Response{Volumes:volumes}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) Get(r volume.Request) volume.Response {
fmt.Printf("-> Get %+v\n", r)
inspect, _, err := d.cli.ImageInspectWithRaw(context.Background(), r.Name)
if err != nil {
return volume.Response{Err: fmt.Sprint(err)}
}
response := volume.Response{}
if inspect.GraphDriver.Name == "overlay2" {
response = volume.Response{Volume: &volume.Volume{Name: r.Name,
Mountpoint: strings.Split(inspect.GraphDriver.Data["UpperDir"], ":")[0]}}
} else {
response = volume.Response{Err: fmt.Sprintf("GraphDriver %s not supported", inspect.GraphDriver.Name)}
}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) Remove(r volume.Request) volume.Response {
fmt.Printf("-> Remove %+v\n", r)
response := volume.Response{Err: "Not implemented"}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) Path(r volume.Request) volume.Response {
fmt.Printf("-> Path %+v\n", r)
response := volume.Response{Mountpoint: d.Get(r).Volume.Mountpoint}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) Mount(r volume.MountRequest) volume.Response {
fmt.Printf("-> Mount %+v\n", r)
response := volume.Response{Mountpoint: d.Get(volume.Request{Name: r.Name}).Volume.Mountpoint}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) Unmount(r volume.UnmountRequest) volume.Response {
fmt.Printf("-> Unmount %+v\n", r)
response := volume.Response{}
fmt.Printf("<- %+v\n", response)
return response
}
func (d ImagefsDriver) Capabilities(r volume.Request) volume.Response {
fmt.Printf("-> Capabilities %+v\n", r)
response := volume.Response{Capabilities: volume.Capability{Scope: "local"}}
fmt.Printf("<- %+v\n", response)
return response
}