1 |
3eab3643
|
Daniel Lobato
|
module ContainersHelper
|
2 |
f880f56e
|
Daniel Lobato
|
def managed?(container, resource)
|
3 |
|
|
uuids_in_resource(resource).include? container.identity
|
4 |
|
|
end
|
5 |
|
|
|
6 |
38e5019c
|
Daniel Lobato
|
def uuids_in_resource(resource)
|
7 |
0838802d
|
Ohad Levy
|
@uuids_in_resource ||= {}
|
8 |
|
|
@uuids_in_resource[resource.id] ||= Container.where(:compute_resource_id => resource.id)
|
9 |
ac230210
|
David Davis
|
.pluck(:uuid)
|
10 |
38e5019c
|
Daniel Lobato
|
end
|
11 |
f880f56e
|
Daniel Lobato
|
|
12 |
|
|
def link_to_container(container, resource)
|
13 |
|
|
link_to_if_authorized container.name[1..-1].titleize,
|
14 |
|
|
container_link_hash(container, resource)
|
15 |
|
|
end
|
16 |
|
|
|
17 |
30891c0a
|
Daniel Lobato
|
def link_to_taxonomies(taxonomies)
|
18 |
4282fa50
|
David Davis
|
taxonomies.map { |taxonomy| link_to(taxonomy) }.join(" ")
|
19 |
30891c0a
|
Daniel Lobato
|
end
|
20 |
|
|
|
21 |
f880f56e
|
Daniel Lobato
|
def container_link_hash(container, resource)
|
22 |
|
|
if managed?(container, resource)
|
23 |
|
|
hash_for_container_path(:id => Container.find_by_uuid(container.identity).id)
|
24 |
|
|
else
|
25 |
|
|
hash_for_compute_resource_vm_path(:compute_resource_id => resource,
|
26 |
|
|
:id => container.identity)
|
27 |
|
|
end
|
28 |
|
|
end
|
29 |
|
|
|
30 |
|
|
def container_title_actions(container)
|
31 |
|
|
@compute_resource = container.compute_resource
|
32 |
|
|
title_actions(
|
33 |
7ff105d1
|
David Davis
|
button_group(
|
34 |
b10c1ca7
|
Daniel Lobato
|
link_to(_('Commit'), '#commit-modal',
|
35 |
|
|
:'data-toggle' => 'modal',
|
36 |
|
|
:class => 'btn btn-default')
|
37 |
7ff105d1
|
David Davis
|
),
|
38 |
|
|
button_group(container_power_action(container.in_fog)),
|
39 |
|
|
button_group(
|
40 |
|
|
display_delete_if_authorized(
|
41 |
|
|
hash_for_container_path(:id => container.id)
|
42 |
|
|
.merge(:auth_object => container,
|
43 |
|
|
:auth_action => 'destroy',
|
44 |
|
|
:authorizer => authorizer),
|
45 |
b10c1ca7
|
Daniel Lobato
|
:confirm => _("Delete %s?") % container.name,
|
46 |
|
|
:class => 'btn btn-default')
|
47 |
7ff105d1
|
David Davis
|
)
|
48 |
f880f56e
|
Daniel Lobato
|
)
|
49 |
|
|
end
|
50 |
fe8bb25c
|
Dmitri Dolguikh
|
|
51 |
e6eb1c48
|
Dmitri Dolguikh
|
def container_power_action(vm, authorizer = nil)
|
52 |
|
|
if managed?(vm, @compute_resource)
|
53 |
|
|
id = Container.find_by_uuid(vm.identity).id
|
54 |
|
|
opts = hash_for_power_container_path(:id => id)
|
55 |
|
|
.merge(:auth_object => @compute_resource,
|
56 |
|
|
:permission => 'power_compute_resources_vms',
|
57 |
|
|
:authorizer => authorizer)
|
58 |
|
|
else
|
59 |
|
|
opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource,
|
60 |
|
|
:id => vm.identity)
|
61 |
|
|
.merge(:auth_object => @compute_resource, :permission => 'power_compute_resources_vms',
|
62 |
|
|
:authorizer => authorizer)
|
63 |
|
|
end
|
64 |
|
|
html = if vm.ready?
|
65 |
|
|
{ :confirm => power_on_off_message(vm), :class => "btn btn-danger" }
|
66 |
|
|
else
|
67 |
|
|
{ :class => "btn btn-info" }
|
68 |
|
|
end
|
69 |
|
|
|
70 |
|
|
display_link_if_authorized "Power #{action_string(vm)}", opts, html.merge(:method => :put)
|
71 |
|
|
end
|
72 |
|
|
|
73 |
|
|
def power_on_off_message(vm)
|
74 |
|
|
_("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip,
|
75 |
7ff105d1
|
David Davis
|
:vm => vm }
|
76 |
e6eb1c48
|
Dmitri Dolguikh
|
end
|
77 |
|
|
|
78 |
5397ee73
|
David Davis
|
def processes(container)
|
79 |
|
|
ForemanDocker::Docker.get_container(container).top
|
80 |
|
|
end
|
81 |
|
|
|
82 |
|
|
def logs(container, opts = {})
|
83 |
329b84dd
|
David Davis
|
ForemanDocker::Docker.get_container(container).logs(opts)
|
84 |
5397ee73
|
David Davis
|
end
|
85 |
3eab3643
|
Daniel Lobato
|
end |