forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_disk.go
82 lines (66 loc) · 1.86 KB
/
list_disk.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
package action
import (
"errors"
boshplatform "github.com/cloudfoundry/bosh-agent/platform"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type ListDiskAction struct {
settingsService boshsettings.Service
platform boshplatform.Platform
logger boshlog.Logger
}
func NewListDisk(
settingsService boshsettings.Service,
platform boshplatform.Platform,
logger boshlog.Logger,
) (action ListDiskAction) {
action.settingsService = settingsService
action.platform = platform
action.logger = logger
return
}
func (a ListDiskAction) IsAsynchronous(version ProtocolVersion) bool {
if version >= 3 {
return true
}
return false
}
func (a ListDiskAction) IsPersistent() bool {
return false
}
func (a ListDiskAction) IsLoggable() bool {
return true
}
func (a ListDiskAction) Run() (interface{}, error) {
err := a.settingsService.LoadSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Refreshing the settings")
}
diskIDs := make([]string, 0)
usedIDs := map[string]bool{}
allPersistentDisks, err := a.settingsService.GetAllPersistentDiskSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Getting persistent disk settings")
}
for diskID, diskSettings := range allPersistentDisks {
isMounted, err := a.platform.IsPersistentDiskMounted(diskSettings)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Checking whether device %+v is mounted", diskSettings)
}
if isMounted {
if _, present := usedIDs[diskID]; !present {
diskIDs = append(diskIDs, diskID)
usedIDs[diskID] = true
}
}
}
return diskIDs, nil
}
func (a ListDiskAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a ListDiskAction) Cancel() error {
return errors.New("not supported")
}