Skip to content

Commit

Permalink
Merge pull request #1634 from h-kataria/container_template_catalog_item
Browse files Browse the repository at this point in the history
Added "Container Template" type support in Catalog Item editor
  • Loading branch information
Dan Clarizio authored Jul 6, 2017
2 parents c0fbac3 + 011fead commit d74c735
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 73 deletions.
94 changes: 76 additions & 18 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def explorer
end
template_locals = {:locals => {:controller => "catalog"}}
template_locals[:locals].merge!(fetch_playbook_details) if need_ansible_locals?
template_locals[:locals].merge!(fetch_ct_details) if need_container_template_locals?

render :layout => "application", :action => "explorer", :locals => template_locals
end
Expand Down Expand Up @@ -932,21 +933,27 @@ def atomic_req_submit
return
end
get_form_vars # need to get long_description
st = @edit[:rec_id] ?
ServiceTemplate.find_by_id(@edit[:rec_id]) :
class_service_template(@edit[:new][:st_prov_type]).new
common_st_record_vars(st)
add_orchestration_template_vars(st) if st.kind_of?(ServiceTemplateOrchestration)
add_ansible_tower_job_template_vars(st) if st.kind_of?(ServiceTemplateAnsibleTower)
st.service_type = "atomic"

if request
st.remove_all_resources
st.add_resource(request) if need_prov_dialogs?(@edit[:new][:st_prov_type])
if @edit[:new][:st_prov_type] == "generic_container_template"
st = @edit[:rec_id] ?
ServiceTemplateContainerTemplate.find_by(:id => @edit[:rec_id]).update_catalog_item(add_container_template_vars) :
ServiceTemplateContainerTemplate.create_catalog_item(add_container_template_vars)
else
st = @edit[:rec_id] ?
ServiceTemplate.find_by(:id => @edit[:rec_id]) :
class_service_template(@edit[:new][:st_prov_type]).new
common_st_record_vars(st)
add_orchestration_template_vars(st) if st.kind_of?(ServiceTemplateOrchestration)
add_ansible_tower_job_template_vars(st) if st.kind_of?(ServiceTemplateAnsibleTower)
st.service_type = "atomic"

if request
st.remove_all_resources
st.add_resource(request) if need_prov_dialogs?(@edit[:new][:st_prov_type])
end
end

if st.save
set_resource_action(st)
set_resource_action(st) unless st.kind_of?(ServiceTemplateContainerTemplate)
flash_key = params[:button] == "save" ? _("%{model} \"%{name}\" was saved") : _("%{model} \"%{name}\" was added")
add_flash(flash_key % {:model => ui_lookup(:model => "ServiceTemplate"), :name => @edit[:new][:name]})
@changed = session[:changed] = false
Expand Down Expand Up @@ -1334,6 +1341,7 @@ def set_form_vars
@edit[:new][:available_catalogs] = @edit[:new][:available_catalogs].sort
available_orchestration_templates if @record.kind_of?(ServiceTemplateOrchestration)
available_ansible_tower_managers if @record.kind_of?(ServiceTemplateAnsibleTower)
available_container_managers if @record.kind_of?(ServiceTemplateContainerTemplate)

# initialize fqnames
@edit[:new][:fqname] = @edit[:new][:reconfigure_fqname] = @edit[:new][:retire_fqname] = ""
Expand Down Expand Up @@ -1474,7 +1482,16 @@ def get_form_vars
@edit[:new][:long_description] = @edit[:new][:long_description].to_s + "..." if params[:transOne]

get_form_vars_orchestration if @edit[:new][:st_prov_type] == 'generic_orchestration'
get_form_vars_ansible_tower if @edit[:new][:st_prov_type] == 'generic_ansible_tower'
fetch_form_vars_ansible_or_ct if %w(generic_ansible_tower generic_container_template).include?(@edit[:new][:st_prov_type])
end

