-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
41 lines (36 loc) · 1.1 KB
/
path.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
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package storage
import (
"path"
"github.com/juju/errors"
)
const (
diskByID = "/dev/disk/by-id"
diskByUUID = "/dev/disk/by-uuid"
diskByWWN = "/dev/disk/by-id/wwn-"
diskByDeviceName = "/dev"
)
// BlockDevicePath returns the path to a block device, or an error if a path
// cannot be determined. The path is based on the hardware ID, if available;
// the first value in device.DeviceLinks, if non-empty; otherwise the device
// name.
func BlockDevicePath(device BlockDevice) (string, error) {
if device.WWN != "" {
return diskByWWN + device.WWN, nil
}
if device.HardwareId != "" {
return path.Join(diskByID, device.HardwareId), nil
}
if len(device.DeviceLinks) > 0 {
// return the first device link in the list
return device.DeviceLinks[0], nil
}
if device.UUID != "" {
return path.Join(diskByUUID, device.UUID), nil
}
if device.DeviceName != "" {
return path.Join(diskByDeviceName, device.DeviceName), nil
}
return "", errors.Errorf("could not determine path for block device")
}