Class: DiscoveredHostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- DiscoveredHostsController
- Includes:
- ActionView::Helpers::NumberHelper, Foreman::Controller::AutoCompleteSearch, Foreman::Controller::DiscoveredExtensions, Foreman::Controller::Parameters::DiscoveredHost, Foreman::Controller::TaxonomyMultiple
- Defined in:
- app/controllers/discovered_hosts_controller.rb
Instance Method Summary collapse
- #auto_provision ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #model_of_controller ⇒ Object
- #multiple_auto_provision ⇒ Object
- #multiple_destroy ⇒ Object
- #multiple_reboot ⇒ Object
- #perform_update(host, success_message = nil) ⇒ Object
- #reboot ⇒ Object
- #refresh_facts ⇒ Object
- #resource_class ⇒ Object
- #show ⇒ Object
- #submit_multiple_auto_provision ⇒ Object
- #submit_multiple_destroy ⇒ Object
- #submit_multiple_reboot ⇒ Object
- #update ⇒ Object
Instance Method Details
#auto_provision ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/discovered_hosts_controller.rb', line 161 def auto_provision if rule = find_discovery_rule(@host) if perform_auto_provision(@host, rule) process_success :success_msg => _("Host %{host} was provisioned with rule %{rule}") % {:host => @host.name, :rule => rule.name}, :success_redirect => discovered_hosts_path else errors = @host.errors..join(' ') logger.warn "Failed to auto provision host %s: %s" % [@host.name, errors] process_error :error_msg => _("Failed to auto provision host %s: %s") % [@host.name, errors], :redirect => :back end else process_success :success_msg => _("No rule found for host %s") % @host.name, :success_redirect => :back end end |
#destroy ⇒ Object
54 55 56 57 |
# File 'app/controllers/discovered_hosts_controller.rb', line 54 def destroy @host.destroy redirect_to :action => 'index' end |
#edit ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/discovered_hosts_controller.rb', line 59 def edit quick = params.delete(:quick_submit) @host = ::ForemanDiscovery::HostConverter.to_managed(@host, true, false, discovered_host_params_host) unless @host.nil? setup_host_class_variables @override_taxonomy = true # need to permit this one but don't know how if quick perform_update(@host, _('Successfully provisioned %s') % @host.name) else @host.build = true render :template => 'discovered_hosts/edit' end end |
#index ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/discovered_hosts_controller.rb', line 30 def index @hosts = resource_base_search_and_page.includes([ :location, :organization, :model, :discovery_attribute_set ], {:interfaces => :subnet}) fact_array = @hosts.collect do |host| [host.id, Hash[host.fact_values.joins(:fact_name).where('fact_names.name' => Setting['discovery_fact_column']).pluck(:name, :value)]] end @host_facts = Hash[fact_array] end |
#model_of_controller ⇒ Object
26 27 28 |
# File 'app/controllers/discovered_hosts_controller.rb', line 26 def model_of_controller Host::Discovered end |
#multiple_auto_provision ⇒ Object
147 148 |
# File 'app/controllers/discovered_hosts_controller.rb', line 147 def multiple_auto_provision end |
#multiple_destroy ⇒ Object
141 142 |
# File 'app/controllers/discovered_hosts_controller.rb', line 141 def multiple_destroy end |
#multiple_reboot ⇒ Object
144 145 |
# File 'app/controllers/discovered_hosts_controller.rb', line 144 def multiple_reboot end |
#perform_update(host, success_message = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/discovered_hosts_controller.rb', line 81 def perform_update(host, = nil) Taxonomy.no_taxonomy_scope do ::ForemanDiscovery::HostConverter.set_build_clean_facts(host) ::ForemanDiscovery::HostConverter.unused_ip_for_host(host) if host.save host_path = Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host) = { :success_redirect => host_path, :redirect_xhr => request.xhr? } [:success_msg] = if process_success else taxonomy_scope load_vars_for_ajax offer_to_overwrite_conflicts process_error :object => host, :render => 'discovered_hosts/edit' end end end |
#reboot ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/controllers/discovered_hosts_controller.rb', line 111 def reboot unless @host.is_a?(::Host::Discovered) process_error :error_msg => _("Host of type %s can not be rebooted") % @host.type, :redirect => :back end if @host.reboot process_success :success_msg => _("Rebooting host %s") % @host.name, :success_redirect => :back else process_error :error_msg => _("Failed to reboot host %s") % @host.name, :redirect => :back end rescue => e exception = Foreman::WrappedException.new(e, N_("Failed to reboot host %{hostname} with error %{error_message}"), :hostname => @host.name, :error_message => e.) Foreman::Logging.exception exception., e process_error :error_msg => exception., :redirect => :back end |
#refresh_facts ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/discovered_hosts_controller.rb', line 99 def refresh_facts if @host.is_a?(::Host::Discovered) && @host.refresh_facts process_success :success_msg => _("Facts refreshed for %s") % @host.name, :success_redirect => :back else process_error :error_msg => _("Failed to refresh facts for %s") % @host.name, :redirect => :back end rescue => e exception = Foreman::WrappedException.new(e, N_("Failed to refresh facts for %{hostname} with error %{error_message}"), :hostname => @host.name, :error_message => e.) Foreman::Logging.exception exception., e process_error :error_msg => exception., :redirect => :back end |
#resource_class ⇒ Object
202 203 204 |
# File 'app/controllers/discovered_hosts_controller.rb', line 202 def resource_class Host::Discovered end |
#show ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/discovered_hosts_controller.rb', line 43 def show # filter graph time range @range = nil # summary report text @report_summary = nil resolver = ForemanDiscovery::FactToCategoryResolver.new(@host) @categories_names = ForemanDiscovery::FactToCategoryResolver::CATEGORIES_NAMES @categories = resolver.categories @interfaces = resolver.interfaces end |
#submit_multiple_auto_provision ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/controllers/discovered_hosts_controller.rb', line 175 def submit_multiple_auto_provision result = true = _("Errors during auto provisioning: %s") if Host::Discovered.count == 0 = _("No discovered hosts to provision") result = false end overall_errors = "" @hosts.each do |discovered_host| if rule = find_discovery_rule(discovered_host) result &= perform_auto_provision(discovered_host, rule) unless discovered_host.errors.empty? errors = discovered_host.errors..join(' ') logger.warn "Failed to auto provision host %s: %s" % [discovered_host.name, errors] overall_errors << "#{discovered_host.name}: #{errors} " end end end if result process_success :success_msg => _("Discovered hosts are provisioning now"), :success_redirect => :back else process_error :error_msg => % overall_errors, :redirect => :back end end |
#submit_multiple_destroy ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'app/controllers/discovered_hosts_controller.rb', line 150 def submit_multiple_destroy # keep all the ones that were not deleted for notification. missed_hosts = @hosts.select {|host| !host.destroy } if missed_hosts success _("Destroyed selected hosts") else error _("The following hosts were not deleted: %s") % missed_hosts end redirect_to(discovered_hosts_path) end |
#submit_multiple_reboot ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/discovered_hosts_controller.rb', line 127 def submit_multiple_reboot = perform_reboot_all(@hosts) if process_error :error_msg => , :redirect => :back else process_success :success_msg => _("Discovered hosts are rebooting now"), :success_redirect => :back end rescue => e exception = Foreman::WrappedException.new(e, N_("Failed to reboot hosts with error %s"), e.) Foreman::Logging.exception exception., e process_error :error_msg => exception., :redirect => :back end |
#update ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/controllers/discovered_hosts_controller.rb', line 73 def update @host = ::ForemanDiscovery::HostConverter.to_managed(@host, true, true, managed_host_params_host) @override_taxonomy = true perform_update(@host) end |