Revision 1ef8f52b
Added by Ondřej Pražák about 8 years ago
app/controllers/hosts_controller.rb | ||
---|---|---|
before_filter :ajax_request, :only => AJAX_REQUESTS
|
||
before_filter :find_resource, :only => [:show, :clone, :edit, :update, :destroy, :puppetrun, :review_before_build,
|
||
:setBuild, :cancelBuild, :power, :overview, :bmc, :vm,
|
||
:runtime, :resources, :templates, :nics, :ipmi_boot, :console,
|
||
:runtime, :resources, :nics, :ipmi_boot, :console,
|
||
:toggle_manage, :pxe_config, :storeconfig_klasses, :disassociate]
|
||
|
||
before_filter :taxonomy_scope, :only => [:new, :edit] + AJAX_REQUESTS
|
||
... | ... | |
end
|
||
|
||
def templates
|
||
render :text => view_context.show_templates
|
||
rescue ActionView::Template::Error => exception
|
||
find_templates
|
||
render :partial => 'templates'
|
||
rescue => exception
|
||
process_ajax_error exception, 'fetch templates information'
|
||
end
|
||
|
||
... | ... | |
end
|
||
redirect_back_or_to hosts_path
|
||
end
|
||
|
||
def find_templates
|
||
find_resource
|
||
@templates = TemplateKind.order(:name).map do |kind|
|
||
@host.provisioning_template(:kind => kind.name)
|
||
end.compact
|
||
raise Foreman::Exception.new(N_("No templates found")) if @templates.empty?
|
||
end
|
||
end
|
app/helpers/hosts_helper.rb | ||
---|---|---|
(SETTINGS[:unattended] and host.managed?) ? host.shortname : host.name
|
||
end
|
||
|
||
def show_templates
|
||
unless SETTINGS[:unattended] and @host.managed?
|
||
return alert(:class=> 'alert-warning',
|
||
:text => _("Provisioning support is disabled or this host is not managed"))
|
||
end
|
||
begin
|
||
templates = Hash[TemplateKind.order(:name).map do |k|
|
||
template = @host.provisioning_template(:kind => k.name)
|
||
next if template.nil?
|
||
[k.name, template]
|
||
end.compact]
|
||
rescue => e
|
||
return case e.to_s
|
||
when "Must provide an operating systems"
|
||
_("Unable to find templates as this host has no operating system")
|
||
else
|
||
e.to_s
|
||
end
|
||
end
|
||
|
||
return _("No template found") if templates.empty?
|
||
content_tag :table, :class=>"table table-bordered table-striped" do
|
||
content_tag(:th, _("Template Type")) + content_tag(:th) +
|
||
templates.map do |kind, tmplt|
|
||
content_tag :tr do
|
||
content_tag(:td, _("%s Template") % kind) +
|
||
content_tag(:td,
|
||
action_buttons(
|
||
display_link_if_authorized(_("Edit"), hash_for_edit_provisioning_template_path(:id => tmplt.to_param), :rel => "external"),
|
||
link_to(_("Review"), url_for(:controller => '/unattended', :action => 'host_template',
|
||
:kind => kind, :hostname => @host.name),
|
||
:rel => 'external', :"data-provisioning-template" => true))
|
||
)
|
||
end
|
||
end.join(" ").html_safe
|
||
end
|
||
end
|
||
|
||
def overview_fields(host)
|
||
global_status = host.build_global_status
|
||
fields = [
|
app/models/template_kind.rb | ||
---|---|---|
has_many :os_default_templates
|
||
validates :name, :presence => true, :uniqueness => true
|
||
scoped_search :on => :name
|
||
|
||
def self.jar
|
||
@jar ||= { "PXELinux" => N_("PXE Linux Template"),
|
||
"PXEGrub" => N_("PXE Grub Template"),
|
||
"iPXE" => N_("iPXE Template"),
|
||
"provision" => N_("Provision Template"),
|
||
"finish" => N_("Finish Template"),
|
||
"script" => N_("Script Template"),
|
||
"user_data" => N_("User Data Template"),
|
||
"ZTP" => N_("ZTP Template"),
|
||
"POAP" => N_("POAP Template")
|
||
}
|
||
end
|
||
|
||
def self.add_to_jar(hash)
|
||
jar.merge!(hash) { |key| raise Foreman::Exception.new(N_("Cannot add template with key %s, it already exists"), key) }
|
||
end
|
||
|
||
def to_s
|
||
TemplateKind.jar[name] || name
|
||
end
|
||
end
|
app/services/foreman/plugin.rb | ||
---|---|---|
@to_prepare_callbacks << block
|
||
end
|
||
|
||
# add human readable label for plugin's template kind with i18n support: template_labels "kind_name" => N_("Nice Name")
|
||
def template_labels(hash)
|
||
TemplateKind.add_to_jar hash
|
||
end
|
||
|
||
private
|
||
|
||
def extend_template_helpers_by_module(mod)
|
app/views/hosts/_templates.html.erb | ||
---|---|---|
<table class="<%= table_css_classes %>">
|
||
<thead>
|
||
<tr>
|
||
<th><%= _("Template Type") %></th>
|
||
<th></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<% @templates.each do |tmpl| %>
|
||
<tr>
|
||
<td><%= _(tmpl.template_kind) %></td>
|
||
<td><%= action_buttons(display_link_if_authorized(_("Edit"),
|
||
hash_for_edit_provisioning_template_path(:id => tmpl.to_param),
|
||
:rel => "external"),
|
||
link_to(_("Review"),
|
||
url_for(:controller => '/unattended',
|
||
:action => 'host_template',
|
||
:kind => tmpl.template_kind.name,
|
||
:hostname => @host.name),
|
||
:rel => 'external', :"data-provisioning-template" => true)) %>
|
||
</td>
|
||
</tr>
|
||
<% end %>
|
||
</tbody>
|
||
</table>
|
app/views/hosts/show.html.erb | ||
---|---|---|
<ul id="myTab" class="nav nav-tabs">
|
||
<li class="active"><a href="#properties" data-toggle="tab"><%= _('Properties') %></a></li>
|
||
<li><a href="#metrics" data-toggle="tab"><%= _('Metrics') %></a></li>
|
||
<% if SETTINGS[:unattended] %>
|
||
<% if SETTINGS[:unattended] && @host.managed? %>
|
||
<li><a href="#template" data-toggle="tab"><%= _('Templates') %></a></li>
|
||
<% end %>
|
||
<% if @host.compute_resource_id %>
|
||
... | ... | |
<%= render :partial => "hosts/metrics", :locals => { :report_summary => @report_summary[@host.name][:metrics] } %>
|
||
<% end %>
|
||
</div>
|
||
<div class="tab-pane" id="template" data-ajax-url='<%= templates_host_path(@host)%>'>
|
||
<%= spinner(_('Loading template information ...')) %>
|
||
</div>
|
||
<% if SETTINGS[:unattended] && @host.managed? %>
|
||
<div class="tab-pane" id="template" data-ajax-url='<%= templates_host_path(@host)%>'>
|
||
<%= spinner(_('Loading template information ...')) %>
|
||
</div>
|
||
<% end %>
|
||
<% if @host.compute_resource_id %>
|
||
<div class="tab-pane" id="vm" data-ajax-url='<%= vm_host_path(@host)%>' data-on-complete='setPowerState'>
|
||
<%= spinner(_('Loading VM information ...')) %>
|
app/views/operatingsystems/_templates.html.erb | ||
---|---|---|
<%= selectable_f f,:provisioning_template_id, @operatingsystem.provisioning_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}, { :include_blank => true }, { :label => f.object.template_kind } %>
|
||
<%= selectable_f f,:provisioning_template_id, @operatingsystem.provisioning_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}, { :include_blank => true }, { :label => _(f.object.template_kind.to_s) } %>
|
||
<%= f.hidden_field :template_kind_id %>
|
app/views/provisioning_templates/_custom_tabs.html.erb | ||
---|---|---|
<%= checkbox_f f, :snippet, :onchange => "snippet_changed(this)", :label=>_('Snippet'), :disabled => @template.locked? %>
|
||
|
||
<div id="kind_selector" <%= display? @template.snippet %>>
|
||
<%= select_f f, :template_kind_id, TemplateKind.all, :id, :name, {:include_blank => true, :selected => @template_kind_id},
|
||
<%= select_f f, :template_kind_id, TemplateKind.all, :id, :to_s, {:include_blank => true, :selected => @template_kind_id},
|
||
{:disabled => @template.locked?, :label => _("Type")} %>
|
||
</div>
|
||
</div>
|
Also available in: Unified diff
Fixes #14395 - Label for provision template capitalized in os details page
s