def merge_planned_volume_mappings(last_mappings, current_planned_volumes)
      results = []
      vm = RightScale::Platform.volume_manager

      # merge latest mappings with last mappings, if any.
      current_planned_volumes.each do |planned_volume|
        raise VolumeManagement::InvalidResponse.new("Reponse for volume mapping was invalid: #{mapping.inspect}") unless planned_volume.is_valid?
        if mount_point = planned_volume.mount_points.find { |mount_point| false == vm.is_attachable_volume_path?(mount_point) }
          raise VolumeManagement::UnsupportedMountPoint.new("Cannot mount a volume using \"#{mount_point}\".")
        end

        mapping = {:volume_id => planned_volume.volume_id,
                   :device_name => planned_volume.device_name,
                   :volume_status => planned_volume.volume_status,
                   :mount_points => planned_volume.mount_points.dup}
        if last_mapping = last_mappings.find { |last_mapping| last_mapping[:volume_id] == mapping[:volume_id] }
          # if device name or mount point(s) have changed then we must start
          # over (we can't prevent the user from doing this).
          if last_mapping[:device_name] != mapping[:device_name] || last_mapping[:mount_points] != mapping[:mount_points]
            last_mapping[:device_name] = mapping[:device_name]
            last_mapping[:mount_points] = mapping[:mount_points].dup
            last_mapping[:management_status] = nil
          end
          last_mapping[:volume_status] = mapping[:volume_status]
          mapping = last_mapping
        end
        results << mapping
      end

      # preserve any last mappings which do not appear in current mappings by
      # assuming that they are 'detached' to support a limitation of the initial
      # query implementation.
      last_mappings.each do |last_mapping|
        mapping = results.find { |mapping| mapping[:volume_id] == last_mapping[:volume_id] }
        unless mapping
          last_mapping[:volume_status] = 'detached'
          results << last_mapping
        end
      end

      return results
    end
def merge_planned_volume_mappings(last_mappings, current_planned_volumes)
      results = []
      vm = RightScale::Platform.volume_manager

      # merge latest mappings with last mappings, if any.
      current_planned_volumes.each do |planned_volume|
        raise VolumeManagement::InvalidResponse.new("Reponse for volume mapping was invalid: #{mapping.inspect}") unless planned_volume.is_valid?
        if mount_point = planned_volume.mount_points.find { |mount_point| false == vm.is_attachable_volume_path?(mount_point) }
          raise VolumeManagement::UnsupportedMountPoint.new("Cannot mount a volume using \"#{mount_point}\".")
        end

        mapping = {:volume_id => planned_volume.volume_id,
                   :device_name => planned_volume.device_name,
                   :volume_status => planned_volume.volume_status,
                   :mount_points => planned_volume.mount_points.dup}
        if last_mapping = last_mappings.find { |last_mapping| last_mapping[:volume_id] == mapping[:volume_id] }
          # if device name or mount point(s) have changed then we must start
          # over (we can't prevent the user from doing this).
          if last_mapping[:device_name] != mapping[:device_name] || last_mapping[:mount_points] != mapping[:mount_points]
            last_mapping[:device_name] = mapping[:device_name]
            last_mapping[:mount_points] = mapping[:mount_points].dup
            last_mapping[:management_status] = nil
          end
          last_mapping[:volume_status] = mapping[:volume_status]
          mapping = last_mapping
        end
        results << mapping
      end

      # preserve any last mappings which do not appear in current mappings by
      # assuming that they are 'detached' to support a limitation of the initial
      # query implementation.
      last_mappings.each do |last_mapping|
        mapping = results.find { |mapping| mapping[:volume_id] == last_mapping[:volume_id] }
        unless mapping
          last_mapping[:volume_status] = 'detached'
          results << last_mapping
        end
      end

      return results
    end
Merges mappings from query with any last known mappings which may have a
 locally persisted state which needs to be evaluated.

 === Parameters
 last_mappings(Array):: previously merged mappings or empty
 current_mappings(Array):: current unmerged mappings or empty

 === Returns
 results(Array):: array of hashes representing merged mappings