github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/apiserver/common/blockdevices.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package common
     5  
     6  import (
     7  	"github.com/juju/juju/state"
     8  	"github.com/juju/juju/storage"
     9  )
    10  
    11  // BlockDeviceFromState translates a state.BlockDeviceInfo to a
    12  // storage.BlockDevice.
    13  func BlockDeviceFromState(in state.BlockDeviceInfo) storage.BlockDevice {
    14  	return storage.BlockDevice{
    15  		in.DeviceName,
    16  		in.Label,
    17  		in.UUID,
    18  		in.HardwareId,
    19  		in.BusAddress,
    20  		in.Size,
    21  		in.FilesystemType,
    22  		in.InUse,
    23  		in.MountPoint,
    24  	}
    25  }
    26  
    27  // MatchingBlockDevice finds the block device that matches the
    28  // provided volume info and volume attachment info.
    29  func MatchingBlockDevice(
    30  	blockDevices []state.BlockDeviceInfo,
    31  	volumeInfo state.VolumeInfo,
    32  	attachmentInfo state.VolumeAttachmentInfo,
    33  ) (*state.BlockDeviceInfo, bool) {
    34  	for _, dev := range blockDevices {
    35  		if volumeInfo.HardwareId != "" {
    36  			if volumeInfo.HardwareId == dev.HardwareId {
    37  				return &dev, true
    38  			}
    39  		} else if attachmentInfo.BusAddress != "" {
    40  			if attachmentInfo.BusAddress == dev.BusAddress {
    41  				return &dev, true
    42  			}
    43  		} else if attachmentInfo.DeviceName == dev.DeviceName {
    44  			return &dev, true
    45  		}
    46  	}
    47  	return nil, false
    48  }