Module: ContainersHelper
- Defined in:
- app/helpers/containers_helper.rb
Instance Method Summary collapse
- #container_link_hash(container, resource) ⇒ Object
- #container_power_action(vm, authorizer = nil) ⇒ Object
- #container_title_actions(container) ⇒ Object
- #link_to_container(container, resource) ⇒ Object
- #link_to_taxonomies(taxonomies) ⇒ Object
- #logs(container, opts = {}) ⇒ Object
- #managed?(container, resource) ⇒ Boolean
- #power_on_off_message(vm) ⇒ Object
- #processes(container) ⇒ Object
- #uuids_in_resource(resource) ⇒ Object
Instance Method Details
#container_link_hash(container, resource) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/helpers/containers_helper.rb', line 21 def container_link_hash(container, resource) if managed?(container, resource) hash_for_container_path(:id => Container.find_by_uuid(container.identity).id) else hash_for_compute_resource_vm_path(:compute_resource_id => resource, :id => container.identity) end end |
#container_power_action(vm, authorizer = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/containers_helper.rb', line 51 def container_power_action(vm, = nil) if managed?(vm, @compute_resource) id = Container.find_by_uuid(vm.identity).id opts = hash_for_power_container_path(:id => id) .merge(:auth_object => @compute_resource, :permission => 'power_compute_resources_vms', :authorizer => ) else opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity) .merge(:auth_object => @compute_resource, :permission => 'power_compute_resources_vms', :authorizer => ) end html = if vm.ready? { :confirm => (vm), :class => "btn btn-danger" } else { :class => "btn btn-info" } end "Power #{action_string(vm)}", opts, html.merge(:method => :put) end |
#container_title_actions(container) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/containers_helper.rb', line 30 def container_title_actions(container) @compute_resource = container.compute_resource title_actions( ( link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal', :class => 'btn btn-default') ), (container_power_action(container.in_fog)), ( ( hash_for_container_path(:id => container.id) .merge(:auth_object => container, :auth_action => 'destroy', :authorizer => ), :confirm => _("Delete %s?") % container.name, :class => 'btn btn-default') ) ) end |
#link_to_container(container, resource) ⇒ Object
12 13 14 15 |
# File 'app/helpers/containers_helper.rb', line 12 def link_to_container(container, resource) container.name[1..-1].titleize, container_link_hash(container, resource) end |
#link_to_taxonomies(taxonomies) ⇒ Object
17 18 19 |
# File 'app/helpers/containers_helper.rb', line 17 def link_to_taxonomies(taxonomies) taxonomies.map { |taxonomy| link_to(taxonomy) }.join(" ") end |
#logs(container, opts = {}) ⇒ Object
82 83 84 |
# File 'app/helpers/containers_helper.rb', line 82 def logs(container, opts = {}) ForemanDocker::Docker.get_container(container).logs(opts) end |
#managed?(container, resource) ⇒ Boolean
2 3 4 |
# File 'app/helpers/containers_helper.rb', line 2 def managed?(container, resource) uuids_in_resource(resource).include? container.identity end |
#power_on_off_message(vm) ⇒ Object
73 74 75 76 |
# File 'app/helpers/containers_helper.rb', line 73 def (vm) _("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip, :vm => vm } end |
#processes(container) ⇒ Object
78 79 80 |
# File 'app/helpers/containers_helper.rb', line 78 def processes(container) ForemanDocker::Docker.get_container(container).top end |
#uuids_in_resource(resource) ⇒ Object
6 7 8 9 10 |
# File 'app/helpers/containers_helper.rb', line 6 def uuids_in_resource(resource) @uuids_in_resource ||= {} @uuids_in_resource[resource.id] ||= Container.where(:compute_resource_id => resource.id) .pluck(:uuid) end |