This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 3
/
list_disk.go
79 lines (63 loc) · 1.77 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
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")
}
settings := a.settingsService.GetSettings()
diskIDs := []string{}
for diskID := range settings.Disks.Persistent {
var isMounted bool
diskSettings, _ := settings.PersistentDiskSettings(diskID)
isMounted, err := a.platform.IsPersistentDiskMounted(diskSettings)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Checking whether device %+v is mounted", diskSettings)
}
if isMounted {
diskIDs = append(diskIDs, diskID)
} else {
a.logger.Debug("list-disk-action", "Volume '%s' not mounted", diskID)
}
}
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")
}