This repository was archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcontainers_helper.rb
More file actions
124 lines (108 loc) · 4.31 KB
/
Copy pathcontainers_helper.rb
File metadata and controls
124 lines (108 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module ContainersHelper
def managed?(container, resource)
uuids_in_resource(resource).include? container.identity
end
def uuids_in_resource(resource)
@uuids_in_resource ||= {}
@uuids_in_resource[resource.id] ||= Container.where(:compute_resource_id => resource.id)
.pluck(:uuid)
end
def link_to_container(container, resource)
link_to_if_authorized container.name[1..-1].titleize,
container_link_hash(container, resource)
end
def link_to_taxonomies(taxonomies)
taxonomies.map { |taxonomy| link_to(taxonomy) }.join(" ")
end
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
def container_title(container)
title = container.name.titleize
title += if container.uuid.present?
"- #{container.in_fog.name}"
else
_(" - provisioning ") + image_tag('spinner.gif')
end
title(container.name.titleize, title.html_safe)
end
def container_title_actions(container)
@compute_resource = container.compute_resource
container_title(container)
title_actions(
button_group(link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal')),
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))
) if container.uuid.present?
end
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
def power_on_off_message(vm)
_("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip,
:vm => vm }
end
def auto_complete_docker_search(name, val, options = {})
addClass options, 'form-control'
text_field_tag(name, val, options)
end
def hub_url(image)
if image['is_official']
"https://registry.hub.docker.com/_/#{image['name']}"
else
"https://registry.hub.docker.com/u/#{image['name']}"
end
end
# Compatibility fixes - to be removed once 1.7 compatibility is no longer required
if SETTINGS[:version].to_s.to_f <= 1.7
def trunc_with_tooltip(text, length = 32)
trunc(text, length)
end
end
def processes(container)
ForemanDocker::Docker.get_container(container).top
end
def logs(container, opts = {})
ForemanDocker::Docker.get_container(container).logs(opts)
end
def fog_property(container)
return 'Not available' unless container.uuid.present?
yield
end
def pair_attributes_table(attributes)
table = "<table id='environment_variables' class='table table-bordered'
style='table-layout:fixed; word-wrap: break-word'>"
attributes.each do |pair|
pair = pair.split("=")
table += "<tr><td><b> #{pair.first} </b></td><td><i> #{pair.second} </i></td></tr>"
end
table += '</table>'
table.html_safe
end
end