github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/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.Size,
    20  		in.FilesystemType,
    21  		in.InUse,
    22  		in.MountPoint,
    23  	}
    24  }
    25  
    26  // MatchingBlockDevice finds the block device that matches the
    27  // provided volume info and volume attachment info.
    28  func MatchingBlockDevice(
    29  	blockDevices []state.BlockDeviceInfo,
    30  	volumeInfo state.VolumeInfo,
    31  	attachmentInfo state.VolumeAttachmentInfo,
    32  ) (*state.BlockDeviceInfo, bool) {
    33  	for _, dev := range blockDevices {
    34  		if volumeInfo.HardwareId != "" {
    35  			if volumeInfo.HardwareId == dev.HardwareId {
    36  				return &dev, true
    37  			}
    38  		} else if attachmentInfo.DeviceName == dev.DeviceName {
    39  			return &dev, true
    40  		}
    41  	}
    42  	return nil, false
    43  }