-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvolume.go
45 lines (35 loc) · 912 Bytes
/
volume.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
package docker
import (
dockType "github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/filters"
"golang.org/x/net/context"
)
// create a new volume
func VolumeCreate(name string) (dockType.Volume, error) {
vol := dockType.VolumeCreateRequest{
Name: name,
}
return client.VolumeCreate(context.Background(), vol)
}
// list the volumes we have
func VolumeList() ([]*dockType.Volume, error) {
volumeList, err := client.VolumeList(context.Background(), filters.Args{})
return volumeList.Volumes, err
}
// check to see if a volume exists
func VolumeExists(name string) bool {
volumes, err := VolumeList()
if err != nil {
return false
}
for _, volume := range volumes {
if volume.Name == name {
return true
}
}
return false
}
// remove an existing volume
func VolumeRemove(name string) error {
return client.VolumeRemove(context.Background(), name, true)
}