示例#1
0
文件: storage.go 项目: bac/juju
// volumeAttachmentDevicePath returns the absolute device path for
// a volume attachment. The value is only meaningful in the context
// of the machine that the volume is attached to.
func volumeAttachmentDevicePath(
	volumeInfo state.VolumeInfo,
	volumeAttachmentInfo state.VolumeAttachmentInfo,
	blockDevice state.BlockDeviceInfo,
) (string, error) {
	if volumeInfo.HardwareId != "" || volumeAttachmentInfo.DeviceName != "" || volumeAttachmentInfo.DeviceLink != "" {
		// Prefer the volume attachment's information over what is
		// in the published block device information.
		var deviceLinks []string
		if volumeAttachmentInfo.DeviceLink != "" {
			deviceLinks = []string{volumeAttachmentInfo.DeviceLink}
		}
		return storage.BlockDevicePath(storage.BlockDevice{
			HardwareId:  volumeInfo.HardwareId,
			DeviceName:  volumeAttachmentInfo.DeviceName,
			DeviceLinks: deviceLinks,
		})
	}
	return storage.BlockDevicePath(BlockDeviceFromState(blockDevice))
}
示例#2
0
func testBlockDevicePath(c *gc.C, dev storage.BlockDevice, expect string) {
	path, err := storage.BlockDevicePath(dev)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(path, jc.SamePath, expect)
}
示例#3
0
func (s *BlockDevicePathSuite) TestBlockDevicePathError(c *gc.C) {
	_, err := storage.BlockDevicePath(storage.BlockDevice{})
	c.Assert(err, gc.ErrorMatches, `could not determine path for block device`)
}