-
Notifications
You must be signed in to change notification settings - Fork 114
/
mount_disk.go
79 lines (63 loc) · 2.02 KB
/
mount_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"
boshdpresolv "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshdirs "github.com/cloudfoundry/bosh-agent/settings/directories"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type diskMounter interface {
MountPersistentDisk(diskSettings boshsettings.DiskSettings, mountPoint string) error
}
type MountDiskAction struct {
settingsService boshsettings.Service
diskMounter diskMounter
devicePathResolver boshdpresolv.DevicePathResolver
dirProvider boshdirs.Provider
logger boshlog.Logger
}
func NewMountDisk(
settingsService boshsettings.Service,
diskMounter diskMounter,
dirProvider boshdirs.Provider,
logger boshlog.Logger,
) (mountDisk MountDiskAction) {
mountDisk.settingsService = settingsService
mountDisk.diskMounter = diskMounter
mountDisk.dirProvider = dirProvider
mountDisk.logger = logger
return
}
func (a MountDiskAction) IsAsynchronous(_ ProtocolVersion) bool {
return true
}
func (a MountDiskAction) IsPersistent() bool {
return false
}
func (a MountDiskAction) IsLoggable() bool {
return true
}
func (a MountDiskAction) Run(diskCid string) (interface{}, error) {
err := a.settingsService.LoadSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Refreshing the settings")
}
settings := a.settingsService.GetSettings()
diskSettings, found := settings.PersistentDiskSettings(diskCid)
if !found {
return nil, bosherr.Errorf("Persistent disk with volume id '%s' could not be found", diskCid)
}
mountPoint := a.dirProvider.StoreDir()
err = a.diskMounter.MountPersistentDisk(diskSettings, mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Mounting persistent disk")
}
return map[string]string{}, nil
}
func (a MountDiskAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a MountDiskAction) Cancel() error {
return errors.New("not supported")
}