forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipath_tool_device_path_resolver.go
55 lines (46 loc) · 1.67 KB
/
multipath_tool_device_path_resolver.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
package devicepathresolver
import (
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type multipathDevicePathResolver struct {
idDevicePathResolver DevicePathResolver
iscsiDevicePathResolver DevicePathResolver
logger boshlog.Logger
logTag string
}
func NewMultipathDevicePathResolver(
idDevicePathResolver DevicePathResolver,
iscsiDevicePathResolver DevicePathResolver,
logger boshlog.Logger,
) DevicePathResolver {
return multipathDevicePathResolver{
idDevicePathResolver: idDevicePathResolver,
iscsiDevicePathResolver: iscsiDevicePathResolver,
logger: logger,
logTag: "multipathDevicePathResolver",
}
}
func (mpr multipathDevicePathResolver) GetRealDevicePath(diskSettings boshsettings.DiskSettings) (string, bool, error) {
realPath, timeout, err := mpr.idDevicePathResolver.GetRealDevicePath(diskSettings)
if err == nil {
mpr.logger.Debug(mpr.logTag, "Resolved disk %+v by ID as '%s'", diskSettings, realPath)
return realPath, false, nil
}
if timeout {
return "", timeout, bosherr.WrapError(err, "Resolving id device path")
}
mpr.logger.Debug(mpr.logTag,
"Failed to get device real path by disk ID: '%s'. Error: '%s', timeout: '%t'",
diskSettings.ID,
err.Error(),
timeout,
)
mpr.logger.Debug(mpr.logTag, "Using iSCSI resolver to get device real path")
realPath, timeout, err = mpr.iscsiDevicePathResolver.GetRealDevicePath(diskSettings)
if err != nil {
return "", timeout, bosherr.WrapError(err, "Resolving mapped device path")
}
return realPath, timeout, nil
}