Module: ContainersHelper

Defined in:
app/helpers/containers_helper.rb

Instance Method Summary collapse

Instance Method Details



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, authorizer = 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 => 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 => authorizer)
  end
  html = if vm.ready?
           { :confirm => power_on_off_message(vm), :class => "btn btn-danger" }
         else
           { :class => "btn btn-info" }
         end

  display_link_if_authorized "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(
    button_group(
      link_to(_('Commit'), '#commit-modal',
              :'data-toggle' => 'modal',
              :class => 'btn btn-default')
    ),
    button_group(container_power_action(container.in_fog)),
    button_group(
      display_delete_if_authorized(
        hash_for_container_path(:id => container.id)
                                .merge(:auth_object => container,
                                       :auth_action => 'destroy',
                                       :authorizer  => authorizer),
        :confirm => _("Delete %s?") % container.name,
        :class => 'btn btn-default')
    )
  )
end


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

def link_to_container(container, resource)
  link_to_if_authorized container.name[1..-1].titleize,
                        container_link_hash(container, resource)
end


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

Returns:

  • (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 power_on_off_message(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