-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.go
30 lines (25 loc) · 821 Bytes
/
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
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package storage
import (
"path/filepath"
"github.com/juju/errors"
)
const (
diskByID = "/dev/disk/by-id"
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 serial, if available,
// otherwise the device name.
func BlockDevicePath(device BlockDevice) (string, error) {
if device.Serial != "" {
// TODO(axw) rename Serial; by-id is a combination of vendor,
// model and serial.
return filepath.Join(diskByID, device.Serial), nil
}
if device.DeviceName != "" {
return filepath.Join(diskByDeviceName, device.DeviceName), nil
}
return "", errors.Errorf("could not determine path for block device")
}