Module: Katello::Concerns::SmartProxyHelperExtensions

Defined in:
app/helpers/katello/concerns/smart_proxy_helper_extensions.rb

Instance Method Summary collapse

Instance Method Details

#available_percent(percent_string) ⇒ Object



27
28
29
30
31
# File 'app/helpers/katello/concerns/smart_proxy_helper_extensions.rb', line 27

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

#boolean_to_icon(boolean) ⇒ Object



21
22
23
24
25
# File 'app/helpers/katello/concerns/smart_proxy_helper_extensions.rb', line 21

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

#disks(storage) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/katello/concerns/smart_proxy_helper_extensions.rb', line 4

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

#kb_to_actual(number) ⇒ Object



45
46
47
48
# File 'app/helpers/katello/concerns/smart_proxy_helper_extensions.rb', line 45

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

#storage_warning(available) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/katello/concerns/smart_proxy_helper_extensions.rb', line 33

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