def available_container_managers
@edit[:new][:available_managers] =
ManageIQ::Providers::ContainerManager.all.collect { |t| [t.name, t.id] }.sort
ct = ContainerTemplate.find_by(:id => @record.config_info[:provision][:container_template_id]) if @record.config_info[:provision] && @record.config_info[:provision][:container_template_id]
@edit[:new][:template_id] = ct.try(:id)
@edit[:new][:manager_id] = ct.try(:ext_management_system).try(:id)
available_job_or_container_templates(@edit[:new][:manager_id]) if @edit[:new][:manager_id]
end

def get_form_vars_orchestration
Expand All @@ -1491,15 +1508,15 @@ def get_form_vars_orchestration
@edit[:new][:manager_id] = params[:manager_id] if params[:manager_id]
end

def get_form_vars_ansible_tower
def fetch_form_vars_ansible_or_ct
if params[:manager_id]
if params[:manager_id] == ""
@edit[:new][:available_templates] = []
@edit[:new][:template_id] = nil
@edit[:new][:manager_id] = nil
else
@edit[:new][:manager_id] = params[:manager_id]
available_ansible_tower_job_templates(params[:manager_id])
available_job_or_container_templates(params[:manager_id]) if %w(generic_ansible_tower generic_container_template).include?(@edit[:new][:st_prov_type])
end
end
@edit[:new][:template_id] = params[:template_id] if params[:template_id]
Expand Down Expand Up @@ -1528,17 +1545,18 @@ def available_orchestration_templates
available_orchestration_managers(@record.orchestration_template.id) if @record.orchestration_template
end

def available_ansible_tower_job_templates(manager_id)
def available_job_or_container_templates(manager_id)
method = @edit[:new][:st_prov_type] == 'generic_ansible_tower' ? 'configuration_scripts' : 'container_templates'
@edit[:new][:available_templates] =
ExtManagementSystem.find_by(:id => manager_id).configuration_scripts.collect { |t| [t.name, t.id] }.sort
ExtManagementSystem.find_by(:id => manager_id).send(method).collect { |t| [t.name, t.id] }.sort
end

def available_ansible_tower_managers
@edit[:new][:available_managers] =
ManageIQ::Providers::AnsibleTower::AutomationManager.all.collect { |t| [t.name, t.id] }.sort
@edit[:new][:template_id] = @record.job_template.try(:id)
@edit[:new][:manager_id] = @record.job_template.try(:manager).try(:id)
available_ansible_tower_job_templates(@edit[:new][:manager_id]) if @edit[:new][:manager_id]
available_job_or_container_templates(@edit[:new][:manager_id]) if @edit[:new][:manager_id]
end

def add_orchestration_template_vars(st)
Expand All @@ -1553,6 +1571,28 @@ def add_ansible_tower_job_template_vars(st)
nil : ConfigurationScript.find_by(:id => @edit[:new][:template_id])
end

def add_container_template_vars
st_options = {}
st_options[:name] = @edit[:new][:name]
st_options[:description] = @edit[:new][:description]
st_options[:long_description] = @edit[:new][:display] ? @edit[:new][:long_description] : nil
st_options[:provision_cost] = @edit[:new][:provision_cost]
st_options[:display] = @edit[:new][:display]

st_options[:service_template_catalog_id] = @edit[:new][:catalog_id].nil? ? nil : @edit[:new][:catalog_id]
st_options[:config_info] = {
:provision => {
:container_template_id => @edit[:new][:template_id],
:dialog_id => @edit[:new][:dialog_id]
}
}
provision = st_options[:config_info][:provision]
provision[:fqname] = @edit[:new][:fqname] if @edit[:new][:fqname]
provision[:reconfigure_fqname] = @edit[:new][:reconfigure_fqname] if @edit[:new][:reconfigure_fqname]
provision[:retire_fqname] = @edit[:new][:retire_fqname] if @edit[:new][:retire_fqname]
st_options
end

def st_get_form_vars
get_form_vars
if params[:resource_id]
Expand Down Expand Up @@ -1800,6 +1840,16 @@ def get_node_info(treenodeid, _show_list = true)
{:view => @view, :pages => @pages}
end

def fetch_ct_details
ct_details = {}
provision = @record.config_info[:provision]
ct_details[:provisioning] = {}
ct = ContainerTemplate.find_by(:id => provision[:container_template_id])
ct_details[:provisioning][:template_name] = ct.try(:name)
ct_details[:provisioning][:provider_name] = ct.try(:ext_management_system).try(:name)
ct_details
end

