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 |
|
|
button_group(
|
34 |
387babdd
|
Daniel Lobato
|
link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal')
|
35 |
f880f56e
|
Daniel Lobato
|
),
|
36 |
e6eb1c48
|
Dmitri Dolguikh
|
button_group(container_power_action(container.in_fog)),
|
37 |
f880f56e
|
Daniel Lobato
|
button_group(
|
38 |
|
|
display_delete_if_authorized(
|
39 |
|
|
hash_for_container_path(:id => container.id)
|
40 |
|
|
.merge(:auth_object => container,
|
41 |
|
|
:auth_action => 'destroy',
|
42 |
|
|
:authorizer => authorizer),
|
43 |
|
|
:confirm => _("Delete %s?") % container.name)
|
44 |
|
|
)
|
45 |
|
|
)
|
46 |
|
|
end
|
47 |
fe8bb25c
|
Dmitri Dolguikh
|
|
48 |
e6eb1c48
|
Dmitri Dolguikh
|
def container_power_action(vm, authorizer = nil)
|
49 |
|
|
if managed?(vm, @compute_resource)
|
50 |
|
|
id = Container.find_by_uuid(vm.identity).id
|
51 |
|
|
opts = hash_for_power_container_path(:id => id)
|
52 |
|
|
.merge(:auth_object => @compute_resource,
|
53 |
|
|
:permission => 'power_compute_resources_vms',
|
54 |
|
|
:authorizer => authorizer)
|
55 |
|
|
else
|
56 |
|
|
opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource,
|
57 |
|
|
:id => vm.identity)
|
58 |
|
|
.merge(:auth_object => @compute_resource, :permission => 'power_compute_resources_vms',
|
59 |
|
|
:authorizer => authorizer)
|
60 |
|
|
end
|
61 |
|
|
html = if vm.ready?
|
62 |
|
|
{ :confirm => power_on_off_message(vm), :class => "btn btn-danger" }
|
63 |
|
|
else
|
64 |
|
|
{ :class => "btn btn-info" }
|
65 |
|
|
end
|
66 |
|
|
|
67 |
|
|
display_link_if_authorized "Power #{action_string(vm)}", opts, html.merge(:method => :put)
|
68 |
|
|
end
|
69 |
|
|
|
70 |
|
|
def power_on_off_message(vm)
|
71 |
|
|
_("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip,
|
72 |
|
|
:vm => vm }
|
73 |
|
|
end
|
74 |
|
|
|
75 |
1f6d29aa
|
Ohad Levy
|
def auto_complete_docker_search(name, val, options = {})
|
76 |
5b5de864
|
Daniel Lobato
|
addClass options, 'form-control'
|
77 |
fe8bb25c
|
Dmitri Dolguikh
|
text_field_tag(name, val, options)
|
78 |
|
|
end
|
79 |
6225eda9
|
Daniel Lobato
|
|
80 |
|
|
def hub_url(image)
|
81 |
|
|
if image['is_official']
|
82 |
|
|
"https://registry.hub.docker.com/_/#{image['name']}"
|
83 |
|
|
else
|
84 |
|
|
"https://registry.hub.docker.com/u/#{image['name']}"
|
85 |
|
|
end
|
86 |
|
|
end
|
87 |
5d7016fd
|
Daniel Lobato
|
|
88 |
|
|
|
89 |
|
|
if SETTINGS[:version].to_s.to_f <= 1.7
|
90 |
|
|
def trunc_with_tooltip(text, length = 32)
|
91 |
|
|
trunc(text, length)
|
92 |
|
|
end
|
93 |
|
|
end
|
94 |
5397ee73
|
David Davis
|
|
95 |
|
|
def processes(container)
|
96 |
|
|
ForemanDocker::Docker.get_container(container).top
|
97 |
|
|
end
|
98 |
|
|
|
99 |
|
|
def logs(container, opts = {})
|
100 |
329b84dd
|
David Davis
|
ForemanDocker::Docker.get_container(container).logs(opts)
|
101 |
5397ee73
|
David Davis
|
end
|
102 |
3eab3643
|
Daniel Lobato
|
end |