Sha256: f858edef2bd122d3bc5931f9429b3842a1685028076a71884305022fcf6b77b3

Contents?: true

Size: 1.63 KB

Versions: 20

Compression:

Stored size: 1.63 KB

Contents

module Katello
  module Concerns
    module SmartProxyHelperExtensions
      def disks(storage)
        mount_points = {}
        disks = []
        storage.each do |_name, values|
          mount = values['mounted']
          mount_points[mount].nil? ? mount_points[mount] = [values['path']] : mount_points[mount] << values['path']
          values['header'] = "#{mount_points[mount].to_sentence} (on #{values['filesystem']})"
          values['available_percent'] = available_percent(values['percent'])
          values['size_status'] = storage_warning(values['available'])
          values['total'] = kb_to_actual(values.delete('1k-blocks'))
          values['used'] = kb_to_actual(values['used'])
          values['available'] = kb_to_actual(values['available'])
          disks << values
        end
        disks.group_by { |h| h['mounted'] }.map { |_, hs| hs.reduce(:merge) }
      end

      def boolean_to_icon(boolean)
        boolean = ::Foreman::Cast.to_bool(boolean)
        icon = boolean ? 'ok' : 'error-circle-o'
        icon_text(icon, '', :kind => 'pficon')
      end

      def available_percent(percent_string)
        used_percent = percent_string.delete('%').to_i
        available_percent = 100 - used_percent
        "#{available_percent}%"
      end

      def storage_warning(available)
        gb_size = available.to_i / 1_048_576
        case gb_size
        when 0..1
          "danger"
        when 2..10
          "warning"
        else
          "success"
        end
      end

      def kb_to_actual(number)
        # Convert number from kb to mb to any size
        number_to_human_size(number.to_i * 1024)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
katello-3.2.1.1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.2.1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.2.0 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.2.0.rc3 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.2.0.rc2 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.2.0.rc1.1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.2.0.rc1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.1.0.1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.1.0 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.1.0.rc2.1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.2 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.1.0.rc1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0.rc7 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0.rc5 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0.rc4 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0.rc3 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0.rc2 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb
katello-3.0.0.rc1 app/helpers/katello/concerns/smart_proxy_helper_extensions.rb