foreman/app/helpers/provisioning_templates_helper.rb @ 9d43fc71
510d53cd | Marek Hulan | module ProvisioningTemplatesHelper
|
|
5f029ed6 | Daniel Lobato | def combination(template)
|
|
cab0d8c6 | Ohad Levy | template.template_combinations.map do |comb|
|
|
str = []
|
|||
bfbf7ed8 | Lukas Zapletal | str << (comb.hostgroup_id.nil? ? _("None") : comb.hostgroup.to_s)
|
|
str << (comb.environment_id.nil? ? _("None") : comb.environment.to_s)
|
|||
cab0d8c6 | Ohad Levy | str.join(" / ")
|
|
end.to_sentence
|
|||
end
|
|||
5e2b847d | Amos Benari | ||
510d53cd | Marek Hulan | def template_kind(template)
|
|
template.template_kind
|
|||
end
|
|||
def permitted_actions(template)
|
|||
404ead2a | Marek Hulan | actions = [
|
|
display_link_if_authorized(_('Clone'), template_hash_for_member(template, 'clone_template')),
|
|||
display_link_if_authorized(_('Export'), template_hash_for_member(template, 'export'), { :data => { :no_turbolink => true } })
|
|||
]
|
|||
4a28771d | Stephen Benjamin | ||
510d53cd | Marek Hulan | if template.locked?
|
|
3279c309 | Stephen Benjamin | confirm = [
|
|
_("You are about to unlock a locked template."),
|
|||
if locations_only?
|
|||
_("This is for every location that uses it.")
|
|||
elsif organizations_only?
|
|||
_("This is for every organization that uses it.")
|
|||
elsif locations_and_organizations?
|
|||
_("This is for every location and organization that uses it.")
|
|||
end,
|
|||
510d53cd | Marek Hulan | if template.vendor
|
|
9a6e73e8 | Dominic Cleal | _("It is not recommended to unlock this template, as it is provided by %{vendor} and may be overwritten. Please consider cloning it instead.") %
|
|
510d53cd | Marek Hulan | {:vendor => template.vendor}
|
|
3279c309 | Stephen Benjamin | end,
|
|
_("Continue?")
|
|||
].compact
|
|||
4a28771d | Stephen Benjamin | ||
510d53cd | Marek Hulan | actions << display_link_if_authorized(_('Unlock'), template_hash_for_member(template, 'unlock'),
|
|
3279c309 | Stephen Benjamin | {:confirm => confirm.join(" "), :style => 'color: red'})
|
|
4a28771d | Stephen Benjamin | ||
else
|
|||
510d53cd | Marek Hulan | actions << display_link_if_authorized(_('Lock'), template_hash_for_member(template, 'lock'))
|
|
actions << display_delete_if_authorized(template_hash_for_member(template).
|
|||
merge(:auth_object => template, :authorizer => authorizer, :permission => "destroy_#{@type_name_plural}"),
|
|||
:confirm => _("Delete %s?") % template)
|
|||
4a28771d | Stephen Benjamin | end
|
|
end
|
|||
3279c309 | Stephen Benjamin | ||
a377f776 | Ondrej Prazak | def pxe_with_building_hosts?(template)
|
|
kinds = ["PXELinux", "PXEGrub"]
|
|||
template.respond_to?(:template_kind) &&
|
|||
fb94aaef | Marek Hulan | template.respond_to?(:operatingsystem_ids) &&
|
|
a377f776 | Ondrej Prazak | template.template_kind.present? &&
|
|
kinds.include?(template.template_kind.name) &&
|
|||
2fba6ad7 | Ondrej Prazak | building_hosts(template).any?
|
|
end
|
|||
def building_hosts(template)
|
|||
Host.where(:build => true, :operatingsystem_id => template.operatingsystem_ids)
|
|||
end
|
|||
def building_hosts_path(template)
|
|||
oses = template.operatingsystem_ids.map { |id| "os_id = #{id}" }.join(" or ")
|
|||
hosts_path(:search => "build = true and ( #{oses} )")
|
|||
a377f776 | Ondrej Prazak | end
|
|
90aa4b03 | Daniel Lobato | def how_templates_are_determined
|
|
alert(:class => 'alert-info', :header => 'How templates are determined',
|
|||
5a573456 | Tomer Brisker | :text => ('<p>' + _("When editing a template, you must assign a list \
|
|
2586cfd9 | Ohad Levy | of operating systems which this template can be used with. Optionally, you can \
|
|
90aa4b03 | Daniel Lobato | restrict a template to a list of host groups and/or environments.") + '</p>' +
|
|
9d43fc71 | Michael Moll | '<p>' + _("When a Host requests a template (e.g. during provisioning), Foreman \
|
|
2586cfd9 | Ohad Levy | will select the best match from the available templates of that type, in the \
|
|
90aa4b03 | Daniel Lobato | following order:") + '</p>' + '<ul>' +
|
|
'<li>' + _("Host group and Environment") + '</li>' +
|
|||
'<li>' + _("Host group only") + '</li>' +
|
|||
'<li>' + _("Environment only") + '</li>' +
|
|||
'<li>' + _("Operating system default") + '</li>' +
|
|||
'</ul>' +
|
|||
(_("The final entry, Operating System default, can be set by editing the %s page.") %
|
|||
5a573456 | Tomer Brisker | (link_to _("Operating System"), operatingsystems_path))).html_safe)
|
|
90aa4b03 | Daniel Lobato | end
|
|
3279c309 | Stephen Benjamin | private
|
|
def locations_only?
|
|||
SETTINGS[:locations_enabled] && !SETTINGS[:organizations_enabled]
|
|||
end
|
|||
def organizations_only?
|
|||
SETTINGS[:organizations_enabled] && !SETTINGS[:locations_enabled]
|
|||
end
|
|||
def locations_and_organizations?
|
|||
SETTINGS[:locations_enabled] && SETTINGS[:organizations_enabled]
|
|||
end
|
|||
cab0d8c6 | Ohad Levy | end
|