forked from ManageIQ/manageiq-ui-classic
/
automation_manager_controller.rb
494 lines (430 loc) · 17.5 KB
/
automation_manager_controller.rb
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
class AutomationManagerController < ApplicationController
before_action :check_privileges
before_action :get_session_data
after_action :cleanup_action
after_action :set_session_data
include Mixins::GenericSessionMixin
include Mixins::ManagerControllerMixin
include Mixins::ExplorerPresenterMixin
menu_section :at
def self.model
ManageIQ::Providers::AutomationManager
end
def self.table_name
@table_name ||= "automation_manager"
end
def self.model_to_name(provmodel)
if provmodel.include?("ManageIQ::Providers::AnsibleTower")
Dictionary.gettext('ansible_tower', :type => :ui_title, :translate => false)
end
end
def concrete_model
ManageIQ::Providers::AnsibleTower::AutomationManager
end
def managed_group_kls
ManageIQ::Providers::AutomationManager::InventoryRootGroup
end
def manager_prefix
'automation_manager'
end
def privilege_prefix
'automation_manager'
end
def tagging
@explorer ||= true
case x_active_accord
when :automation_manager_providers
assert_privileges("automation_manager_provider_tag")
tagging_edit(class_for_provider_node.to_s, false)
when :automation_manager_cs_filter
assert_privileges("automation_manager_configured_system_tag")
tagging_edit('ConfiguredSystem', false)
when :configuration_scripts
assert_privileges("automation_manager_configuration_script_tag")
tagging_edit('ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript', false)
end
render_tagging_form
end
def load_or_clear_adv_search
adv_search_build(configuration_manager_scripts_tree(x_active_tree))
session[:edit] = @edit
@explorer = true
if !filtering? || x_node == "root"
listnav_search_selected(0)
else
@nodetype, id = parse_nodetype_and_id(valid_active_node(x_node))
if filtering? && %w(xx-csa ms).include?(@nodetype)
search_id = from_cid(id)
listnav_search_selected(search_id) unless params.key?(:search_text) # Clear or set the adv search filter
if @edit[:adv_search_applied] &&
MiqExpression.quick_search?(@edit[:adv_search_applied][:exp]) &&
%w(reload tree_select).include?(params[:action])
self.x_node = params[:id]
quick_search_show
end
end
end
end
def x_show
tree_record
if request.format.js? && !@record
return
end
generic_x_show
end
def tree_record
@record =
case x_active_tree
when :automation_manager_providers_tree then automation_manager_providers_tree_rec
when :automation_manager_cs_filter_tree then automation_manager_cs_filter_tree_rec
when :configuration_scripts_tree then configuration_scripts_tree_rec
end
end
def class_for_provider_node
nodes = x_node.split('-')
case nodes.first
when "root" then ManageIQ::Providers::AnsibleTower::AutomationManager
when "at", "e" then ManageIQ::Providers::AutomationManager::InventoryRootGroup
when "f", "cs" then ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem
when "xx" then
case nodes.second
when "at" then ManageIQ::Providers::AnsibleTower::AutomationManager
when "csa" then ConfiguredSystem
end
end
end
def automation_manager_providers_tree_rec
find_record(class_for_provider_node, params[:id])
end
def automation_manager_cs_filter_tree_rec
nodes = x_node.split('-')
case nodes.first
when "root", "xx" then find_record(ConfiguredSystem, params[:id])
when "ms" then find_record(ConfiguredSystem, from_cid(params[:id]))
end
end
def configuration_scripts_tree_rec
nodes = x_node.split('-')
case nodes.first
when "root", "at", "cf"
find_record(ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript, params[:id])
end
end
def show_record(_id = nil)
@display = params[:display] || "main" unless pagination_or_gtl_request?
@lastaction = "show"
if @record.nil?
add_flash(_("Error: Record no longer exists in the database"), :error)
if request.xml_http_request? && params[:id] # Is this an Ajax request clicking on a node that no longer exists?
@delete_node = params[:id] # Set node to be removed from the tree
end
return
end
if @record.kind_of?(ConfiguredSystem)
rec_cls = "#{model_to_type_name(@record.ext_management_system.class.to_s)}_configured_system"
end
return unless @display == 'main'
@button_group = case x_active_accord
when :automation_manager_cs_filter
rec_cls.to_s
when :automation_manager_providers
"automation_manager_#{rec_cls}"
when :configuration_scripts
@record.kind_of?(ConfigurationScript) ? "configuration_script" : "configuration_scripts"
end
end
def configscript_service_dialog_submit
case params[:button]
when "cancel"
configscript_service_dialog_submit_cancel
when "save"
configscript_service_dialog_submit_save
end
end
def validate_before_save?
true
end
private
def textual_group_list
[%i(properties tags)]
end
helper_method :textual_group_list
def provider_class
ManageIQ::Providers::AnsibleTower::Provider
end
def features
[
{:role => "automation_manager_providers",
:role_any => true,
:name => :automation_manager_providers,
:title => _("Providers")},
{:role => "automation_manager_configured_system",
:role_any => true,
:name => :automation_manager_cs_filter,
:title => _("Configured Systems")},
{:role => "automation_manager_configuration_scripts_accord",
:role_any => true,
:name => :configuration_scripts,
:title => _("Job Templates")}
].map do |hsh|
ApplicationController::Feature.new_with_hash(hsh)
end
end
def build_automation_manager_tree(type, name)
tree = case name
when :automation_manager_providers_tree
TreeBuilderAutomationManagerProviders.new(name, type, @sb)
when :automation_manager_cs_filter_tree
TreeBuilderAutomationManagerConfiguredSystems.new(name, type, @sb)
else
TreeBuilderAutomationManagerConfigurationScripts.new(name, type, @sb)
end
instance_variable_set :"@#{name}", tree.tree_nodes
tree
end
def get_node_info(treenodeid, _show_list = true)
@sb[:action] = nil
@nodetype, id = parse_nodetype_and_id(valid_active_node(treenodeid))
model = TreeBuilder.get_model_for_prefix(@nodetype)
if model == "Hash"
model = TreeBuilder.get_model_for_prefix(id)
id = nil
end
case model
when "ManageIQ::Providers::AnsibleTower::AutomationManager", "ExtManagementSystem"
provider_list(id, "ManageIQ::Providers::AnsibleTower::AutomationManager")
when "EmsFolder"
inventory_group_node(id, model)
when "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem", "ConfiguredSystem"
configured_system_list(id, model)
when "ConfigurationScript"
configuration_scripts_list(id, model)
when "MiqSearch"
miq_search_node
else
default_node
end
# Edit right cell text if using filter
@right_cell_text += @edit[:adv_search_applied][:text] if x_tree && filtering? && @edit && @edit[:adv_search_applied]
if @edit && @edit.fetch_path(:adv_search_applied, :qs_exp) # If qs is active, save it in history
x_history_add_item(:id => x_node,
:qs_exp => @edit[:adv_search_applied][:qs_exp],
:text => @right_cell_text)
else
x_history_add_item(:id => treenodeid, :text => @right_cell_text) # Add to history pulldown array
end
{:view => @view, :pages => @pages}
end
def filtering?
%w(automation_manager_cs_filter configuration_scripts).include?(x_tree[:type].to_s)
end
def provider_node(id, model)
@record = provider = find_record(ExtManagementSystem, id)
if provider.nil?
self.x_node = "root"
get_node_info("root")
elsif x_active_tree == :configuration_scripts_tree
cs_provider_node(provider)
else
@show_adv_search = true
@no_checkboxes = true
options = {:model => "ManageIQ::Providers::AutomationManager::InventoryRootGroup",
:match_via_descendants => 'ConfiguredSystem',
:named_scope => [[:with_provider, provider.id]],
:gtl_dbname => "automation_manager_providers"}
process_show_list(options)
record_model = ui_lookup(:model => self.class.model_to_name(model || TreeBuilder.get_model_for_prefix(@nodetype)))
@right_cell_text = _("Inventory Groups under %{record_model} Provider \"%{name}\"") %
{:name => provider.name, :record_model => record_model}
end
end
def cs_provider_node(provider)
options = {:model => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript",
:match_via_descendants => 'ConfigurationScript',
:named_scope => [[:with_manager, provider.id]],
:gtl_dbname => "automation_manager_configuration_scripts"}
@show_adv_search = true
process_show_list(options)
@right_cell_text = _("Job Templates under \"%{name}\"") % {:name => provider.name}
end
def inventory_group_node(id, model)
@record = @inventory_group_record = find_record(ManageIQ::Providers::AutomationManager::InventoryRootGroup, id) if model
if @inventory_group_record.nil?
self.x_node = "root"
get_node_info("root")
else
@show_adv_search = true
options = {:model => "ConfiguredSystem",
:match_via_descendants => 'ConfiguredSystem',
:named_scope => [[:with_inventory_root_group, from_cid(@inventory_group_record.id)]],
:gtl_dbname => "automation_manager_configured_systems"}
process_show_list(options)
record_model = ui_lookup(:model => model || TreeBuilder.get_model_for_prefix(@nodetype))
if @sb[:active_tab] == 'configured_systems'
inventory_group_right_cell_text(model)
else
@pages = nil
@right_cell_text = _("%{model} \"%{name}\"") % {:name => @inventory_group_record.name, :model => record_model}
end
end
end
def configuration_scripts_list(id, model)
return configuration_script_node(id) if id
@show_adv_search = true
@listicon = "configuration_script"
if x_active_tree == :configuration_scripts_tree
options = {:model => model.to_s,
:gtl_dbname => "configuration_scripts"}
@right_cell_text = _("All Ansible Tower Job Templates")
process_show_list(options)
end
end
def configuration_script_node(id)
@record = @configuration_script_record = find_record(ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript, id)
@show_adv_search = false
display_node(id, nil)
end
def default_node
return unless x_node == "root"
@show_adv_search = true
if x_active_tree == :automation_manager_providers_tree
options = {:model => "ManageIQ::Providers::AnsibleTower::AutomationManager",
:gtl_dbname => "automation_manager_providers"}
process_show_list(options)
@right_cell_text = _("All Ansible Tower Providers")
elsif x_active_tree == :automation_manager_cs_filter_tree
options = {:model => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem",
:gtl_dbname => "automation_manager_configured_systems"}
process_show_list(options)
@right_cell_text = _("All Ansible Tower Configured Systems")
elsif x_active_tree == :configuration_scripts_tree
options = {:model => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript",
:gtl_dbname => "automation_manager_configuration_scripts"}
process_show_list(options)
@right_cell_text = _("All Ansible Tower Job Templates")
end
end
def rebuild_trees(replace_trees)
build_replaced_trees(replace_trees, %i(automation_manager_providers automation_manager_cs_filter configuration_scripts))
end
def leaf_record
get_node_info(x_node)
@delete_node = params[:id] if @replace_trees
type, _id = parse_nodetype_and_id(x_node)
type && %w(ConfiguredSystem ConfigurationScript).include?(TreeBuilder.get_model_for_prefix(type))
end
def managed_group_record?(node = x_node)
type, _id = parse_nodetype_and_id(node)
type && %w(EmsFolder).include?(TreeBuilder.get_model_for_prefix(type))
end
def automation_manager_manager_record?(node = x_node)
return @record.kind_of?(ManageIQ::Providers::AnsibleTower::AutomationManager) if @record
type, _id = node.split("-")
type && ["ManageIQ::Providers::AnsibleTower::AutomationManager"].include?(TreeBuilder.get_model_for_prefix(type))
end
def provider_record?(node = x_node)
automation_manager_manager_record?(node)
end
def search_text_type(node)
return "provider" if provider_record?(node)
return "inventory_group" if managed_group_record?(node)
node
end
def update_partials(record_showing, presenter)
if record_showing && valid_configured_system_record?(@configured_system_record)
get_tagdata(@record)
presenter.hide(:form_buttons_div)
presenter.update(:main_div, r[:partial => "layouts/textual_groups_generic"])
elsif @in_a_form
partial_locals = {:controller => controller_name}
@right_cell_text =
if @sb[:action] == "automation_manager_add_provider"
_("Add a new Automation Manager Provider")
elsif @sb[:action] == "automation_manager_edit_provider"
_("Edit Provider")
end
partial = 'form'
presenter.update(:main_div, r[:partial => partial, :locals => partial_locals])
elsif valid_managed_group_record?(@inventory_group_record)
presenter.hide(:form_buttons_div)
presenter.update(:main_div, r[:partial => "inventory_group",
:locals => {:controller => controller_name}])
elsif valid_configuration_script_record?(@configuration_script_record)
presenter.hide(:form_buttons_div)
presenter.update(:main_div, r[:partial => "configuration_script",
:locals => {:controller => controller_name}])
else
presenter.update(:main_div, r[:partial => 'layouts/x_gtl'])
end
end
def group_summary_tab_selected?
@inventory_group_record && @sb[:active_tab] == 'summary'
end
def locals_for_service_dialog
{:action_url => 'service_dialog',
:no_reset => true,
:record_id => @sb[:rec_id] || @edit[:object_ids] && @edit[:object_ids][0]}
end
def update_service_dialog_partials(presenter)
presenter.update(:main_div, r[:partial => 'configscript_service_dialog',
:locals => locals_for_service_dialog])
locals = {:record_id => @edit[:rec_id],
:action_url => "configscript_service_dialog_submit",
:no_reset => true,
:serialize => true}
presenter.update(:form_buttons_div, r[:partial => 'layouts/x_edit_buttons', :locals => locals])
end
def active_tab_configured_systems?
(%w(x_show x_search_by_name).include?(action_name) && managed_group_record?)
end
def empty_managed_group_record?(inventory_group_record)
inventory_group_record.try(:id).nil?
end
def valid_managed_group_record?(inventory_group_record)
inventory_group_record.try(:id)
end
def inventory_group_right_cell_text(_model)
return if @sb[:active_tab] != 'configured_systems'
if valid_managed_group_record?(@inventory_group_record)
@right_cell_text = _("Configured Systems under Inventory Group \"%{name}\"") %
{:name => @inventory_group_record.name}
end
end
def valid_configuration_script_record?(configuration_script_record)
configuration_script_record.try(:id)
end
def configscript_service_dialog
assert_privileges("automation_manager_configuration_script_service_dialog")
cs = ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript.find_by(:id => params[:id])
@edit = {:new => {:dialog_name => ""},
:key => "cs_edit__#{cs.id}",
:rec_id => cs.id}
@in_a_form = true
@right_cell_text = _("Adding a new Service Dialog from \"%{name}\"") % {:name => cs.name}
render_service_dialog_form
end
def configscript_service_dialog_submit_cancel
add_flash(_("Creation of a new Service Dialog was cancelled by the user"))
@in_a_form = false
@edit = @record = nil
replace_right_cell
end
def configscript_service_dialog_submit_save
assert_privileges("automation_manager_configuration_script_service_dialog")
load_edit("cs_edit__#{params[:id]}", "replace_cell__explorer")
begin
cs = ConfigurationScript.find_by(:id => params[:id])
AnsibleTowerJobTemplateDialogService.new.create_dialog(cs, @edit[:new][:dialog_name])
rescue => bang
add_flash(_("Error when creating Service Dialog: %{error_message}") %
{:error_message => bang.message}, :error)
javascript_flash
else
add_flash(_("Service Dialog \"%{name}\" was successfully created") %
{:name => @edit[:new][:dialog_name]}, :success)
@in_a_form = false
@edit = @record = nil
replace_right_cell
end
end
end