github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/storage/path.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storage 5 6 import ( 7 "path/filepath" 8 9 "github.com/juju/errors" 10 ) 11 12 const ( 13 diskByID = "/dev/disk/by-id" 14 diskByDeviceName = "/dev" 15 ) 16 17 // BlockDevicePath returns the path to a block device, or an error if a path 18 // cannot be determined. The path is based on the hardware ID, if available; 19 // the first value in device.DeviceLinks, if non-empty; otherwise the device 20 // name. 21 func BlockDevicePath(device BlockDevice) (string, error) { 22 if device.HardwareId != "" { 23 return filepath.Join(diskByID, device.HardwareId), nil 24 } 25 if len(device.DeviceLinks) > 0 { 26 // return the first device link in the list 27 return device.DeviceLinks[0], nil 28 } 29 if device.DeviceName != "" { 30 return filepath.Join(diskByDeviceName, device.DeviceName), nil 31 } 32 return "", errors.Errorf("could not determine path for block device") 33 }