foreman/app/helpers/hosts_helper.rb @ d7c67746
2f077f63 | Ohad Levy | module HostsHelper
|
|
cdf02336 | Ohad Levy | include OperatingsystemsHelper
|
|
36f93e4d | Ohad Levy | include HostsAndHostgroupsHelper
|
|
8ffd9aee | Ohad Levy | include ComputeResourcesVmsHelper
|
|
79c0664a | Timo Goebel | include HostsNicHelper
|
|
40df7dfb | Daniel Lobato | include BmcHelper
|
|
cdf02336 | Ohad Levy | ||
6d05514a | Tomas Strachota | def provider_partial_exist?(compute_resource, partial)
|
|
return false unless compute_resource
|
|||
43c4bd72 | Marek Hulan | ||
c2f60b57 | Tomas Strachota | compute_resource_name = compute_resource.provider.downcase
|
|
ActionController::Base.view_paths.any? do |path|
|
|||
File.exist?(File.join(path, 'compute_resources_vms', 'form', compute_resource_name, "_#{partial}.html.erb"))
|
|||
end
|
|||
43c4bd72 | Marek Hulan | end
|
|
6d05514a | Tomas Strachota | def provider_partial(compute_resource, partial)
|
|
return nil unless compute_resource
|
|||
43c4bd72 | Marek Hulan | ||
c2f60b57 | Tomas Strachota | compute_resource_name = compute_resource.provider.downcase
|
|
6d05514a | Tomas Strachota | "compute_resources_vms/form/#{compute_resource_name}/#{partial}"
|
|
end
|
|||
51685ba8 | Timo Goebel | def provision_method_partial_exist?(provision_method, partial)
|
|
return false unless provision_method
|
|||
ActionController::Base.view_paths.any? do |path|
|
|||
File.exist?(File.join(path, 'hosts', 'provision_method', provision_method, "_#{partial}.html.erb"))
|
|||
end
|
|||
end
|
|||
def provision_method_partial(provision_method, partial)
|
|||
return nil unless provision_method
|
|||
"hosts/provision_method/#{provision_method}/#{partial}"
|
|||
end
|
|||
5e813fae | elad | def compute_specific_js(compute_resource, js_name)
|
|
javascript_include_tag("compute_resources/#{compute_resource.provider.downcase}/#{js_name}.js")
|
|||
43c4bd72 | Marek Hulan | end
|
|
55ee550c | Tom Caspy | def value_hash_cache(host)
|
|
@value_hash_cache ||= {}
|
|||
@value_hash_cache[host.id] ||= begin
|
|||
60cf5a37 | Shimon Shtein | info = HostInfoProviders::PuppetInfo.new(host)
|
|
info.inherited_puppetclass_parameters.
|
|||
merge(info.inherited_smart_variables)
|
|||
55ee550c | Tom Caspy | end
|
|
end
|
|||
65292474 | Tomer Brisker | def host_taxonomy_select(f, taxonomy)
|
|
taxonomy_id = "#{taxonomy.to_s.downcase}_id"
|
|||
selected_taxonomy = @host.new_record? ? taxonomy.current.try(:id) : @host.send(taxonomy_id)
|
|||
fb386861 | Marek Hulan | label = _(taxonomy.to_s)
|
|
65292474 | Tomer Brisker | select_opts = { :include_blank => !@host.managed? || @host.send(taxonomy_id).nil?,
|
|
:selected => selected_taxonomy }
|
|||
html_opts = { :disabled => !@host.new_record?,
|
|||
:onchange => "#{taxonomy.to_s.downcase}_changed(this);",
|
|||
74f5ebfe | Sean O\'Keeffe | :label => label,
|
|
65292474 | Tomer Brisker | :'data-host-id' => @host.id,
|
|
:'data-url' => process_taxonomy_hosts_path,
|
|||
:help_inline => :indicator,
|
|||
:required => true }
|
|||
fb386861 | Marek Hulan | html_opts[:label_help] = _("#{taxonomy} can be changed using bulk action on the All Hosts page") unless @host.new_record?
|
|
65292474 | Tomer Brisker | ||
select_f f, taxonomy_id.to_sym, taxonomy.send("my_#{taxonomy.to_s.downcase.pluralize}"), :id, :to_label,
|
|||
select_opts, html_opts
|
|||
end
|
|||
43c4bd72 | Marek Hulan | def new_host_title
|
|
b11071cd | June Zhang | t = _("Create Host")
|
|
43c4bd72 | Marek Hulan | title(t, (t + ' <span id="hostFQDN"></span>').html_safe)
|
|
end
|
|||
def flags_for_nic(nic)
|
|||
flags = ""
|
|||
flags += "<i class=\"nic-flag glyphicon glyphicon glyphicon-tag\" title=\"#{_('Primary')}\"></i>" if nic.primary?
|
|||
flags += "<i class=\"nic-flag glyphicon glyphicon glyphicon-hdd\" title=\"#{_('Provisioning')}\"></i>" if nic.provision?
|
|||
flags.html_safe
|
|||
end
|
|||
eafaf5f1 | Ohad Levy | def last_report_column(record)
|
|
d738d2c0 | Marek Hulan | time = record.last_report? ? date_time_relative_value(record.last_report) : ""
|
|
056baf6c | Amos Benari | link_to_if_authorized(time,
|
|
e8d6d2d6 | Shlomi Zadok | hash_for_host_config_report_path(:host_id => record.to_param, :id => "last"),
|
|
056baf6c | Amos Benari | last_report_tooltip(record))
|
|
05ab4c16 | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def last_report_tooltip(record)
|
|
717899c9 | Ohad Levy | opts = { :rel => "twipsy" }
|
|
d738d2c0 | Marek Hulan | date = record.last_report.nil? ? '' : date_time_absolute_value(record.last_report) + ", "
|
|
e54016da | Marek Hulan | if @last_report_ids[record.id]
|
|
d738d2c0 | Marek Hulan | opts["data-original-title"] = date + _("view last report details")
|
|
717899c9 | Ohad Levy | else
|
|
056baf6c | Amos Benari | opts.merge!(:disabled => true, :class => "disabled", :onclick => 'return false')
|
|
d738d2c0 | Marek Hulan | opts["data-original-title"] = date + _("report already deleted") unless record.last_report.nil?
|
|
717899c9 | Ohad Levy | end
|
|
056baf6c | Amos Benari | opts
|
|
c439b058 | Ohad Levy | end
|
|
767bbf03 | Ohad Levy | ||
3aea8c81 | Amos Benari | # method that reformat the hostname column by adding the status icons
|
|
e54016da | Marek Hulan | def name_column(host)
|
|
style = host_global_status_icon_class_for_host(host)
|
|||
tooltip = host.host_statuses.select(&:relevant?).sort_by(&:type).map { |status| "#{_(status.name)}: #{_(status.to_label)}" }.join(', ')
|
|||
f4459c11 | David Davis | content = content_tag(:span, "", {:rel => "twipsy", :class => style, :"data-original-title" => tooltip})
|
|
027d2087 | Tomer Brisker | content += link_to(" #{host}", host_path(host))
|
|
e54016da | Marek Hulan | content
|
|
end
|
|||
def host_global_status_icon_class_for_host(host)
|
|||
options = {}
|
|||
options[:last_reports] = @last_reports unless @last_reports.nil?
|
|||
host_global_status_icon_class(host.build_global_status(options).status)
|
|||
end
|
|||
def host_global_status_icon_class(status)
|
|||
icon_class = case status
|
|||
c77212ef | Ohad Levy | when HostStatus::Global::OK
|
|
'pficon-ok'
|
|||
when HostStatus::Global::WARN
|
|||
'pficon-info'
|
|||
when HostStatus::Global::ERROR
|
|||
'pficon-error-circle-o'
|
|||
else
|
|||
'pficon-help'
|
|||
end
|
|||
"host-status #{icon_class} #{host_global_status_class(status)}"
|
|||
e54016da | Marek Hulan | end
|
|
def host_global_status_class(status)
|
|||
case status
|
|||
when HostStatus::Global::OK
|
|||
'status-ok'
|
|||
when HostStatus::Global::WARN
|
|||
'status-warn'
|
|||
when HostStatus::Global::ERROR
|
|||
'status-error'
|
|||
else
|
|||
'status-question'
|
|||
2ce2046f | Ohad Levy | end
|
|
766e0f38 | Ohad Levy | end
|
|
c439b058 | Ohad Levy | ||
5f029ed6 | Daniel Lobato | def days_ago(time)
|
|
8af7d0e1 | Ondrej Prazak | ((Time.zone.now - time) / 1.day).ceil.to_i
|
|
72e65b31 | Ohad Levy | end
|
|
7c0c8e06 | Ohad Levy | ||
b09b4515 | Ohad Levy | def searching?
|
|
params[:search].empty?
|
|||
end
|
|||
4dcf38a5 | Å imon LukaÅ¡Ãk | def multiple_actions
|
|
29c5556a | Tomer Brisker | actions = []
|
|
if authorized_for(:controller => :hosts, :action => :edit)
|
|||
actions.concat [
|
|||
[_('Change Group'), select_multiple_hostgroup_hosts_path],
|
|||
[_('Change Environment'), select_multiple_environment_hosts_path],
|
|||
[_('Edit Parameters'), multiple_parameters_hosts_path],
|
|||
[_('Disable Notifications'), multiple_disable_hosts_path],
|
|||
[_('Enable Notifications'), multiple_enable_hosts_path],
|
|||
[_('Disassociate Hosts'), multiple_disassociate_hosts_path],
|
|||
f4459c11 | David Davis | [_('Rebuild Config'), rebuild_config_hosts_path]
|
|
29c5556a | Tomer Brisker | ]
|
|
actions.insert(1, [_('Build Hosts'), multiple_build_hosts_path]) if SETTINGS[:unattended]
|
|||
actions << [_('Assign Organization'), select_multiple_organization_hosts_path] if SETTINGS[:organizations_enabled]
|
|||
actions << [_('Assign Location'), select_multiple_location_hosts_path] if SETTINGS[:locations_enabled]
|
|||
actions << [_('Change Owner'), select_multiple_owner_hosts_path] if SETTINGS[:login]
|
|||
actions << [_('Change Puppet Master'), select_multiple_puppet_proxy_hosts_path] if SmartProxy.unscoped.authorized.with_features("Puppet").exists?
|
|||
actions << [_('Change Puppet CA'), select_multiple_puppet_ca_proxy_hosts_path] if SmartProxy.unscoped.authorized.with_features("Puppet CA").exists?
|
|||
end
|
|||
actions << [_('Run Puppet'), multiple_puppetrun_hosts_path] if Setting[:puppetrun] && authorized_for(:controller => :hosts, :action => :puppetrun)
|
|||
actions << [_('Change Power State'), select_multiple_power_state_hosts_path] if authorized_for(:controller => :hosts, :action => :power)
|
|||
actions << [_('Delete Hosts'), multiple_destroy_hosts_path] if authorized_for(:controller => :hosts, :action => :destroy)
|
|||
4dcf38a5 | Å imon LukaÅ¡Ãk | actions
|
|
end
|
|||
1a51088d | Ohad Levy | ||
4dcf38a5 | Å imon LukaÅ¡Ãk | def multiple_actions_select
|
|
f4459c11 | David Davis | select_action_button(_("Select Action"), {:id => 'submit_multiple'},
|
|
afe02d30 | Daniel Lobato | multiple_actions.map do |action|
|
|
e7a8e82e | Stephen Benjamin | # If the action array has 3 entries, the third one is whether to use a modal dialog or not
|
|
da9865b8 | Michael Moll | modal = (action.size == 3) ? action[3] : true
|
|
e7a8e82e | Stephen Benjamin | if modal
|
|
link_to_function(action[0], "build_modal(this, '#{action[1]}')", :'data-dialog-title' => _("%s - The following hosts are about to be changed") % action[0])
|
|||
else
|
|||
link_to_function(action[0], "build_redirect('#{action[1]}')")
|
|||
end
|
|||
afe02d30 | Daniel Lobato | end.flatten
|
|
)
|
|||
1a51088d | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def date(ts = nil)
|
|
bfbf7ed8 | Lukas Zapletal | return _("%s ago") % (time_ago_in_words ts) if ts
|
|
_("N/A")
|
|||
69f9cb82 | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def template_path(opts = {})
|
|
510d53cd | Marek Hulan | if (t = @host.provisioning_template(opts))
|
|
link_to t, edit_provisioning_template_path(t)
|
|||
69f9cb82 | Ohad Levy | else
|
|
bfbf7ed8 | Lukas Zapletal | _("N/A")
|
|
69f9cb82 | Ohad Levy | end
|
|
end
|
|||
1a51088d | Ohad Levy | ||
5f029ed6 | Daniel Lobato | def selected?(host)
|
|
287082a5 | David Davis | return false if host.nil? || !host.is_a?(Host::Base) || session[:selected].nil?
|
|
52538203 | Ohad Levy | session[:selected].include?(host.id.to_s)
|
|
end
|
|||
870e7fcc | Amos Benari | def resources_chart(timerange = 1.day.ago)
|
|
3cd8c84b | Michael Moll | applied, failed, restarted, failed_restarts, skipped = [], [], [], [], []
|
|
870e7fcc | Amos Benari | @host.reports.recent(timerange).each do |r|
|
|
9d43fc71 | Michael Moll | applied << [r.reported_at.to_i * 1000, r.applied ]
|
|
failed << [r.reported_at.to_i * 1000, r.failed ]
|
|||
restarted << [r.reported_at.to_i * 1000, r.restarted ]
|
|||
failed_restarts << [r.reported_at.to_i * 1000, r.failed_restarts ]
|
|||
skipped << [r.reported_at.to_i * 1000, r.skipped ]
|
|||
870e7fcc | Amos Benari | end
|
|
9d43fc71 | Michael Moll | [{:label => _("Applied"), :data => applied, :color => '#89A54E'},
|
|
{:label => _("Failed"), :data => failed, :color => '#AA4643'},
|
|||
{:label => _("Failed restarts"), :data => failed_restarts, :color => '#EC971F'},
|
|||
{:label => _("Skipped"), :data => skipped, :color => '#80699B'},
|
|||
{:label => _("Restarted"), :data => restarted, :color => '#4572A7'}]
|
|||
3aea8c81 | Amos Benari | end
|
|
3eecf845 | Amos Benari | ||
870e7fcc | Amos Benari | def runtime_chart(timerange = 1.day.ago)
|
|
config, runtime = [], []
|
|||
@host.reports.recent(timerange).each do |r|
|
|||
9d43fc71 | Michael Moll | config << [r.reported_at.to_i * 1000, r.config_retrieval]
|
|
runtime << [r.reported_at.to_i * 1000, r.runtime]
|
|||
870e7fcc | Amos Benari | end
|
|
9d43fc71 | Michael Moll | [{:label => _("Config Retrieval"), :data => config, :color => '#AA4643'}, {:label => _("Runtime"), :data => runtime, :color => '#4572A7'}]
|
|
3eecf845 | Amos Benari | end
|
|
fb158de8 | Amos Benari | ||
def reports_show
|
|||
d96635ce | Ohad Levy | return if @host.reports.empty?
|
|
189cc0be | Tom Caspy | number_of_days = days_ago(@host.reports.order(:reported_at).first.reported_at)
|
|
width = [number_of_days.to_s.size + 2, 4].max
|
|||
ec4108a5 | ripcurld00d | form_tag @host, :id => 'days_filter', :method => :get, :class => "form form-inline" do
|
|
8dfe5543 | Shlomi Zadok | content_tag(:span, (_("Found %{count} reports from the last %{days} days") %
|
|
9d43fc71 | Michael Moll | { :days => select(nil, 'range', 1..number_of_days,
|
|
{:selected => @range}, {:style => "float:none; width: #{width}em;", :onchange => "$('#days_filter').submit();$(this).disabled();"}),
|
|||
3dfb6e4c | Dominic Cleal | :count => @host.reports.recent(@range.days.ago).count }).html_safe)
|
|
fb158de8 | Amos Benari | end
|
|
bf228dd6 | Paul Kelly | end
|
|
056baf6c | Amos Benari | ||
5f029ed6 | Daniel Lobato | def name_field(host)
|
|
8f87064c | Ohad Levy | return if host.name.blank?
|
|
287082a5 | David Davis | (SETTINGS[:unattended] && host.managed?) ? host.shortname : host.name
|
|
056baf6c | Amos Benari | end
|
|
67110766 | Lukas Zapletal | def build_duration(host)
|
|
return _("N/A") if host.initiated_at.nil? && host.installed_at.nil?
|
|||
if host.installed_at.nil?
|
|||
time_ago_in_words(host.initiated_at, include_seconds: true) + " (in progress)"
|
|||
else
|
|||
distance_of_time_in_words(host.initiated_at, host.installed_at, include_seconds: true)
|
|||
end
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def overview_fields(host)
|
|
e54016da | Marek Hulan | global_status = host.build_global_status
|
|
370a7ac7 | Ohad Levy | fields = [
|
|
d6641b26 | Tomer Brisker | [
|
|
_("Status"),
|
|||
content_tag(:span, ''.html_safe, :class => host_global_status_icon_class(global_status.status)) +
|
|||
content_tag(:span, _(global_status.to_label), :class => host_global_status_class(global_status.status))
|
|||
e54016da | Marek Hulan | ]
|
|
]
|
|||
fields += host_detailed_status_list(host)
|
|||
67110766 | Lukas Zapletal | fields += [[_("Build duration"), build_duration(host)]]
|
|
fields += [[_("Build errors"), link_to("Logs from OS installer", build_errors_host_path(:id => host.id))]] if host.build_errors.present?
|
|||
fields += [[_("Token"), host.token || _("N/A")]] if User.current.admin?
|
|||
ee360810 | Michael Moll | fields += [[_("Domain"), link_to(host.domain, hosts_path(:search => %{domain = "#{host.domain}"}))]] if host.domain.present?
|
|
fields += [[_("Realm"), link_to(host.realm, hosts_path(:search => %{realm = "#{host.realm}"}))]] if host.realm.present?
|
|||
44505095 | Sean O'Keeffe | fields += [[_("IP Address"), host.ip]] if host.ip.present?
|
|
b215c092 | Timo Goebel | fields += [[_("IPv6 Address"), host.ip6]] if host.ip6.present?
|
|
68b36ebc | Ron | fields += [[_("Comment"), host.comment]] if host.comment.present?
|
|
44505095 | Sean O'Keeffe | fields += [[_("MAC Address"), host.mac]] if host.mac.present?
|
|
ee360810 | Michael Moll | fields += [[_("Puppet Environment"), link_to(host.environment, hosts_path(:search => %{environment = "#{host.environment}"}))]] if host.environment.present?
|
|
fields += [[_("Architecture"), link_to(host.arch, hosts_path(:search => %{architecture = "#{host.arch}"}))]] if host.arch.present?
|
|||
fields += [[_("Operating System"), link_to(host.operatingsystem.to_label, hosts_path(:search => %{os_title = "#{host.operatingsystem.title}"}))]] if host.operatingsystem.present?
|
|||
4cbf879e | Lukas Zapletal | fields += [[_("PXE Loader"), host.pxe_loader]] if host.operatingsystem.present? && host.pxe_build?
|
|
ee360810 | Michael Moll | fields += [[_("Host group"), link_to(host.hostgroup, hosts_path(:search => %{hostgroup_title = "#{host.hostgroup}"}))]] if host.hostgroup.present?
|
|
3ce09016 | Mac Reid | fields += [[_("Location"), (link_to(host.location.title, hosts_path(:search => %{location = "#{host.location}"})) if host.location)]] if SETTINGS[:locations_enabled]
|
|
fields += [[_("Organization"), (link_to(host.organization.title, hosts_path(:search => %{organization = "#{host.organization}"})) if host.organization)]] if SETTINGS[:organizations_enabled]
|
|||
fea8c959 | Joseph Mitchell Magen | if SETTINGS[:login]
|
|
bfbf7ed8 | Lukas Zapletal | if host.owner_type == _("User")
|
|
3ce09016 | Mac Reid | fields += [[_("Owner"), (link_to(host.owner, hosts_path(:search => %{user.login = "#{host.owner.login}"})) if host.owner)]]
|
|
fea8c959 | Joseph Mitchell Magen | else
|
|
bfbf7ed8 | Lukas Zapletal | fields += [[_("Owner"), host.owner]]
|
|
fea8c959 | Joseph Mitchell Magen | end
|
|
end
|
|||
bfbf7ed8 | Lukas Zapletal | fields += [[_("Certificate Name"), host.certname]] if Setting[:use_uuid_for_certificates]
|
|
370a7ac7 | Ohad Levy | fields
|
|
end
|
|||
dd42df0a | Ohad Levy | ||
e54016da | Marek Hulan | def host_detailed_status_list(host)
|
|
host.host_statuses.sort_by(&:type).map do |status|
|
|||
next unless status.relevant?
|
|||
[
|
|||
_(status.name),
|
|||
aa50ab15 | alongoldboim | content_tag(:span, ' '.html_safe, :class => host_global_status_icon_class(status.to_global)) +
|
|
e54016da | Marek Hulan | content_tag(:span, _(status.to_label), :class => host_global_status_class(status.to_global))
|
|
]
|
|||
1f76a8ba | Marek Hulan | end.compact
|
|
e54016da | Marek Hulan | end
|
|
5f029ed6 | Daniel Lobato | def possible_images(cr, arch = nil, os = nil)
|
|
4bd19fb1 | Marek Hulan | return cr.images.order(:name) unless controller_name == "hosts"
|
|
dd42df0a | Ohad Levy | return [] unless arch && os
|
|
4bd19fb1 | Marek Hulan | cr.images.where(:architecture_id => arch, :operatingsystem_id => os).order(:name)
|
|
dd42df0a | Ohad Levy | end
|
|
2be85b23 | Amos Benari | ||
5f029ed6 | Daniel Lobato | def state(s)
|
|
bfbf7ed8 | Lukas Zapletal | s ? ' ' + _("Off") : ' ' + _("On")
|
|
3f482b82 | Ohad Levy | end
|
|
2be85b23 | Amos Benari | ||
88ed4900 | Amos Benari | def host_title_actions(host)
|
|
2be85b23 | Amos Benari | title_actions(
|
|
766421e6 | Tomer Brisker | button_group(
|
|
link_to(_("Back"), hosts_path, :class => 'btn btn-default')
|
|||
),
|
|||
button_group(
|
|||
link_to_if_authorized(_("Edit"), hash_for_edit_host_path(:id => host).merge(:auth_object => host),
|
|||
:title => _("Edit this host"), :id => "edit-button", :class => 'btn btn-default'),
|
|||
display_link_if_authorized(_("Clone"), hash_for_clone_host_path(:id => host).merge(:auth_object => host),
|
|||
:title => _("Clone this host"), :id => "clone-button", :class => 'btn btn-default'),
|
|||
if host.build
|
|||
link_to_if_authorized(_("Cancel build"), hash_for_cancelBuild_host_path(:id => host).merge(:auth_object => host, :permission => 'build_hosts'),
|
|||
:disabled => host.can_be_built?,
|
|||
:title => _("Cancel build request for this host"), :id => "cancel-build-button", :class => 'btn btn-default')
|
|||
else
|
|||
link_to_if_authorized(_("Build"), hash_for_host_path(:id => host).merge(:auth_object => host, :permission => 'build_hosts', :anchor => "review_before_build"),
|
|||
:disabled => !host.can_be_built?,
|
|||
:title => _("Enable rebuild on next host boot"),
|
|||
:class => "btn btn-default",
|
|||
:id => "build-review",
|
|||
:data => { :toggle => 'modal',
|
|||
:target => '#review_before_build',
|
|||
:url => review_before_build_host_path(:id => host)
|
|||
}
|
|||
2be85b23 | Amos Benari | )
|
|
766421e6 | Tomer Brisker | end
|
|
),
|
|||
if host.supports_power?
|
|||
2be85b23 | Amos Benari | button_group(
|
|
b7d400f6 | Michael Moll | link_to(_("Loading power state ..."), '#', :disabled => true, :class => 'btn btn-default', :id => :loading_power_state)
|
|
2be85b23 | Amos Benari | )
|
|
766421e6 | Tomer Brisker | end,
|
|
button_group(
|
|||
if host.try(:puppet_proxy)
|
|||
link_to_if_authorized(_("Run puppet"), hash_for_puppetrun_host_path(:id => host).merge(:auth_object => host, :permission => 'puppetrun_hosts'),
|
|||
:disabled => !Setting[:puppetrun],
|
|||
:class => 'btn btn-default',
|
|||
9d43fc71 | Michael Moll | :title => _("Trigger a puppetrun on a node; requires that puppet run is enabled"))
|
|
766421e6 | Tomer Brisker | end
|
|
),
|
|||
button_group(
|
|||
link_to_if_authorized(_("Delete"), hash_for_host_path(:id => host).merge(:auth_object => host, :permission => 'destroy_hosts'),
|
|||
:class => "btn btn-danger",
|
|||
:id => "delete-button",
|
|||
:data => { :message => delete_host_dialog(host) },
|
|||
:method => :delete)
|
|||
)
|
|||
2be85b23 | Amos Benari | )
|
|
end
|
|||
8838eb42 | Ohad Levy | ||
0b605bf6 | Ondrej Prazak | def delete_host_dialog(host)
|
|
if host.compute?
|
|||
_("Are you sure you want to delete host %s? This will delete the virtual machine and its disks, and is irreversible.") % host.name
|
|||
else
|
|||
_("Are you sure you want to delete host %s? This action is irreversible.") % host.name
|
|||
end
|
|||
end
|
|||
43c4bd72 | Marek Hulan | # we ignore interfaces.conflict because they are always registered in host errors as well
|
|
5f029ed6 | Daniel Lobato | def conflict_objects(errors)
|
|
43c4bd72 | Marek Hulan | errors.keys.map(&:to_s).select { |key| key =~ /conflict$/ && key != 'interfaces.conflict' }.map(&:to_sym)
|
|
8838eb42 | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def has_conflicts?(errors)
|
|
8838eb42 | Ohad Levy | conflict_objects(errors).each do |c|
|
|
return true if errors[c.to_sym].any?
|
|||
end
|
|||
false
|
|||
end
|
|||
66afbc33 | Joseph Mitchell Magen | ||
5f029ed6 | Daniel Lobato | def has_dhcp_lease_errors?(errors)
|
|
90ff2a3a | Dmitri Dolguikh | errors.include?(:dhcp_lease_error)
|
|
end
|
|||
66afbc33 | Joseph Mitchell Magen | def args_for_compute_resource_partial(host)
|
|
a27196f0 | Neil Miao | args = {}
|
|
args[:arch] = host.try(:architecture_id) || (params[:host] && params[:host][:architecture_id])
|
|||
args[:os] = host.try(:operatingsystem_id) || (params[:host] && params[:host][:operatingsystem_id])
|
|||
args[:selected_cluster] = vm_attrs['cluster'] if defined?(vm_attrs)
|
|||
args
|
|||
66afbc33 | Joseph Mitchell Magen | end
|
|
e902d939 | Greg Sutcliffe | ||
def show_appropriate_host_buttons(host)
|
|||
d6641b26 | Tomer Brisker | [
|
|
link_to_if_authorized(_("Audits"), hash_for_host_audits_path(:host_id => @host), :title => _("Host audit entries"), :class => 'btn btn-default'),
|
|||
4f7a4d0b | David Davis | (link_to_if_authorized(_("Facts"), hash_for_host_facts_path(:host_id => host), :title => _("Browse host facts"), :class => 'btn btn-default') if host.fact_values.any?),
|
|
e8d6d2d6 | Shlomi Zadok | (link_to_if_authorized(_("Reports"), hash_for_host_config_reports_path(:host_id => host), :title => _("Browse host config management reports"), :class => 'btn btn-default') if host.reports.any?),
|
|
4f7a4d0b | David Davis | (link_to(_("YAML"), externalNodes_host_path(:name => host), :title => _("Puppet external nodes YAML dump"), :class => 'btn btn-default') if SmartProxy.with_features("Puppet").any?)
|
|
e902d939 | Greg Sutcliffe | ].compact
|
|
end
|
|||
41fb208d | Lukas Zapletal | ||
5f029ed6 | Daniel Lobato | def allocation_text_f(f)
|
|
41fb208d | Lukas Zapletal | active = 'Size'
|
|
active = 'None' if f.object.allocation.to_i == 0
|
|||
active = 'Full' if f.object.allocation == f.object.capacity
|
|||
aa50ab15 | alongoldboim | text_f f, :allocation, :class => "input-mini", :label => _("Allocation (GB)"), :label_size => "col-md-2",
|
|
41fb208d | Lukas Zapletal | :readonly => (active == 'Size') ? false : true,
|
|
:help_inline => (content_tag(:span, :class => 'btn-group', :'data-toggle' => 'buttons-radio') do
|
|||
[N_('None'), N_('Size'), N_('Full')].collect do |label|
|
|||
content_tag :button, _(label), :type => 'button', :href => '#',
|
|||
:name => 'allocation_radio_btn',
|
|||
1fa42669 | Amos Benari | :class => (label == active) ? 'btn btn-default active' : 'btn btn-default',
|
|
9234d6c5 | Ohad Levy | :onclick => "tfm.computeResource.libvirt.allocationSwitcher(this, '#{label}');",
|
|
4ad35960 | lizagilman | :data => { :toggle => 'button' },
|
|
:id => (label == 'Full') ? 'btnAllocationFull' : nil
|
|||
41fb208d | Lukas Zapletal | end.join(' ').html_safe
|
|
end)
|
|||
end
|
|||
160ffa2a | Ohad Levy | ||
ffedb85d | Tomer Brisker | # helper method to provide data attribute if subnets has ipam enabled / disabled
|
|
79c0664a | Timo Goebel | def subnets_ipam_data(field)
|
|
160ffa2a | Ohad Levy | data = {}
|
|
79c0664a | Timo Goebel | domain_subnets(field).each do |subnet|
|
|
160ffa2a | Ohad Levy | data[subnet.id] = { :ipam => subnet.ipam? }
|
|
end
|
|||
data
|
|||
end
|
|||
d455f32c | Marek Hulan | ||
def remove_interface_link(f)
|
|||
remove_child_link('x', f, {:rel => 'twipsy',
|
|||
:'data-title' => _('remove network interface'),
|
|||
:'data-placement' => 'left',
|
|||
:class => 'fr label label-danger'})
|
|||
end
|
|||
3154d77e | Tomas Strachota | def link_status(nic)
|
|
return '' if nic.new_record?
|
|||
if nic.link
|
|||
9d43fc71 | Michael Moll | status = '<i class="glyphicon glyphicon glyphicon-arrow-up interface-up" title="' + _('Interface is up') + '"></i>'
|
|
3154d77e | Tomas Strachota | else
|
|
9d43fc71 | Michael Moll | status = '<i class="glyphicon glyphicon glyphicon-arrow-down interface-down" title="' + _('Interface is down') + '"></i>'
|
|
3154d77e | Tomas Strachota | end
|
|
status.html_safe
|
|||
d455f32c | Marek Hulan | end
|
|
6e916e52 | Shlomi Zadok | ||
43c4bd72 | Marek Hulan | def interface_flags(nic)
|
|
primary_class = nic.primary? ? "active" : ""
|
|||
provision_class = nic.provision? ? "active" : ""
|
|||
status = "<i class=\"glyphicon glyphicon glyphicon-tag primary-flag #{primary_class}\" title=\"#{_('Primary')}\"></i>"
|
|||
status += "<i class=\"glyphicon glyphicon glyphicon-hdd provision-flag #{provision_class}\" title=\"#{_('Provisioning')}\"></i>"
|
|||
status.html_safe
|
|||
end
|
|||
6e916e52 | Shlomi Zadok | def build_state(build)
|
|
build.state ? 'warning' : 'danger'
|
|||
end
|
|||
def review_build_button(form, status)
|
|||
form.submit(_("Build"),
|
|||
:class => "btn btn-#{status} submit",
|
|||
:title => (status == 'warning') ? _('Build') : _('Errors occurred, build may fail')
|
|||
)
|
|||
end
|
|||
def build_error_link(type, id)
|
|||
case type
|
|||
when :templates
|
|||
510d53cd | Marek Hulan | link_to_if_authorized(_("Edit"), hash_for_edit_provisioning_template_path(:id => id).merge(:auth_object => id),
|
|
f4459c11 | David Davis | :class => "btn btn-default btn-xs pull-right", :title => _("Edit %s" % type))
|
|
6e916e52 | Shlomi Zadok | end
|
|
end
|
|||
5081efd9 | Shimon Shtein | ||
def inherited_by_default?(field, host)
|
|||
return false unless host.hostgroup && host.hostgroup_id_was.nil?
|
|||
return false if params[:action] == 'clone'
|
|||
return true unless params[:host]
|
|||
!params[:host][field]
|
|||
end
|
|||
fbb47ea5 | Timo Goebel | ||
def multiple_proxy_select(form, proxy_feature)
|
|||
selectable_f form,
|
|||
:proxy_id,
|
|||
[[_("Select desired %s proxy") % _(proxy_feature), "disabled"]] +
|
|||
[[_("*Clear %s proxy*") % _(proxy_feature), "" ]] +
|
|||
SmartProxy.with_features(proxy_feature).map {|p| [p.name, p.id]},
|
|||
{},
|
|||
49fad244 | amirfefer | {:label => _(proxy_feature), :onchange => "toggle_multiple_ok_button(this)" }
|
|
fbb47ea5 | Timo Goebel | end
|
|
03510341 | Lukas Zapletal | ||
def randomize_mac_link
|
|||
d7c67746 | Michael Moll | if NameGenerator.random_based?
|
|
link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default',
|
|||
:title => _('Generate new random name. Visit Settings to disable this feature.'))
|
|||
end
|
|||
03510341 | Lukas Zapletal | end
|
|
901fe896 | Ondrej Prazak | ||
def power_status_visible?
|
|||
SETTINGS[:unattended] && Setting[:host_power_status]
|
|||
end
|
|||
833e2aef | Amir Fefer | ||
def host_breadcrumb
|
|||
breadcrumbs(resource_url: "/api/v2/hosts?thin=true'")
|
|||
end
|
|||
2f077f63 | Ohad Levy | end
|