def fetch_playbook_details
playbook_details = {}
provision = @record.config_info[:provision]
Expand Down Expand Up @@ -1973,6 +2023,8 @@ def replace_right_cell(options = {})
else
template_locals = {:controller => "catalog"}
template_locals.merge!(fetch_playbook_details) if need_ansible_locals?
template_locals.merge!(fetch_ct_details) if need_container_template_locals?

r[:partial => "catalog/#{x_active_tree}_show", :locals => template_locals]
end
elsif @sb[:buttons_node]
Expand Down Expand Up @@ -2071,6 +2123,12 @@ def need_ansible_locals?
@record.prov_type == "generic_ansible_playbook"
end

def need_container_template_locals?
x_active_tree == :sandt_tree &&
TreeBuilder.get_model_for_prefix(@nodetype) == "ServiceTemplate" &&
@record.prov_type == "generic_container_template"
end

# Build a Catalog Items explorer tree
def build_st_tree
TreeBuilderCatalogItems.new('sandt_tree', 'sandt', @sb)
Expand Down
104 changes: 49 additions & 55 deletions app/views/catalog/_form_basic_info.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- url = url_for_only_path(:id => (@edit[:rec_id] || "new"),
- url = url_for(:id => "#{@edit[:rec_id] || "new"}",
:action => @edit[:new][:service_type] == "composite" ? "st_form_field_changed" : "atomic_form_field_changed")

#basic_info_div
Expand Down Expand Up @@ -52,13 +52,6 @@
:class => "selectpicker")
:javascript
miqSelectPickerEvent('dialog_id', '#{url}')
- if @edit[:new][:st_prov_type]
.form-group
%label.col-md-2.control-label
= _('Item Type')
.col-md-4
%p.form-control-static
= h(ServiceTemplate::CATALOG_ITEM_TYPES[@edit[:new][:st_prov_type]])
- if @edit[:new][:st_prov_type] == "generic"
.form-group
%label.col-md-2.control-label
Expand Down Expand Up @@ -99,7 +92,7 @@
:class => "selectpicker")
:javascript
miqSelectPickerEvent('manager_id', '#{url}')
- elsif @edit[:new][:st_prov_type] == "generic_ansible_tower"
- elsif %w(generic_ansible_tower generic_container_template).include?(@edit[:new][:st_prov_type])
- opts = [["<#{_('Choose')}>", nil]] + @edit[:new][:available_managers]
.form-group
%label.col-md-2.control-label
Expand All @@ -115,7 +108,7 @@
- opts = [["<#{_('Choose')}>", nil]] + @edit[:new][:available_templates]
.form-group
%label.col-md-2.control-label
= _('Ansible Tower Job Template')
= @edit[:new][:st_prov_type] == "generic_ansible_tower" ? _('Ansible Tower Job Template') : _('Container Template')
.col-md-8
= select_tag('template_id',
options_for_select(opts, @edit[:new][:template_id]),
Expand Down Expand Up @@ -145,49 +138,50 @@
:title => _("Remove this Provisioning Entry Point")) do
%i.pficon.pficon-close
%span.input-group-addon{:style => "visibility:hidden"}
.form-group
%label.col-md-2.control-label{:title => _("Reconfigure Entry Point (NameSpace/Class/Instance)")}
= _('Reconfigure Entry Point')
.col-md-8{:title => @edit[:new][:reconfigure_fqname]}
.input-group
= text_field_tag("reconfigure_fqname",
@edit[:new][:reconfigure_fqname],
:class => "form-control",
:onFocus => 'miqShowAE_Tree("reconfigure");miqButtons("hide", "automate");',
"data-miq_observe" => {:interval => '.5', :url => url}.to_json)
%span.input-group-btn
#reconfigure_fqname_div{:style => @edit[:new][:reconfigure_fqname] != "" ? "" : "display:none"}
= link_to({:action => 'ae_tree_select_discard',
:typ => "reconfigure"},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-confirm" => _("Are you sure you want to remove this Reconfigure Entry Point?"),
"data-method" => :post,
:remote => true,
:class => "btn btn-default",
:title => _("Remove this Reconfigure Entry Point")) do
%i.pficon.pficon-close
%span.input-group-addon{:style => "visibility:hidden"}
- unless @edit[:new][:st_prov_type] == 'generic_container_template'
.form-group
%label.col-md-2.control-label{:title => _("Reconfigure Entry Point (NameSpace/Class/Instance)")}
= _('Reconfigure Entry Point')
.col-md-8{:title => @edit[:new][:reconfigure_fqname]}
.input-group
= text_field_tag("reconfigure_fqname",
@edit[:new][:reconfigure_fqname],
:class => "form-control",
:onFocus => 'miqShowAE_Tree("reconfigure");miqButtons("hide", "automate");',
"data-miq_observe" => {:interval => '.5', :url => url}.to_json)
%span.input-group-btn
#reconfigure_fqname_div{:style => @edit[:new][:reconfigure_fqname] != "" ? "" : "display:none"}
= link_to({:action => 'ae_tree_select_discard',
:typ => "reconfigure"},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-confirm" => _("Are you sure you want to remove this Reconfigure Entry Point?"),
"data-method" => :post,
:remote => true,
:class => "btn btn-default",
:title => _("Remove this Reconfigure Entry Point")) do
%i.pficon.pficon-close
%span.input-group-addon{:style => "visibility:hidden"}
.form-group
%label.col-md-2.control-label{:title => _("Retirement Entry Point (NameSpace/Class/Instance)")}
= _('Retirement Entry Point')
.col-md-8{:title => @edit[:new][:retire_fqname]}
.input-group
= text_field_tag("retire_fqname",
@edit[:new][:retire_fqname],
:class => "form-control",
:onFocus => 'miqShowAE_Tree("retire");miqButtons("hide", "automate");')
%span.input-group-btn
#retire_fqname_div{:style => @edit[:new][:retire_fqname] != "" ? "" : "display:none"}
= link_to({:action => 'ae_tree_select_discard',
:typ => "retire"},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-confirm" => _("Are you sure you want to remove this Retirement Entry Point?"),
"data-method" => :post,
:remote => true,
:class => "btn btn-default",
:title => _("Remove this Retirement Entry Point")) do
%i.pficon.pficon-close
%span.input-group-addon{:style => "visibility:hidden"}
.form-group
%label.col-md-2.control-label{:title => _("Retirement Entry Point (NameSpace/Class/Instance)")}
= _('Retirement Entry Point')
.col-md-8{:title => @edit[:new][:retire_fqname]}
.input-group
= text_field_tag("retire_fqname",
@edit[:new][:retire_fqname],
:class => "form-control",
:onFocus => 'miqShowAE_Tree("retire");miqButtons("hide", "automate");')
%span.input-group-btn
#retire_fqname_div{:style => @edit[:new][:retire_fqname] != "" ? "" : "display:none"}
= link_to({:action => 'ae_tree_select_discard',
:typ => "retire"},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-confirm" => _("Are you sure you want to remove this Retirement Entry Point?"),
"data-method" => :post,
:remote => true,
:class => "btn btn-default",
:title => _("Remove this Retirement Entry Point")) do
%i.pficon.pficon-close
%span.input-group-addon{:style => "visibility:hidden"}
11 changes: 11 additions & 0 deletions app/views/catalog/_sandt_tree_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@
= _('Ansible Tower Job Template')
.col-md-9
= h(@record.try(:job_template).try(:name))
- elsif @record.prov_type == "generic_container_template"
.form-group
%label.col-md-3.control-label
= _('Provider')
.col-md-9
= h(provisioning[:provider_name])
.form-group
%label.col-md-3.control-label
= _('Container Template')
.col-md-9
= h(provisioning[:template_name])
- unless @record.prov_type == "generic_ansible_playbook"
- entry_points = [[_("Provisioning"), :fqname]]
- unless @record.prov_type.try(:start_with?, "generic_")
Expand Down
Loading

0 comments on commit d74c735

Please sign in to comment.