Skip to content

Commit

Permalink
#create_dialogs used by both create and update_catalog_item
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed May 4, 2017
1 parent ceefbbe commit c5f755e
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions app/models/service_template_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,9 @@ def self.create_catalog_item(options, auth_user)

transaction do
create_from_options(options).tap do |service_template|
[:provision, :retirement, :reconfigure].each do |action|
action_info = enhanced_config[action]
next unless service_template.send(:new_dialog_required?, action_info)

dialog_name = action_info[:new_dialog_name]
job_template = action_info[:configuration_template]
hosts = action_info[:hosts]

new_dialog = service_template.send(:create_new_dialog, dialog_name, job_template, hosts)
action_info[:dialog] = new_dialog
service_template.options[:config_info][action][:dialog_id] = new_dialog.id
end
dialog_ids = service_template.send(:create_dialogs, enhanced_config)
enhanced_config.deep_merge!(dialog_ids)
service_template.options[:config_info].deep_merge!(dialog_ids)
service_template.create_resource_actions(enhanced_config)
end
end
Expand Down Expand Up @@ -151,10 +142,15 @@ def update_catalog_item(options, auth_user = nil)

update_job_templates(name, description, config_info, auth_user)

updated_config = config_info.deep_merge(self.class.send(:create_job_templates, name, description, config_info, auth_user, self))
config_info.deep_merge!(self.class.send(:create_job_templates, name, description, config_info, auth_user, self))

create_dialogs(updated_config)
options[:config_info] = updated_config
[:provision, :retirement, :reconfigure].each do |action|
next unless config_info.key?(action)
config_info[action][:configuration_template] ||= job_template(action)
end
config_info.deep_merge!(create_dialogs(config_info))

options[:config_info] = config_info

super
end
Expand Down Expand Up @@ -186,11 +182,10 @@ def check_retirement_potential
end

def create_dialogs(config_info)
[:provision, :retirement, :reconfigure].each do |action|
[:provision, :retirement, :reconfigure].each_with_object({}) do |action, hash|
info = config_info[action]
if new_dialog_required?(info)
info[:dialog_id] = create_new_dialog(info[:new_dialog_name], job_template(action), info[:hosts]).id
end
next unless new_dialog_required?(info)
hash[action] = {:dialog_id => create_new_dialog(info[:new_dialog_name], info[:configuration_template], info[:hosts]).id}
end
end

Expand Down

0 comments on commit c5f755e

Please sign in to comment.