Skip to content

Commit a8c1396

Browse files
committed
add in volume control
1 parent 935e3cd commit a8c1396

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

volume.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package docker
2+
3+
import (
4+
dockType "github.com/docker/engine-api/types"
5+
"github.com/docker/engine-api/types/filters"
6+
"golang.org/x/net/context"
7+
8+
9+
)
10+
11+
// create a new volume
12+
func VolumeCreate(name string) (dockType.Volume, error) {
13+
vol := dockType.VolumeCreateRequest{
14+
Name: name,
15+
}
16+
17+
return client.VolumeCreate(context.Background(), vol)
18+
}
19+
20+
// list the volumes we have
21+
func VolumeList() ([]*dockType.Volume, error) {
22+
volumeList, err := client.VolumeList(context.Background(), filters.Args{})
23+
return volumeList.Volumes, err
24+
}
25+
26+
// check to see if a volume exists
27+
func VolumeExists(name string) bool {
28+
volumes, err := VolumeList()
29+
if err != nil {
30+
return false
31+
}
32+
33+
for _, volume := range volumes {
34+
if volume.Name == name {
35+
return true
36+
}
37+
38+
}
39+
return false
40+
}
41+
42+
// remove an existing volume
43+
func VolumeRemove(name string) error {
44+
return client.VolumeRemove(context.Background(), name, true)
45+
}

0 commit comments

Comments
 (0)