forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.go
52 lines (42 loc) · 1.08 KB
/
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
46
47
48
49
50
51
52
package cluster
import "github.com/docker/engine-api/types"
// Volume is exported
type Volume struct {
types.Volume
Engine *Engine
}
// Volumes represents an array of volumes
type Volumes []*Volume
// Get returns a volume using its ID or Name
func (volumes Volumes) Get(name string) *Volume {
// Abort immediately if the name is empty.
if len(name) == 0 {
return nil
}
candidates := []*Volume{}
// Match name or engine/name.
for _, volume := range volumes {
if volume.Name == name || volume.Engine.ID+"/"+volume.Name == name || volume.Engine.Name+"/"+volume.Name == name {
candidates = append(candidates, volume)
}
}
// Return if we found a unique match.
if size := len(candidates); size == 1 {
return candidates[0]
} else if size > 1 {
// Match first volume with non-local driver
for _, volume := range candidates {
if volume.Name == name && volume.Driver != "local" {
return volume
}
}
return nil
}
// Match /name and return as soon as we find one.
for _, volume := range volumes {
if volume.Name == "/"+name {
return volume
}
}
return nil
}