-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathdocker_utils.go
91 lines (79 loc) · 1.96 KB
/
docker_utils.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
package docker
import (
"fmt"
"path"
"strings"
"github.com/akutz/goof"
"github.com/codedellemc/libstorage/api/context"
"github.com/codedellemc/libstorage/api/types"
"github.com/codedellemc/libstorage/api/utils"
)
func (d *driver) getVolumeMountPath(volumeName string) (string, error) {
if volumeName == "" {
return "", goof.New("missing volume name")
}
return path.Join(d.mountDirPath(), volumeName), nil
}
func (d *driver) volumeInspectByID(
ctx types.Context,
volumeID string,
attachments types.VolumeAttachmentsTypes,
opts types.Store) (*types.Volume, error) {
client := context.MustClient(ctx)
vol, err := client.Storage().VolumeInspect(ctx, volumeID,
&types.VolumeInspectOpts{
Attachments: attachments})
if err != nil {
return nil, err
}
return vol, nil
}
func (d *driver) volumeInspectByIDOrName(
ctx types.Context,
volumeID, volumeName string,
attachments types.VolumeAttachmentsTypes,
opts types.Store) (*types.Volume, error) {
if volumeID != "" && volumeName != "" {
return nil, goof.New("specify either volumeID or volumeName")
}
client := context.MustClient(ctx)
var obj *types.Volume
if volumeID != "" {
var err error
obj, err = d.volumeInspectByID(ctx, volumeID, attachments, opts)
if err != nil {
return nil, err
}
} else {
objs, err := client.Storage().Volumes(
ctx, &types.VolumesOpts{Attachments: 0})
if err != nil {
return nil, err
}
for _, o := range objs {
if strings.EqualFold(volumeName, o.Name) {
obj, err = d.volumeInspectByID(ctx, o.ID, attachments, opts)
if err != nil {
return nil, err
}
break
}
}
}
if obj == nil {
return nil, utils.NewNotFoundError(
fmt.Sprintf("volumeID=%s,volumeName=%s", volumeID, volumeName))
}
return obj, nil
}
func isErrNotFound(err error) bool {
switch err.(type) {
case *types.ErrNotFound:
return true
default:
return false
}
}
func (d *driver) volumeMountPath(target string) string {
return path.Join(target, d.volumeRootPath())
}