libraries/patch_mgmt.rb
# -----------------------------------------------------------------
# Compute RqName suma parameter
#
#    raise InvalidTargetsProperty in case of error
# -----------------------------------------------------------------
Compute RqName suma parameter
raise InvalidTargetsProperty in case of error
Compute RqName suma parameter raise InvalidTargetsProperty in case of error
def compute_rq_name(rq_type, targets, niminfo)
      case rq_type
      when 'Latest'
        levels = Hash.new { |h, k| h[k] = k == 'master' ? niminfo['nim']['master'].fetch('oslevel', nil) : niminfo['nim']['clients'].fetch(k, {}).fetch('oslevel', nil) }
        targets.each { |k| levels[k] }
        levels.delete_if { |_k, v| v.nil? || v.empty? }
        log_debug("Hash table (machine/oslevel) built #{levels}")
        unless levels.empty?
          ary = levels.values.collect { |v| v.match(/^([0-9]{4}-[0-9]{2})(|-[0-9]{2}|-[0-9]{2}-[0-9]{4})$/)[1].delete('-') }
          metadata_filter_ml = ary.max
          if ary.min[0..3].to_i < ary.max[0..3].to_i
            log_warn("Release level mismatch, only AIX #{ary.max[0]}.#{ary.max[1]} SP/TL will be downloaded")
          end
        end
        raise InvalidTargetsProperty, 'Error: cannot discover filter ml based on the list of targets' if metadata_filter_ml.nil?
        metadata_filter_ml.insert(4, '-')
        log_info("Found highest ML #{metadata_filter_ml} from client list")
        tmp_dir = "#{Chef::Config[:file_cache_path]}/metadata"
        suma = Suma.new({ 'DisplayName' => desc, 'RqType' => 'Latest', 'RqName' => nil, 'FilterML' => metadata_filter_ml, 'DLTarget' => tmp_dir })
        suma.metadata
        sps = Dir.glob("#{tmp_dir}/installp/ppc/*.install.tips.html")
        sps.collect! do |file|
          file.gsub!('install.tips.html', 'xml')
          ::File.open(file) do |f|
            f.read.match(/^<SP name="([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4})">$/)[1].delete('-')
          end
        end
        rq_name = sps.max
        unless rq_name.nil?
          rq_name.insert(4, '-')
          rq_name.insert(7, '-')
          rq_name.insert(10, '-')
        end
        FileUtils.rm_rf(tmp_dir)
        log_info("Discover RqName #{rq_name} with metadata suma command")
      when 'TL'
        rq_name = "#{oslevel.match(/^([0-9]{4}-[0-9]{2})(|-00|-00-0000)$/)[1]}-00-0000"
      when 'SP'
        if oslevel =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4}$/
          rq_name = oslevel
        elsif oslevel =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
          metadata_filter_ml = oslevel.match(/^([0-9]{4}-[0-9]{2})-[0-9]{2}$/)[1]
          tmp_dir = "#{Chef::Config[:file_cache_path]}/metadata"
          suma = Suma.new({ 'DisplayName' => desc, 'RqType' => 'Latest', 'RqName' => nil, 'FilterML' => metadata_filter_ml, 'DLTarget' => tmp_dir })
          suma.metadata
          ::File.open("#{tmp_dir}/installp/ppc/#{oslevel}.xml") do |f|
            rq_name = f.read.match(/^<SP name="([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4})">$/)[1]
          end
          FileUtils.rm_rf(tmp_dir)
          log_info("Discover RqName #{rq_name} with metadata suma command")
        end
      end
      rq_name
    end
def compute_rq_name ( rq_type , targets , niminfo ) case rq_type when 'Latest' levels = Hash . new { | h , k | h [ k ] = k == 'master' ? niminfo [ 'nim' ] [ 'master' ] . fetch ( 'oslevel' , nil ) : niminfo [ 'nim' ] [ 'clients' ] . fetch ( k , { } ) . fetch ( 'oslevel' , nil ) } targets . each { | k | levels [ k ] } levels . delete_if { | _k , v | v . nil? || v . empty? } log_debug ( "Hash table (machine/oslevel) built #{levels}" ) unless levels . empty? ary = levels . values . collect { | v | v . match ( / ^([0-9]{4}-[0-9]{2})(|-[0-9]{2}|-[0-9]{2}-[0-9]{4})$ / ) [ 1 ] . delete ( '-' ) } metadata_filter_ml = ary . max if ary . min [ 0 .. 3 ] . to_i < ary . max [ 0 .. 3 ] . to_i log_warn ( "Release level mismatch, only AIX #{ary.max[0]}.#{ary.max[1]} SP/TL will be downloaded" ) end end raise InvalidTargetsProperty , 'Error: cannot discover filter ml based on the list of targets' if metadata_filter_ml . nil? metadata_filter_ml . insert ( 4 , '-' ) log_info ( "Found highest ML #{metadata_filter_ml} from client list" ) tmp_dir = "#{Chef::Config[:file_cache_path]}/metadata" suma = Suma . new ( { 'DisplayName' => desc , 'RqType' => 'Latest' , 'RqName' => nil , 'FilterML' => metadata_filter_ml , 'DLTarget' => tmp_dir } ) suma . metadata sps = Dir . glob ( "#{tmp_dir}/installp/ppc/*.install.tips.html" ) sps . collect! do | file | file . gsub! ( 'install.tips.html' , 'xml' ) :: File . open ( file ) do | f | f . read . match ( / ^<SP name="([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4})">$ / ) [ 1 ] . delete ( '-' ) end end rq_name = sps . max unless rq_name . nil? rq_name . insert ( 4 , '-' ) rq_name . insert ( 7 , '-' ) rq_name . insert ( 10 , '-' ) end FileUtils . rm_rf ( tmp_dir ) log_info ( "Discover RqName #{rq_name} with metadata suma command" ) when 'TL' rq_name = "#{oslevel.match(/^([0-9]{4}-[0-9]{2})(|-00|-00-0000)$/)[1]}-00-0000" when 'SP' if oslevel =~ / ^[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4}$ / rq_name = oslevel elsif oslevel =~ / ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ / metadata_filter_ml = oslevel . match ( / ^([0-9]{4}-[0-9]{2})-[0-9]{2}$ / ) [ 1 ] tmp_dir = "#{Chef::Config[:file_cache_path]}/metadata" suma = Suma . new ( { 'DisplayName' => desc , 'RqType' => 'Latest' , 'RqName' => nil , 'FilterML' => metadata_filter_ml , 'DLTarget' => tmp_dir } ) suma . metadata :: File . open ( "#{tmp_dir}/installp/ppc/#{oslevel}.xml" ) do | f | rq_name = f . read . match ( / ^<SP name="([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4})">$ / ) [ 1 ] end FileUtils . rm_rf ( tmp_dir ) log_info ( "Discover RqName #{rq_name} with metadata suma command" ) end end rq_name end
Compute RqName suma parameter
raise InvalidTargetsProperty in case of error
Compute RqName suma parameter raise InvalidTargetsProperty in case of error
# build machine-oslevel hash # discover FilterML level # find highest ML # check ml level of machines # suma metadata # find latest SP for highest TL # pad with 0 # suma metadata # find SP build number
rq_type
targets
niminfo