Skip to content

Commit

Permalink
Fixed initialization for default inventory value
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis committed Feb 17, 2017
1 parent f0e294e commit 04e8c76
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions app/controllers/miq_policy_controller/miq_actions.rb
Expand Up @@ -123,21 +123,17 @@ def action_field_changed
@refresh_inventory = false
if params[:inventory_manual] || params[:inventory_localhost] || params[:inventory_event_target]
@refresh_inventory = true
update_playbook_variables(params)
end

@edit[:new][:options][:service_template_id] = params[:service_template_id].to_i if params[:service_template_id]
@edit[:new][:inventory_type] = params[:inventory_manual] if params[:inventory_manual]
@edit[:new][:inventory_type] = params[:inventory_localhost] if params[:inventory_localhost]
@edit[:new][:inventory_type] = params[:inventory_event_target] if params[:inventory_event_target]
@edit[:new][:options][:use_event_target] = @edit[:new][:inventory_type] == 'event_target'
@edit[:new][:options][:use_localhost] = @edit[:new][:inventory_type] == 'localhost'
@edit[:new][:options][:hosts] = params[:hosts] if params[:hosts]

if params[:miq_action_type] && params[:miq_action_type] != @edit[:new][:action_type] # action type was changed
@edit[:new][:action_type] = params[:miq_action_type]
@edit[:new][:options] = {} # Clear out the options
action_build_alert_choices if params[:miq_action_type] == "evaluate_alerts" # Build alert choices hash
action_build_snmp_variables if params[:miq_action_type] == "snmp_trap" # Build snmp_trap variables hash
action_initialize_playbook_variables
if params[:miq_action_type] == "tag"
get_tags_tree
end
Expand All @@ -147,6 +143,20 @@ def action_field_changed
send_button_changes
end

def action_initialize_playbook_variables
@edit[:new][:options][:use_event_target] = @edit[:new][:inventory_type] == 'event_target'
@edit[:new][:options][:use_localhost] = @edit[:new][:inventory_type] == 'localhost'
end

def update_playbook_variables(params)
@edit[:new][:inventory_type] = params[:inventory_manual] if params[:inventory_manual]
@edit[:new][:inventory_type] = params[:inventory_localhost] if params[:inventory_localhost]
@edit[:new][:inventory_type] = params[:inventory_event_target] if params[:inventory_event_target]
@edit[:new][:options][:hosts] = '' if params[:inventory_localhost] || params[:inventory_event_target]
@edit[:new][:options][:use_event_target] = @edit[:new][:inventory_type] == 'event_target'
@edit[:new][:options][:use_localhost] = @edit[:new][:inventory_type] == 'localhost'
end

def action_tag_pressed
@edit = session[:edit]
@action = @edit[:action_id] ? MiqAction.find_by_id(@edit[:action_id]) : MiqAction.new
Expand Down Expand Up @@ -289,6 +299,7 @@ def action_build_edit_screen
@edit[:cats] = MiqAction.inheritable_cats.sort_by { |c| c.description.downcase }.collect { |c| [c.name, c.description] }

@edit[:ansible_playbooks] = ServiceTemplateAnsiblePlaybook.order(:name).pluck(:name, :id) || {}
@edit[:new][:inventory_type] = 'localhost'
action_build_playbook_variables if @action.action_type == "run_ansible_playbook"

@edit[:current] = copy_hash(@edit[:new])
Expand Down Expand Up @@ -345,7 +356,7 @@ def action_set_record_vars(action)
def action_build_playbook_variables
@edit[:new][:inventory_type] = 'manual' if @edit[:new][:options][:hosts]
@edit[:new][:inventory_type] = 'event_target' if @edit[:new][:options][:use_event_target]
@edit[:new][:inventory_type] ||= 'localhost'
@edit[:new][:inventory_type] = 'localhost' if @edit[:new][:options][:use_localhost]
end

# Check action record variables
Expand Down

0 comments on commit 04e8c76

Please sign in to comment.