Module: ComputeResourcesHelper

Includes:
LookupKeysHelper
Defined in:
app/helpers/compute_resources_helper.rb

Instance Method Summary collapse

Methods included from LookupKeysHelper

#add_child_link, #host_key_with_diagnostic, #hostgroup_key_with_diagnostic, #new_child_fields_template, #overridable_lookup_keys, #param_type_selector, #remove_child_link, #show_puppet_class, #validator_type_selector

Instance Method Details

#list_datacenters(compute) ⇒ Object


33
34
35
36
37
38
39
40
41
# File 'app/helpers/compute_resources_helper.rb', line 33

def list_datacenters compute
  return [] unless compute.uuid || controller.action_name == 'test_connection'
  compute.datacenters
rescue Foreman::FingerprintException => e
  compute.errors[:pubkey_hash] = e
  []
rescue
  []
end

#memory_options(max_memory) ⇒ Object


23
24
25
26
27
# File 'app/helpers/compute_resources_helper.rb', line 23

def memory_options max_memory
  gb = 1024*1024*1024
  opts = [0.25, 0.5, 0.75, 1, 2, 4, 8, 16]
  opts.map{|n| [number_to_human_size(n*gb), (n*gb).to_i] unless n > (max_memory / gb)}.compact
end

#password_placeholder(obj) ⇒ Object


29
30
31
# File 'app/helpers/compute_resources_helper.rb', line 29

def password_placeholder(obj)
  obj.id ? "********" : ""
end

#show_console_action(state, link) ⇒ Object


4
5
6
# File 'app/helpers/compute_resources_helper.rb', line 4

def show_console_action(state, link)
  state ? link : ""
end

#vm_power_action(vm) ⇒ Object


16
17
18
19
20
21
# File 'app/helpers/compute_resources_helper.rb', line 16

def vm_power_action vm
  opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity)
  html = vm.ready? ? { :confirm => _('Are you sure?'), :class => "btn btn-small btn-danger" } : { :class => "btn btn-small btn-info" }

  display_link_if_authorized (_("Power %s") % vm_state(vm.ready?)), opts, html.merge(:method => :put)
end

#vm_power_class(s) ⇒ Object


12
13
14
# File 'app/helpers/compute_resources_helper.rb', line 12

def vm_power_class s
  "class='label #{s ? "label-success" : ""}'".html_safe
end

#vm_state(s) ⇒ Object


8
9
10
# File 'app/helpers/compute_resources_helper.rb', line 8

def vm_state s
  s ? ' ' + _("Off") : ' ' + _("On")
end