forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtio_device_path_resolver.go
51 lines (43 loc) · 1.58 KB
/
virtio_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
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 virtioDevicePathResolver struct {
idDevicePathResolver DevicePathResolver
mappedDevicePathResolver DevicePathResolver
logger boshlog.Logger
logTag string
}
func NewVirtioDevicePathResolver(
idDevicePathResolver DevicePathResolver,
mappedDevicePathResolver DevicePathResolver,
logger boshlog.Logger,
) DevicePathResolver {
return virtioDevicePathResolver{
idDevicePathResolver: idDevicePathResolver,
mappedDevicePathResolver: mappedDevicePathResolver,
logger: logger,
logTag: "virtioDevicePathResolver",
}
}
func (vpr virtioDevicePathResolver) GetRealDevicePath(diskSettings boshsettings.DiskSettings) (string, bool, error) {
realPath, timeout, err := vpr.idDevicePathResolver.GetRealDevicePath(diskSettings)
if err == nil {
vpr.logger.Debug(vpr.logTag, "Resolved disk %+v by ID as '%s'", diskSettings, realPath)
return realPath, false, nil
}
vpr.logger.Debug(vpr.logTag,
"Failed to get device real path by disk ID: '%s'. Error: '%s', timeout: '%t'",
diskSettings.ID,
err.Error(),
timeout,
)
vpr.logger.Debug(vpr.logTag, "Using mapped resolver to get device real path")
realPath, timeout, err = vpr.mappedDevicePathResolver.GetRealDevicePath(diskSettings)
if err != nil {
return "", timeout, bosherr.WrapError(err, "Resolving mapped device path")
}
return realPath, false, nil
}