foreman_discovery 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/discovered_hosts_controller.rb +41 -51
- data/app/controllers/concerns/foreman/controller/discovered_extensions.rb +20 -23
- data/app/controllers/discovered_hosts_controller.rb +50 -46
- data/app/helpers/concerns/foreman_discovery/settings_helper_extensions.rb +34 -0
- data/app/helpers/discovery_rules_helper.rb +5 -6
- data/app/mailers/discovered_mailer.rb +19 -0
- data/app/models/discovery_rule.rb +3 -3
- data/app/models/host/discovered.rb +33 -11
- data/app/models/host/managed_extensions.rb +10 -0
- data/app/models/hostgroup_extensions.rb +1 -1
- data/app/models/setting/discovered.rb +17 -11
- data/app/services/foreman_discovery/fact_parser.rb +16 -0
- data/app/services/foreman_discovery/host_converter.rb +0 -4
- data/app/services/foreman_discovery/node_api/power.rb +3 -3
- data/app/views/discovered_hosts/_discovered_host.html.erb +4 -2
- data/app/views/discovered_hosts/_discovered_hosts_list.html.erb +1 -1
- data/app/views/discovered_mailer/_discovered_host.html.erb +10 -0
- data/app/views/discovered_mailer/discovered_summary.html.erb +35 -0
- data/app/views/discovered_mailer/discovered_summary.text.erb +24 -0
- data/config/routes.rb +3 -3
- data/db/seeds.d/70_discovery_mail_notification.rb +9 -0
- data/lib/foreman_discovery/engine.rb +12 -9
- data/lib/foreman_discovery/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ca/foreman_discovery.edit.po +780 -0
- data/locale/ca/foreman_discovery.po +358 -261
- data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/de/foreman_discovery.edit.po +774 -0
- data/locale/de/foreman_discovery.po +418 -311
- data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/en_GB/foreman_discovery.edit.po +779 -0
- data/locale/en_GB/foreman_discovery.po +423 -313
- data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/es/foreman_discovery.edit.po +781 -0
- data/locale/es/foreman_discovery.po +425 -313
- data/locale/foreman_discovery.pot +496 -159
- data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/fr/foreman_discovery.edit.po +778 -0
- data/locale/fr/foreman_discovery.po +458 -322
- data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/gl/foreman_discovery.edit.po +757 -0
- data/locale/gl/foreman_discovery.po +306 -215
- data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/it/foreman_discovery.edit.po +771 -0
- data/locale/it/foreman_discovery.po +411 -301
- data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ja/foreman_discovery.edit.po +770 -0
- data/locale/ja/foreman_discovery.po +395 -300
- data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ko/foreman_discovery.edit.po +768 -0
- data/locale/ko/foreman_discovery.po +393 -299
- data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/pt_BR/foreman_discovery.edit.po +780 -0
- data/locale/pt_BR/foreman_discovery.po +438 -309
- data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ru/foreman_discovery.edit.po +775 -0
- data/locale/ru/foreman_discovery.po +413 -308
- data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/sv_SE/foreman_discovery.edit.po +766 -0
- data/locale/sv_SE/foreman_discovery.po +321 -232
- data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/zh_CN/foreman_discovery.edit.po +769 -0
- data/locale/zh_CN/foreman_discovery.po +393 -302
- data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/zh_TW/foreman_discovery.edit.po +769 -0
- data/locale/zh_TW/foreman_discovery.po +395 -302
- data/test/functional/api/v2/discovered_hosts_controller_test.rb +8 -0
- data/test/functional/api/v2/discovery_rules_controller_test.rb +9 -0
- data/test/functional/discovered_hosts_controller_test.rb +26 -17
- data/test/functional/discovery_rules_controller_test.rb +9 -8
- data/test/test_helper.rb +0 -4
- data/test/test_helper_discovery.rb +24 -0
- data/test/unit/discovered_extensions_test.rb +31 -0
- data/test/unit/discovered_mailer_test.rb +44 -0
- data/test/unit/discovery_attribute_set_test.rb +12 -0
- data/test/unit/discovery_rule_test.rb +20 -0
- data/test/unit/{puppet_fact_parser_extensions_test.rb → fact_parser_test.rb} +3 -16
- data/test/unit/host_discovered_test.rb +56 -11
- metadata +29 -5
- data/app/lib/puppet_fact_parser_extensions.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502993f89f5431e289e5efb8461e7cc0ebaacd8e
|
4
|
+
data.tar.gz: de1e98597a4aa81d8a79c47eb92e16d839217306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc594acebdc231572f3b2057a04e3317506ac454c5befd1c51aad5d81efb19e343cc37cc6a3ed77eac8e30388486e3e782afe812a7094fccc978c054cebea0c
|
7
|
+
data.tar.gz: 1d1cb83f0c3ada7a3c43c8f150db2e0e143cb4abbca4c783c5f48c7dc06faa7c2301b4615681bec8b56dd88b3c73a7b82b3f768810241f566bc2d9f6ebea95f8
|
@@ -76,12 +76,10 @@ module Api
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def update
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
process_response update_response
|
84
|
-
end
|
79
|
+
@host = ::ForemanDiscovery::HostConverter.to_managed(@discovered_host)
|
80
|
+
forward_request_url
|
81
|
+
update_response = @host.update_attributes(params[:discovered_host])
|
82
|
+
process_response update_response
|
85
83
|
end
|
86
84
|
|
87
85
|
api :DELETE, "/discovered_hosts/:id/", N_("Delete a discovered host")
|
@@ -96,16 +94,12 @@ module Api
|
|
96
94
|
|
97
95
|
def facts
|
98
96
|
state = true
|
99
|
-
Host.
|
100
|
-
@discovered_host, state = Host::Discovered.import_host_and_facts(params[:facts])
|
101
|
-
end
|
97
|
+
@discovered_host, state = Host::Discovered.import_host_and_facts(params[:facts])
|
102
98
|
if Setting['discovery_auto']
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Rails.logger.warn "Discovered facts import unsuccessful, skipping auto provisioning"
|
108
|
-
end
|
99
|
+
if state && rule = find_discovery_rule(@discovered_host)
|
100
|
+
state = perform_auto_provision(@discovered_host, rule)
|
101
|
+
else
|
102
|
+
Rails.logger.warn "Discovered facts import unsuccessful, skipping auto provisioning"
|
109
103
|
end
|
110
104
|
end
|
111
105
|
process_response state
|
@@ -119,21 +113,19 @@ module Api
|
|
119
113
|
param :id, :identifier, :required => true
|
120
114
|
|
121
115
|
def auto_provision
|
122
|
-
|
123
|
-
if
|
124
|
-
|
125
|
-
|
126
|
-
render :json => {:message => msg}
|
127
|
-
else
|
128
|
-
msg = _("Unable to provision %{host}: %{errors}") % {:host => @discovered_host.name, :errors => @discovered_host.errors.full_messages.join(' ')}
|
129
|
-
render :json => {:message => msg}, :status => :unprocessable_entity
|
130
|
-
end
|
116
|
+
if rule = find_discovery_rule(@discovered_host)
|
117
|
+
if perform_auto_provision(@discovered_host, rule)
|
118
|
+
msg = _("Host %{host} was provisioned with rule %{rule}") % {:host => @discovered_host.name, :rule => rule.name}
|
119
|
+
render :json => {:message => msg}
|
131
120
|
else
|
132
|
-
|
133
|
-
|
134
|
-
:message => _("No rule found for host %s") % @discovered_host.name
|
135
|
-
}
|
121
|
+
msg = _("Unable to provision %{host}: %{errors}") % {:host => @discovered_host.name, :errors => @discovered_host.errors.full_messages.join(' ')}
|
122
|
+
render :json => {:message => msg}, :status => :unprocessable_entity
|
136
123
|
end
|
124
|
+
else
|
125
|
+
render_error :custom_error, :status => :not_found,
|
126
|
+
:locals => {
|
127
|
+
:message => _("No rule found for host %s") % @discovered_host.name
|
128
|
+
}
|
137
129
|
end
|
138
130
|
rescue ::Foreman::Exception => e
|
139
131
|
render :json => {'message' => e.to_s}, :status => :unprocessable_entity
|
@@ -151,34 +143,32 @@ module Api
|
|
151
143
|
end
|
152
144
|
|
153
145
|
total_count = 0
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
overall_errors << "#{discovered_host.name}: #{errors} "
|
163
|
-
else
|
164
|
-
total_count += 1
|
165
|
-
end
|
146
|
+
overall_errors = ""
|
147
|
+
Host::Discovered.all.each do |discovered_host|
|
148
|
+
if rule = find_discovery_rule(discovered_host)
|
149
|
+
result &= perform_auto_provision(discovered_host, rule)
|
150
|
+
unless discovered_host.errors.empty?
|
151
|
+
errors = discovered_host.errors.full_messages.join(' ')
|
152
|
+
logger.warn "Failed to auto provision host %s: %s" % [discovered_host.name, errors]
|
153
|
+
overall_errors << "#{discovered_host.name}: #{errors} "
|
166
154
|
else
|
167
|
-
|
155
|
+
total_count += 1
|
168
156
|
end
|
169
|
-
end
|
170
|
-
|
171
|
-
if result
|
172
|
-
msg = _("%s discovered hosts were provisioned") % total_count
|
173
|
-
render :json => {:message => msg}
|
174
157
|
else
|
175
|
-
|
176
|
-
:status => :unprocessable_entity,
|
177
|
-
:locals => {
|
178
|
-
:message => error_message % overall_errors
|
179
|
-
}
|
158
|
+
logger.warn "No rule found for host %s" % discovered_host.name
|
180
159
|
end
|
181
160
|
end
|
161
|
+
|
162
|
+
if result
|
163
|
+
msg = _("%s discovered hosts were provisioned") % total_count
|
164
|
+
render :json => {:message => msg}
|
165
|
+
else
|
166
|
+
render_error :custom_error,
|
167
|
+
:status => :unprocessable_entity,
|
168
|
+
:locals => {
|
169
|
+
:message => error_message % overall_errors
|
170
|
+
}
|
171
|
+
end
|
182
172
|
end
|
183
173
|
|
184
174
|
api :PUT, "/discovered_hosts/:id/refresh_facts", N_("Refreshing the facts of a discovered host")
|
@@ -44,19 +44,18 @@ module Foreman::Controller::DiscoveredExtensions
|
|
44
44
|
|
45
45
|
# trigger the provisioning
|
46
46
|
def perform_auto_provision original_host, rule
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
47
|
+
raise(::Foreman::Exception.new(N_("No hostgroup associated with rule '%s'"), rule)) if rule.hostgroup.nil?
|
48
|
+
host = ::ForemanDiscovery::HostConverter.to_managed(original_host)
|
49
|
+
host.hostgroup_id = rule.hostgroup_id
|
50
|
+
host.comment = "Auto-discovered and provisioned via rule '#{rule.name}'"
|
51
|
+
host.discovery_rule = rule
|
52
|
+
# render hostname only when all other fields are set
|
53
|
+
original_name = host.name
|
54
|
+
host.name = host.render_template(rule.hostname) unless rule.hostname.empty?
|
55
|
+
# fallback to the original if template did not expand
|
56
|
+
host.name = original_name if host.name.empty?
|
57
|
+
# save! does not work here
|
58
|
+
host.save
|
60
59
|
end
|
61
60
|
|
62
61
|
def perform_reboot_all hosts = Host::Discovered.all
|
@@ -65,19 +64,17 @@ module Foreman::Controller::DiscoveredExtensions
|
|
65
64
|
overall_errors = ""
|
66
65
|
|
67
66
|
if hosts.count > 0
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
error = "#{discovered_host.name}: failed to reboot "
|
73
|
-
overall_errors << error
|
74
|
-
logger.error error
|
75
|
-
end
|
76
|
-
rescue Exception => e
|
77
|
-
error = "#{discovered_host.name}: #{e.to_s} "
|
67
|
+
hosts.each do |discovered_host|
|
68
|
+
begin
|
69
|
+
unless discovered_host.reboot
|
70
|
+
error = "#{discovered_host.name}: failed to reboot "
|
78
71
|
overall_errors << error
|
79
72
|
logger.error error
|
80
73
|
end
|
74
|
+
rescue Exception => e
|
75
|
+
error = "#{discovered_host.name}: #{e.to_s} "
|
76
|
+
overall_errors << error
|
77
|
+
logger.error error
|
81
78
|
end
|
82
79
|
end
|
83
80
|
else
|
@@ -3,7 +3,6 @@ class DiscoveredHostsController < ::ApplicationController
|
|
3
3
|
include Foreman::Controller::TaxonomyMultiple
|
4
4
|
include Foreman::Controller::DiscoveredExtensions
|
5
5
|
include ActionView::Helpers::NumberHelper
|
6
|
-
unloadable
|
7
6
|
|
8
7
|
before_filter :find_by_name, :only => %w[edit update destroy refresh_facts convert reboot auto_provision]
|
9
8
|
before_filter :find_by_name_incl_subnet, :only => [:show]
|
@@ -23,6 +22,10 @@ class DiscoveredHostsController < ::ApplicationController
|
|
23
22
|
:model,
|
24
23
|
:discovery_attribute_set
|
25
24
|
], {:interfaces => :subnet}).paginate(:page => params[:page])
|
25
|
+
fact_array = @hosts.collect do |host|
|
26
|
+
[host.id, Hash[host.fact_values.joins(:fact_name).where('fact_names.name' => Setting::Discovered.discovery_fact_column_array).pluck(:name, :value)]]
|
27
|
+
end
|
28
|
+
@host_facts = Hash[fact_array]
|
26
29
|
end
|
27
30
|
|
28
31
|
def show
|
@@ -46,25 +49,21 @@ class DiscoveredHostsController < ::ApplicationController
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def edit
|
49
|
-
|
50
|
-
|
51
|
-
render :template => 'hosts/edit'
|
52
|
-
end
|
52
|
+
@host = ::ForemanDiscovery::HostConverter.to_managed(@host, true, false) unless @host.nil?
|
53
|
+
render :template => 'hosts/edit'
|
53
54
|
end
|
54
55
|
|
55
56
|
def update
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
process_error :object => @host, :render => 'hosts/edit'
|
67
|
-
end
|
57
|
+
@host = ::ForemanDiscovery::HostConverter.to_managed(@host)
|
58
|
+
forward_url_options
|
59
|
+
Taxonomy.no_taxonomy_scope do
|
60
|
+
if @host.update_attributes(params[:host])
|
61
|
+
process_success :success_redirect => host_path(@host), :redirect_xhr => request.xhr?
|
62
|
+
else
|
63
|
+
taxonomy_scope
|
64
|
+
load_vars_for_ajax
|
65
|
+
offer_to_overwrite_conflicts
|
66
|
+
process_error :object => @host, :render => 'hosts/edit'
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -75,6 +74,10 @@ class DiscoveredHostsController < ::ApplicationController
|
|
75
74
|
else
|
76
75
|
process_error :error_msg => _("Failed to refresh facts for %s") % @host.name, :redirect => :back
|
77
76
|
end
|
77
|
+
rescue => e
|
78
|
+
exception = Foreman::WrappedException.new(e, N_("Failed to refresh facts for %{hostname} with error %{error_message}"), :hostname => @host.name, :error_message => e.message)
|
79
|
+
Foreman::Logging.exception exception.message, e
|
80
|
+
process_error :error_msg => exception.message, :redirect => :back
|
78
81
|
end
|
79
82
|
|
80
83
|
def reboot
|
@@ -87,9 +90,10 @@ class DiscoveredHostsController < ::ApplicationController
|
|
87
90
|
else
|
88
91
|
process_error :error_msg => _("Failed to reboot host %s") % @host.name, :redirect => :back
|
89
92
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
rescue => e
|
94
|
+
exception = Foreman::WrappedException.new(e, N_("Failed to reboot host %{hostname} with error %{error_message}"), :hostname => @host.name, :error_message => e.message)
|
95
|
+
Foreman::Logging.exception exception.message, e
|
96
|
+
process_error :error_msg => exception.message, :redirect => :back
|
93
97
|
end
|
94
98
|
|
95
99
|
def reboot_all
|
@@ -100,6 +104,10 @@ class DiscoveredHostsController < ::ApplicationController
|
|
100
104
|
else
|
101
105
|
process_success :success_msg => _("Discovered hosts are rebooting now"), :success_redirect => :back
|
102
106
|
end
|
107
|
+
rescue => e
|
108
|
+
exception = Foreman::WrappedException.new(e, N_("Failed to reboot hosts with error %s"), e.message)
|
109
|
+
Foreman::Logging.exception exception.message, e
|
110
|
+
process_error :error_msg => exception.message, :redirect => :back
|
103
111
|
end
|
104
112
|
|
105
113
|
def multiple_destroy
|
@@ -107,7 +115,7 @@ class DiscoveredHostsController < ::ApplicationController
|
|
107
115
|
|
108
116
|
def submit_multiple_destroy
|
109
117
|
# keep all the ones that were not deleted for notification.
|
110
|
-
@hosts.delete_if {|host| host.destroy}
|
118
|
+
@hosts.to_a.delete_if {|host| host.destroy}
|
111
119
|
|
112
120
|
missed_hosts = @hosts.map(&:name).join('<br/>')
|
113
121
|
if @hosts.empty?
|
@@ -134,18 +142,16 @@ class DiscoveredHostsController < ::ApplicationController
|
|
134
142
|
end
|
135
143
|
|
136
144
|
def auto_provision
|
137
|
-
|
138
|
-
if
|
139
|
-
|
140
|
-
process_success :success_msg => _("Host %{host} was provisioned with rule %{rule}") % {:host => @host.name, :rule => rule.name}, :success_redirect => discovered_hosts_path
|
141
|
-
else
|
142
|
-
errors = @host.errors.full_messages.join(' ')
|
143
|
-
logger.warn "Failed to auto provision host %s: %s" % [@host.name, errors]
|
144
|
-
process_error :error_msg => _("Failed to auto provision host %s: %s") % [@host.name, errors], :redirect => :back
|
145
|
-
end
|
145
|
+
if rule = find_discovery_rule(@host)
|
146
|
+
if perform_auto_provision(@host, rule)
|
147
|
+
process_success :success_msg => _("Host %{host} was provisioned with rule %{rule}") % {:host => @host.name, :rule => rule.name}, :success_redirect => discovered_hosts_path
|
146
148
|
else
|
147
|
-
|
149
|
+
errors = @host.errors.full_messages.join(' ')
|
150
|
+
logger.warn "Failed to auto provision host %s: %s" % [@host.name, errors]
|
151
|
+
process_error :error_msg => _("Failed to auto provision host %s: %s") % [@host.name, errors], :redirect => :back
|
148
152
|
end
|
153
|
+
else
|
154
|
+
process_success :success_msg => _("No rule found for host %s") % @host.name, :success_redirect => :back
|
149
155
|
end
|
150
156
|
end
|
151
157
|
|
@@ -158,23 +164,21 @@ class DiscoveredHostsController < ::ApplicationController
|
|
158
164
|
result = false
|
159
165
|
end
|
160
166
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
overall_errors << "#{discovered_host.name}: #{errors} "
|
170
|
-
end
|
167
|
+
overall_errors = ""
|
168
|
+
Host::Discovered.all.each do |discovered_host|
|
169
|
+
if rule = find_discovery_rule(discovered_host)
|
170
|
+
result &= perform_auto_provision(discovered_host, rule)
|
171
|
+
unless discovered_host.errors.empty?
|
172
|
+
errors = discovered_host.errors.full_messages.join(' ')
|
173
|
+
logger.warn "Failed to auto provision host %s: %s" % [discovered_host.name, errors]
|
174
|
+
overall_errors << "#{discovered_host.name}: #{errors} "
|
171
175
|
end
|
172
176
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
177
|
+
end
|
178
|
+
if result
|
179
|
+
process_success :success_msg => _("Discovered hosts are provisioning now"), :success_redirect => :back
|
180
|
+
else
|
181
|
+
process_error :error_msg => error_message % overall_errors, :redirect => :back
|
178
182
|
end
|
179
183
|
end
|
180
184
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ForemanDiscovery
|
2
|
+
module SettingsHelperExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
alias_method_chain :value, :discovery
|
7
|
+
end
|
8
|
+
|
9
|
+
def value_with_discovery(setting)
|
10
|
+
return value_without_discovery(setting) unless [
|
11
|
+
'discovery_location',
|
12
|
+
'discovery_organization'].include?(setting.name)
|
13
|
+
|
14
|
+
case setting.name
|
15
|
+
when "discovery_location"
|
16
|
+
edit_select(
|
17
|
+
setting,
|
18
|
+
:value,
|
19
|
+
:select_values => discovery_taxonomy_values(Location))
|
20
|
+
when "discovery_organization"
|
21
|
+
edit_select(
|
22
|
+
setting,
|
23
|
+
:value,
|
24
|
+
:select_values => discovery_taxonomy_values(Organization))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def discovery_taxonomy_values(taxonomy_class)
|
31
|
+
Hash[taxonomy_class.all.map{ |org| [org[:title], org[:title]] }].to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -23,14 +23,13 @@ module DiscoveryRulesHelper
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def permitted_discovery_actions(rule)
|
26
|
-
actions = [
|
27
|
-
|
26
|
+
actions = [display_link_if_authorized(_('Discovered Hosts'), hash_for_discovered_hosts_path.merge(:search => rule.search))]
|
27
|
+
actions << display_link_if_authorized(_('Associated Hosts'), hash_for_hosts_path.merge(:search => "discovery_rule = \"#{rule.name}\""))
|
28
28
|
if rule.enabled?
|
29
|
-
actions << display_link_if_authorized(_('Disable'), hash_for_disable_discovery_rule_path(:id => rule),
|
30
|
-
{:confirm => _('Disable rule?')})
|
29
|
+
actions << display_link_if_authorized(_('Disable'), hash_for_disable_discovery_rule_path(:id => rule).merge(:auth_object => rule, :authorizer => authorizer), :confirm => _("Disable rule '%s'?") % rule)
|
31
30
|
else
|
32
|
-
actions << display_link_if_authorized(_('Enable'), hash_for_enable_discovery_rule_path(:id => rule),
|
33
|
-
{:confirm => _('Enable rule?')})
|
31
|
+
actions << display_link_if_authorized(_('Enable'), hash_for_enable_discovery_rule_path(:id => rule).merge(:auth_object => rule, :authorizer => authorizer), :confirm => _("Enable rule '%s'?") % rule)
|
34
32
|
end
|
33
|
+
actions << display_delete_if_authorized(hash_for_discovery_rule_path(:id => rule).merge(:auth_object => rule, :authorizer => authorizer), :confirm => _("Delete rule '%s'?") % rule)
|
35
34
|
end
|
36
35
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class DiscoveredMailer < ::ApplicationMailer
|
2
|
+
helper :discovered_hosts
|
3
|
+
def discovered_summary(options = {})
|
4
|
+
raise ::Foreman::Exception.new(N_("Must specify a user with email enabled")) unless (user = User.find(options[:user])) && user.mail_enabled?
|
5
|
+
begin
|
6
|
+
Time.zone = user.timezone
|
7
|
+
rescue ArgumentError
|
8
|
+
Time.zone = 'UTC'
|
9
|
+
end
|
10
|
+
|
11
|
+
set_url
|
12
|
+
@time = options[:time] || 1.day.ago
|
13
|
+
@discovered_hosts = Host::Discovered.authorized_as(user, :view_discovered_hosts, Host::Discovered).where("created_at >= ?", @time)
|
14
|
+
set_locale_for(user) do
|
15
|
+
subject = _("Discovered hosts summary")
|
16
|
+
mail(:to => user.mail, :subject => subject)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -13,14 +13,14 @@ class DiscoveryRule < ActiveRecord::Base
|
|
13
13
|
validates :hostname, :format => { :with => /\A[a-zA-Z<]/, :message => N_("must start with a letter or ERB.") },
|
14
14
|
:allow_blank => true
|
15
15
|
validates :hostgroup_id, :presence => true
|
16
|
-
validates :max_count, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
|
17
|
-
validates :priority, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
|
16
|
+
validates :max_count, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0, :less_than => 2**31 }
|
17
|
+
validates :priority, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0, :less_than => 2**31 }
|
18
18
|
validates_lengths_from_database
|
19
19
|
before_validation :default_int_attributes
|
20
20
|
before_validation :enforce_taxonomy
|
21
21
|
|
22
22
|
belongs_to :hostgroup
|
23
|
-
has_many :hosts
|
23
|
+
has_many :hosts, :dependent => :nullify
|
24
24
|
|
25
25
|
scoped_search :on => :name, :complete_value => :true
|
26
26
|
scoped_search :on => :priority
|