foreman/app/helpers/compute_resources_helper.rb @ bf4a13d3
334d0359 | Amos Benari | module ComputeResourcesHelper
|
|
include LookupKeysHelper
|
|||
50a072f2 | Sam Kottler | def show_console_action(state, link)
|
|
state ? link : ""
|
|||
end
|
|||
a6ce3c99 | Daniel Lobato | def vm_state vm
|
|
if vm.state == 'PAUSED'
|
|||
' ' + _("Paused")
|
|||
else
|
|||
vm.ready? ? _("On") : _("Off")
|
|||
end
|
|||
end
|
|||
def action_string vm
|
|||
vm.ready? ? ' ' + _("Off") : ' ' + _("On")
|
|||
334d0359 | Amos Benari | end
|
|
def vm_power_class s
|
|||
bf4a13d3 | Walden Raines | "class='label #{s ? "label-success" : "label-default"}'".html_safe
|
|
334d0359 | Amos Benari | end
|
|
def vm_power_action vm
|
|||
opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity)
|
|||
a6ce3c99 | Daniel Lobato | html = vm.ready? ? { :confirm =>_("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip, :vm => vm } , :class => "btn btn-danger" } :
|
|
{ :class => "btn btn-info" }
|
|||
display_link_if_authorized "Power #{action_string(vm)}", opts, html.merge(:method => :put)
|
|||
end
|
|||
def vm_pause_action vm
|
|||
opts = hash_for_pause_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity)
|
|||
pause_action = vm.ready? ? _('Pause') : _('Resume')
|
|||
html = vm.state.downcase == 'paused' ? { :class => "btn btn-info" } :
|
|||
{ :confirm =>_("Are you sure you want to %{act} %{vm}?") % { :act => pause_action.downcase, :vm => vm } , :class => "btn btn-danger" }
|
|||
334d0359 | Amos Benari | ||
a6ce3c99 | Daniel Lobato | display_link_if_authorized pause_action, opts, html.merge(:method => :put)
|
|
334d0359 | Amos Benari | end
|
|
def memory_options max_memory
|
|||
gb = 1024*1024*1024
|
|||
opts = [0.25, 0.5, 0.75, 1, 2, 4, 8, 16]
|
|||
f37934af | Ohad Levy | opts.map{|n| [number_to_human_size(n*gb), (n*gb).to_i] unless n > (max_memory / gb)}.compact
|
|
334d0359 | Amos Benari | end
|
|
ddb54f0b | Amos Benari | ||
def password_placeholder(obj)
|
|||
obj.id ? "********" : ""
|
|||
end
|
|||
617ee75f | Amos Benari | ||
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
|
|||
334d0359 | Amos Benari | end
|