core/rails/app/models/barclamp_raid/raid_hammer.rb
# Apply the raid configuration from the provided noderole and update
# the output log.
#
# @param nr [NodeRole]param noderole containing raid configuration
# @return [Array<Volumes>] The current volumes on the system
Apply the raid configuration from the provided noderole and update
the output log.
Apply the raid configuration from the provided noderole and update the output log .
def converge(nr)
    logger = NodeRoleLogger.new(nr)
    logger << "Converging Raid Configuration\n"
    wanted_config = Attrib.get('raid-wanted-volumes',nr) || []
    current_controllers = drivers(logger).map{|d|d.controllers}.flatten
    current_volumes = []
    current_controllers.each do |c|
      current_volumes += c.volumes
    end
    current_volume_hash = (current_volumes.map{|v|[v["name"], v]}.to_h rescue {})
    wanted_volume_hash = (wanted_config.map{|v|[v["name"], v]}.to_h rescue {})
    obsolete_volumes = current_volumes.reject{|v|same_volume(v, wanted_volume_hash[v['name']])}
    new_volumes = wanted_config.reject{|v|same_volume(current_volume_hash[v['name']], v)}
    obsolete_volumes.each do |v|
      logger << "Deleting RAID volume #{v.inspect}\n"
      begin
        v.delete_vd
        current_volumes.delete(v)
      rescue => e
        Rails.logger.error("Unable to delete #{v}")
        Rails.logger.error("Error was: #{e.message}")
        logger << "Unable to delete #{v}\n"
        logger << "Error was: #{e.message}\n"
      end
    end
    failed = false
    new_volumes.each do |v|
      logger << "Building #{v}"
      new_vol = nil
      current_controllers.each_with_index do |c,index|
        logger << "Trying to put #{v} on #{index} - #{c}"
        if !v["controller_index"].nil? and v["controller_index"] != index
          logger << "Skipping #{index} #{c} not #{v["controller_index"]}"
          next
        end
        begin
          logger << "Creating new volume #{v}\n"
          new_vol = c.create_vd(v)
        rescue => e
          Rails.logger.info("Could not create #{v} on #{c.name}")
          Rails.logger.info("Error was: #{e.message}")
          logger << "Could not create #{v} on #{c.name}\n"
          logger << "Error was: #{e.message}\n"
          next
        end
        logger << "Volume #{v} created on #{c.name}\n"
        break
      end
      if new_vol
        current_volumes << new_vol
      else
        Rails.logger.error("Unable to create #{v} on any raid controller!\n")
        logger << "Unable to create #{v} on any raid controller!\n"
        failed = true
      end
    end
    raise logger if failed
    current_volumes
  end
def converge ( nr ) logger = NodeRoleLogger . new ( nr ) logger << "Converging Raid Configuration\n" wanted_config = Attrib . get ( 'raid-wanted-volumes' , nr ) || [ ] current_controllers = drivers ( logger ) . map { | d | d . controllers } . flatten current_volumes = [ ] current_controllers . each do | c | current_volumes += c . volumes end current_volume_hash = ( current_volumes . map { | v | [ v [ "name" ] , v ] } . to_h rescue { } ) wanted_volume_hash = ( wanted_config . map { | v | [ v [ "name" ] , v ] } . to_h rescue { } ) obsolete_volumes = current_volumes . reject { | v | same_volume ( v , wanted_volume_hash [ v [ 'name' ] ] ) } new_volumes = wanted_config . reject { | v | same_volume ( current_volume_hash [ v [ 'name' ] ] , v ) } obsolete_volumes . each do | v | logger << "Deleting RAID volume #{v.inspect}\n" begin v . delete_vd current_volumes . delete ( v ) rescue => e Rails . logger . error ( "Unable to delete #{v}" ) Rails . logger . error ( "Error was: #{e.message}" ) logger << "Unable to delete #{v}\n" logger << "Error was: #{e.message}\n" end end failed = false new_volumes . each do | v | logger << "Building #{v}" new_vol = nil current_controllers . each_with_index do | c , index | logger << "Trying to put #{v} on #{index} - #{c}" if ! v [ "controller_index" ] . nil? and v [ "controller_index" ] != index logger << "Skipping #{index} #{c} not #{v["controller_index"]}" next end begin logger << "Creating new volume #{v}\n" new_vol = c . create_vd ( v ) rescue => e Rails . logger . info ( "Could not create #{v} on #{c.name}" ) Rails . logger . info ( "Error was: #{e.message}" ) logger << "Could not create #{v} on #{c.name}\n" logger << "Error was: #{e.message}\n" next end logger << "Volume #{v} created on #{c.name}\n" break end if new_vol current_volumes << new_vol else Rails . logger . error ( "Unable to create #{v} on any raid controller!\n" ) logger << "Unable to create #{v} on any raid controller!\n" failed = true end end raise logger if failed current_volumes end
Apply the raid configuration from the provided noderole and update
the output log.
Apply the raid configuration from the provided noderole and update the output log .
# Figure out what our current volumes are # Figure out what to kill and what to keep. # kill any volumes we no longer care about # Some day, modify the configuration of changed ones, if their requested config changed. # Crete new volumes.
The current volumes on the system
The current volumes on the system
Array<Volumes>
nr
param noderole containing raid configuration
param noderole containing raid configuration