forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmount_disk.go
71 lines (56 loc) · 1.58 KB
/
unmount_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
package action
import (
"errors"
"fmt"
boshplatform "github.com/cloudfoundry/bosh-agent/platform"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type UnmountDiskAction struct {
settingsService boshsettings.Service
platform boshplatform.Platform
}
func NewUnmountDisk(
settingsService boshsettings.Service,
platform boshplatform.Platform,
) (unmountDisk UnmountDiskAction) {
unmountDisk.settingsService = settingsService
unmountDisk.platform = platform
return
}
func (a UnmountDiskAction) IsAsynchronous(_ ProtocolVersion) bool {
return true
}
func (a UnmountDiskAction) IsPersistent() bool {
return false
}
func (a UnmountDiskAction) IsLoggable() bool {
return true
}
func (a UnmountDiskAction) Run(diskID string) (value interface{}, err error) {
diskSettings, err := a.settingsService.GetPersistentDiskSettings(diskID)
if err != nil {
err = bosherr.WrapError(err, "Getting persistent disk settings")
return
}
didUnmount, err := a.platform.UnmountPersistentDisk(diskSettings)
if err != nil {
err = bosherr.WrapError(err, "Unmounting persistent disk")
return
}
msg := fmt.Sprintf("Partition of %+v is not mounted", diskSettings)
if didUnmount {
msg = fmt.Sprintf("Unmounted partition of %+v", diskSettings)
}
type valueType struct {
Message string `json:"message"`
}
value = valueType{Message: msg}
return
}
func (a UnmountDiskAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a UnmountDiskAction) Cancel() error {
return errors.New("not supported")
}