foreman_salt 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -3
  3. data/app/controllers/foreman_salt/api/v2/base_controller.rb +13 -0
  4. data/app/controllers/foreman_salt/api/v2/jobs_controller.rb +9 -17
  5. data/app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb +64 -0
  6. data/app/controllers/foreman_salt/api/v2/salt_environments_controller.rb +46 -0
  7. data/app/controllers/foreman_salt/api/v2/salt_keys_controller.rb +79 -0
  8. data/app/controllers/foreman_salt/api/v2/salt_minions_controller.rb +44 -0
  9. data/app/controllers/foreman_salt/api/v2/salt_states_controller.rb +46 -0
  10. data/app/controllers/foreman_salt/application_controller.rb +0 -1
  11. data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +0 -41
  12. data/app/controllers/foreman_salt/minions_controller.rb +54 -0
  13. data/app/controllers/foreman_salt/salt_autosign_controller.rb +8 -9
  14. data/app/controllers/foreman_salt/salt_environments_controller.rb +1 -1
  15. data/app/controllers/foreman_salt/salt_keys_controller.rb +10 -11
  16. data/app/controllers/foreman_salt/salt_modules_controller.rb +1 -1
  17. data/app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb +10 -10
  18. data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +2 -2
  19. data/app/helpers/foreman_salt/salt_keys_helper.rb +2 -3
  20. data/app/lib/actions/foreman_salt/report_import.rb +1 -2
  21. data/app/lib/proxy_api/salt.rb +1 -1
  22. data/app/models/foreman_salt/concerns/host_managed_extensions.rb +4 -4
  23. data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +2 -2
  24. data/app/models/foreman_salt/concerns/orchestration/salt.rb +1 -1
  25. data/app/models/foreman_salt/fact_name.rb +0 -1
  26. data/app/models/foreman_salt/salt_environment.rb +2 -0
  27. data/app/models/foreman_salt/salt_module.rb +3 -1
  28. data/app/models/setting/salt.rb +12 -0
  29. data/app/overrides/salt_modules_selector.rb +12 -12
  30. data/app/services/foreman_salt/fact_importer.rb +10 -7
  31. data/app/services/foreman_salt/fact_parser.rb +100 -0
  32. data/app/services/foreman_salt/report_importer.rb +17 -14
  33. data/app/services/foreman_salt/smart_proxies/salt_keys.rb +26 -29
  34. data/app/views/foreman_salt/api/v2/salt_autosign/base.json.rabl +3 -0
  35. data/app/views/foreman_salt/api/v2/salt_autosign/create.json.rabl +3 -0
  36. data/app/views/foreman_salt/api/v2/salt_autosign/index.json.rabl +3 -0
  37. data/app/views/foreman_salt/api/v2/salt_autosign/main.json.rabl +3 -0
  38. data/app/views/foreman_salt/api/v2/salt_environments/base.json.rabl +3 -0
  39. data/app/views/foreman_salt/api/v2/salt_environments/create.json.rabl +3 -0
  40. data/app/views/foreman_salt/api/v2/salt_environments/index.json.rabl +3 -0
  41. data/app/views/foreman_salt/api/v2/salt_environments/main.json.rabl +3 -0
  42. data/app/views/foreman_salt/api/v2/salt_environments/show.json.rabl +3 -0
  43. data/app/views/foreman_salt/api/v2/salt_keys/base.json.rabl +3 -0
  44. data/app/views/foreman_salt/api/v2/salt_keys/index.json.rabl +3 -0
  45. data/app/views/foreman_salt/api/v2/salt_keys/main.json.rabl +3 -0
  46. data/app/views/foreman_salt/api/v2/salt_keys/update.json.rabl +3 -0
  47. data/app/views/foreman_salt/api/v2/salt_minions/base.json.rabl +3 -0
  48. data/app/views/foreman_salt/api/v2/salt_minions/index.json.rabl +3 -0
  49. data/app/views/foreman_salt/api/v2/salt_minions/main.json.rabl +3 -0
  50. data/app/views/foreman_salt/api/v2/salt_minions/show.json.rabl +8 -0
  51. data/app/views/foreman_salt/api/v2/salt_states/base.json.rabl +3 -0
  52. data/app/views/foreman_salt/api/v2/salt_states/create.json.rabl +3 -0
  53. data/app/views/foreman_salt/api/v2/salt_states/index.json.rabl +3 -0
  54. data/app/views/foreman_salt/api/v2/salt_states/main.json.rabl +3 -0
  55. data/app/views/foreman_salt/api/v2/salt_states/show.json.rabl +3 -0
  56. data/config/routes.rb +25 -12
  57. data/db/migrate/20140813081913_add_salt_proxy_to_host_and_host_group.rb +0 -1
  58. data/db/migrate/20140817210214_create_salt_modules.rb +1 -1
  59. data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +22 -0
  60. data/lib/foreman_salt/engine.rb +114 -57
  61. data/lib/foreman_salt/version.rb +1 -1
  62. data/lib/tasks/foreman_salt_tasks.rake +2 -2
  63. data/test/functional/api/v2/salt_autosign_controller_test.rb +27 -0
  64. data/test/functional/api/v2/salt_environments_controller_test.rb +33 -0
  65. data/test/functional/api/v2/salt_keys_controller_test.rb +29 -0
  66. data/test/functional/api/v2/salt_states_controller_test.rb +33 -0
  67. data/test/functional/minions_controller_test.rb +18 -0
  68. data/test/integration/salt_environment_test.rb +0 -1
  69. data/test/integration/salt_keys_test.rb +4 -6
  70. data/test/integration/salt_module_test.rb +0 -1
  71. data/test/unit/grains_centos.json +4 -1
  72. data/test/unit/grains_importer_test.rb +39 -13
  73. data/test/unit/salt_keys_test.rb +4 -6
  74. metadata +44 -5
  75. data/app/controllers/foreman_salt/concerns/smart_proxy_auth_extensions.rb +0 -24
  76. data/test/functional/hosts_controller_test.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce1b4cb399d2e977121144ef5e214df9cfb96c14
4
- data.tar.gz: 7ae9a7bfe423ed887ae6b6a4b553bebc2a493197
3
+ metadata.gz: 65b92f3373cea9c5f4be875edbae423c369ca7bb
4
+ data.tar.gz: 85a03b34a72fa72659b5ab3ebf5f7428a463c7bf
5
5
  SHA512:
6
- metadata.gz: 642dccb0a0683cee2885bcf2a9446c13687fb8af7685537d1b2db45532c81c59476fb326e91c1e1144ccb0882f236ee18497b3fd64d580aaf68de4891e1070e0
7
- data.tar.gz: 3cc3ab238b85f88d1c60f8bf6e8c29985de38a28ebfdadb58e010ddf25c6458c8d69b9f8c354b6aeebe8ba6690f33482f5cf04c02d264f7e913363fd5e9de40f
6
+ metadata.gz: bbbf937cb431c0d96205def06cc7e069953ca15eba4548dd3ae09edb7e4515fe10ddbecdf8ee4edc3a082508dd31005fc153f501901a6885928c5747cfed1319
7
+ data.tar.gz: 40ed6313ddeca1b424eed17583331d32cc2bc858f37e77a046e71be6530eb66dc1bfb9f57c7079ce50f3aba18cf57ad59e3d808865a3ca05e0011fbcf8a31a0a
data/Rakefile CHANGED
@@ -23,8 +23,6 @@ end
23
23
  APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
-
27
-
28
26
  Bundler::GemHelper.install_tasks
29
27
 
30
28
  require 'rake/testtask'
@@ -36,5 +34,4 @@ Rake::TestTask.new(:test) do |t|
36
34
  t.verbose = false
37
35
  end
38
36
 
39
-
40
37
  task :default => :test
@@ -0,0 +1,13 @@
1
+ module ForemanSalt
2
+ module Api
3
+ module V2
4
+ class BaseController < ::Api::V2::BaseController
5
+ resource_description do
6
+ resource_id 'foreman_salt'
7
+ api_version 'v2'
8
+ api_base_url '/salt/api'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,16 +3,9 @@ require 'uri'
3
3
  module ForemanSalt
4
4
  module Api
5
5
  module V2
6
- class JobsController < ::Api::V2::BaseController
7
- include ::Api::Version2
6
+ class JobsController < ::ForemanSalt::Api::V2::BaseController
8
7
  include ::Foreman::Controller::SmartProxyAuth
9
- include ForemanSalt::Concerns::SmartProxyAuthExtensions
10
-
11
- add_puppetmaster_filters :upload
12
-
13
- resource_description do
14
- api_base_url '/salt/api'
15
- end
8
+ add_smart_proxy_filters :upload, :features => 'Salt'
16
9
 
17
10
  def_param_group :job do
18
11
  param :job, Hash, :required => true, :action_aware => true do
@@ -22,7 +15,7 @@ module ForemanSalt
22
15
  end
23
16
  end
24
17
 
25
- api :POST, '/upload/', N_('Upload a Job')
18
+ api :POST, '/upload', N_('Upload a Job')
26
19
  param_group :job, :as => :upload
27
20
 
28
21
  def upload
@@ -32,16 +25,16 @@ module ForemanSalt
32
25
  # Dynflowize the action if we can, otherwise we'll do it live
33
26
  if defined? ForemanTasks
34
27
  task = ForemanTasks.async_task(::Actions::ForemanSalt::ReportImport, params[:job], detected_proxy.try(:id))
35
- render :json => {:task_id => task.id}
28
+ render :json => { :task_id => task.id }
36
29
  else
37
30
  reports = ForemanSalt::ReportImporter.import(params[:job][:result], detected_proxy.try(:id))
38
- render :json => {:message => "Imported #{reports.count} new reports."}
31
+ render :json => { :message => "Imported #{reports.count} new reports." }
39
32
  end
40
33
  else
41
- render :json => {:message => 'Unsupported function'}, :status => :unprocessable_entity
34
+ render :json => { :message => 'Unsupported function' }, :status => :unprocessable_entity
42
35
  end
43
36
  rescue ::Foreman::Exception => e
44
- render :json => {:message => e.to_s}, :status => :unprocessable_entity
37
+ render :json => { :message => e.to_s }, :status => :unprocessable_entity
45
38
  end
46
39
 
47
40
  def resource_class
@@ -54,12 +47,11 @@ module ForemanSalt
54
47
  case params[:action]
55
48
  when 'upload'
56
49
  :create
57
- else
58
- super
50
+ else
51
+ super
59
52
  end
60
53
  end
61
54
  end
62
55
  end
63
56
  end
64
57
  end
65
-
@@ -0,0 +1,64 @@
1
+ require 'ostruct'
2
+
3
+ module ForemanSalt
4
+ module Api
5
+ module V2
6
+ class SaltAutosignController < ::ForemanSalt::Api::V2::BaseController
7
+ before_filter :find_proxy, :setup_proxy
8
+
9
+ api :GET, '/salt_autosign/:smart_proxy_id', N_('List all autosign records')
10
+ param :smart_proxy_id, :identifier_dottable, :required => true
11
+ def index
12
+ @salt_autosigns = all_autosign
13
+ end
14
+
15
+ api :POST, '/salt_autosign/:smart_proxy_id', N_('Create an autosign record')
16
+ param :smart_proxy_id, :identifier_dottable, :required => true
17
+ param :record, String, :required => true, :desc => N_('Autosign record')
18
+ def create
19
+ @api.autosign_create params[:record]
20
+ @salt_autosign = { :record => params[:record] }
21
+ end
22
+
23
+ api :DELETE, '/salt_autosign/:smart_proxy_id/:record', N_('Delete an autosign record')
24
+ param :smart_proxy_id, :identifier_dottable, :required => true
25
+ param :record, String, :required => true, :desc => N_('Autosign record')
26
+ def destroy
27
+ @api.autosign_remove params[:record]
28
+ render :json => { root_node_name => _('Record deleted.') }
29
+ end
30
+
31
+ def metadata_total
32
+ @total ||= all_autosign.count
33
+ end
34
+
35
+ def metadata_subtotal
36
+ metadata_total
37
+ end
38
+
39
+ def metadata_page
40
+ 1
41
+ end
42
+
43
+ def metadata_per_page
44
+ metadata_total
45
+ end
46
+
47
+ private
48
+
49
+ def all_autosign
50
+ @_autosigns ||= @api.autosign_list.map { |record| OpenStruct.new(:record => record) }
51
+ end
52
+
53
+ def find_proxy
54
+ @proxy = ::SmartProxy.find(params[:smart_proxy_id])
55
+ not_found unless @proxy
56
+ end
57
+
58
+ def setup_proxy
59
+ @api = ProxyAPI::Salt.new(:url => @proxy.url)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,46 @@
1
+ module ForemanSalt
2
+ module Api
3
+ module V2
4
+ class SaltEnvironmentsController < ::ForemanSalt::Api::V2::BaseController
5
+ before_filter :find_resource, :except => [:index, :create]
6
+
7
+ api :GET, '/salt_environments', N_('List all Salt environments')
8
+ def index
9
+ @salt_environments = resource_scope_for_index
10
+ end
11
+
12
+ api :GET, '/salt_environments/:id/', N_('Show a Salt environment')
13
+ param :id, :identifier_dottable, :required => true
14
+ def show
15
+ end
16
+
17
+ def_param_group :environment do
18
+ param :environment, Hash, :required => true, :action_aware => true do
19
+ param :name, String, :required => true
20
+ end
21
+ end
22
+
23
+ api :POST, '/salt_environments', N_('Create a Salt environment')
24
+ param_group :environment, :as => :create
25
+ def create
26
+ @salt_environment = SaltEnvironment.new(params[:environment])
27
+ process_response @salt_environment.save
28
+ end
29
+
30
+ api :DELETE, '/salt_environments/:id/', N_('Destroy a Salt environment')
31
+ param :id, :identifier, :required => true
32
+ def destroy
33
+ process_response @salt_environment.destroy
34
+ end
35
+
36
+ def controller_permission
37
+ 'salt_environments'
38
+ end
39
+
40
+ def resource_class
41
+ ForemanSalt::SaltEnvironment
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,79 @@
1
+ module ForemanSalt
2
+ module Api
3
+ module V2
4
+ class SaltKeysController < ::ForemanSalt::Api::V2::BaseController
5
+ before_filter :find_proxy
6
+ before_filter :find_key, :only => [:update, :destroy]
7
+
8
+ api :GET, '/salt_keys/:smart_proxy_id', N_('List all Salt keys')
9
+ param :smart_proxy_id, :identifier_dottable, :required => true
10
+ def index
11
+ @salt_keys = all_keys
12
+ end
13
+
14
+ def_param_group :key do
15
+ param :smart_proxy_id, :identifier_dottable, :required => true
16
+ param :name, String, :required => true, :desc => N_('FQDN of host that key belongs to')
17
+ end
18
+
19
+ api :PUT, '/salt_keys/:smart_proxy_id/:name', N_('Update a Salt Key')
20
+ param :name, :identifier_dottable, :required => true
21
+ param :smart_proxy_id, :identifier_dottable, :required => true
22
+ param :state, String, :required => true, :desc => N_('State can be "accepted" or "rejected"')
23
+ def update
24
+ case params[:key][:state]
25
+ when 'accepted'
26
+ @key.accept
27
+ when 'rejected'
28
+ @key.reject
29
+ end
30
+
31
+ @salt_key = find_key(@key.name)
32
+ end
33
+
34
+ api :DELETE, '/salt_keys/:smart_proxy_id/:name', N_('Delete a Salt Key')
35
+ param_group :key, :as => :destroy
36
+ def destroy
37
+ if @key.delete
38
+ message = 'Key successfully deleted.'
39
+ else
40
+ message = 'Unable to delete key.'
41
+ end
42
+ render :json => { root_node_name => message }
43
+ end
44
+
45
+ def metadata_total
46
+ @total ||= all_keys.count
47
+ end
48
+
49
+ def metadata_subtotal
50
+ metadata_total
51
+ end
52
+
53
+ def metadata_page
54
+ 1
55
+ end
56
+
57
+ def metadata_per_page
58
+ metadata_total
59
+ end
60
+
61
+ private
62
+
63
+ def all_keys
64
+ @_keys ||= SmartProxies::SaltKeys.all(@proxy)
65
+ end
66
+
67
+ def find_proxy
68
+ @proxy = ::SmartProxy.find(params[:smart_proxy_id])
69
+ not_found unless @proxy
70
+ end
71
+
72
+ def find_key(name = params[:name])
73
+ @key = SmartProxies::SaltKeys.find(@proxy, name)
74
+ @key || not_found
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,44 @@
1
+ module ForemanSalt
2
+ module Api
3
+ module V2
4
+ class SaltMinionsController < ::ForemanSalt::Api::V2::BaseController
5
+ before_filter :find_resource, :except => [:index]
6
+
7
+ api :GET, '/salt_minions', N_('List all Salt Minions')
8
+ def index
9
+ @salt_minions = resource_scope_for_index
10
+ end
11
+
12
+ api :GET, '/salt_minions/:id', N_('Show a minion')
13
+ param :id, :identifier_dottable, :required => true
14
+ def show
15
+ @salt_states = @salt_minion.salt_modules
16
+ end
17
+
18
+ def_param_group :minion do
19
+ param :minion, Hash, :required => true, :action_aware => true do
20
+ param :salt_environment_id, :number, :desc => N_('Salt environment ID')
21
+ param :salt_proxy_id, :number, :desc => N_('ID of Salt Proxy')
22
+ param :salt_state_ids, Array, :desc => N_('Array of State ids')
23
+ end
24
+ end
25
+
26
+ api :PUT, '/salt_minions/:id/', N_('Update a minion')
27
+ param :id, :identifier_dottable, :required => true
28
+ param_group :minion
29
+ def update
30
+ params[:minion][:salt_module_ids] = params[:minion].delete(:salt_state_ids)
31
+ process_response @salt_minion.update_attributes(params[:minion])
32
+ end
33
+
34
+ def controller_permission
35
+ 'hosts'
36
+ end
37
+
38
+ def resource_class
39
+ Host
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,46 @@
1
+ module ForemanSalt
2
+ module Api
3
+ module V2
4
+ class SaltStatesController < ::ForemanSalt::Api::V2::BaseController
5
+ before_filter :find_resource, :except => [:index, :create]
6
+
7
+ api :GET, '/salt_states', N_('List all Salt states')
8
+ def index
9
+ @salt_states = resource_scope_for_index
10
+ end
11
+
12
+ api :GET, '/salt_states/:id/', N_('Show a state')
13
+ param :id, :identifier_dottable, :required => true
14
+ def show
15
+ end
16
+
17
+ def_param_group :state do
18
+ param :state, Hash, :required => true, :action_aware => true do
19
+ param :name, String, :required => true, :desc => N_('Name of the Salt state')
20
+ end
21
+ end
22
+
23
+ api :POST, '/salt_states', N_('Create a state')
24
+ param_group :state, :as => :create
25
+ def create
26
+ @salt_state = SaltModule.new(params[:state])
27
+ process_response @salt_state.save
28
+ end
29
+
30
+ api :DELETE, '/salt_states/:id/', N_('Destroy a state')
31
+ param :id, :identifier_dottable, :required => true
32
+ def destroy
33
+ process_response @salt_state.destroy
34
+ end
35
+
36
+ def controller_permission
37
+ 'salt_modules'
38
+ end
39
+
40
+ def resource_class
41
+ ForemanSalt::SaltModule
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,6 +1,5 @@
1
1
  module ForemanSalt
2
2
  class ApplicationController < ::ApplicationController
3
-
4
3
  def resource_class
5
4
  "ForemanSalt::#{controller_name.singularize.classify}".constantize
6
5
  end
@@ -4,40 +4,10 @@ module ForemanSalt
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- alias_method :find_resource_salt, :find_resource
8
- before_filter :find_resource_salt, :only => [:saltrun]
9
- alias_method_chain :action_permission, :salt_run
10
7
  alias_method_chain :load_vars_for_ajax, :salt_modules
11
8
  alias_method_chain :process_hostgroup, :salt_modules
12
9
  end
13
10
 
14
- def saltrun
15
- if @host.saltrun!
16
- notice _('Successfully executed, check log files for more details')
17
- else
18
- error @host.errors[:base].to_sentence
19
- end
20
- redirect_to host_path(@host)
21
- end
22
-
23
- def salt_external_node
24
- begin
25
- @host = resource_base.find(params[:name])
26
- enc = {}
27
- env = @host.salt_environment.blank? ? 'base' : @host.salt_environment.name
28
- enc['classes'] = @host.salt_modules.any? ? @host.salt_modules.map(&:name) : []
29
- enc['parameters'] = @host.info['parameters']
30
- enc['environment'] = env
31
- respond_to do |format|
32
- format.html { render :text => "<pre>#{ERB::Util.html_escape(enc.to_yaml)}</pre>" }
33
- format.yml { render :text => enc.to_yaml }
34
- end
35
- rescue
36
- logger.warn "Failed to generate external nodes for #{@host} with #{$!}"
37
- render :text => _('Unable to generate output, Check log files\n'), :status => 412 and return
38
- end
39
- end
40
-
41
11
  def process_hostgroup_with_salt_modules
42
12
  @hostgroup = Hostgroup.find(params[:host][:hostgroup_id]) if params[:host][:hostgroup_id].to_i > 0
43
13
  return head(:not_found) unless @hostgroup
@@ -49,17 +19,6 @@ module ForemanSalt
49
19
 
50
20
  private
51
21
 
52
- def action_permission_with_salt_run
53
- case params[:action]
54
- when 'saltrun'
55
- :saltrun
56
- when 'salt_external_node'
57
- :view
58
- else
59
- action_permission_without_salt_run
60
- end
61
- end
62
-
63
22
  def load_vars_for_ajax_with_salt_modules
64
23
  return unless @host
65
24
  @salt_modules = @host.salt_modules
@@ -0,0 +1,54 @@
1
+ module ForemanSalt
2
+ class MinionsController < ::ForemanSalt::ApplicationController
3
+ include ::Foreman::Controller::SmartProxyAuth
4
+
5
+ before_filter :find_resource, :only => [:node, :run]
6
+ add_smart_proxy_filters :node, :features => 'Salt'
7
+
8
+ def node
9
+ enc = {}
10
+ env = @minion.salt_environment.blank? ? 'base' : @minion.salt_environment.name
11
+ enc['classes'] = @minion.salt_modules.any? ? @minion.salt_modules.map(&:name) : []
12
+
13
+ pillars = @minion.info['parameters']
14
+ enc['parameters'] = Setting[:salt_namespace_pillars] ? { 'foreman' => pillars } : pillars
15
+
16
+ enc['environment'] = env
17
+ respond_to do |format|
18
+ format.html { render :text => "<pre>#{ERB::Util.html_escape(enc.to_yaml)}</pre>" }
19
+ format.yml { render :text => enc.to_yaml }
20
+ end
21
+ rescue
22
+ logger.warn "Failed to generate external nodes for #{@minion} with #{$ERROR_INFO}"
23
+ render :text => _('Unable to generate output, Check log files\n'), :status => 412 and return
24
+ end
25
+
26
+ def run
27
+ if @minion.saltrun!
28
+ notice _('Successfully executed, check log files for more details')
29
+ else
30
+ error @minion.errors[:base].to_sentence
31
+ end
32
+ redirect_to host_path(@minion)
33
+ end
34
+
35
+ def action_permission
36
+ case params[:action]
37
+ when 'run'
38
+ :saltrun
39
+ when 'node'
40
+ :view
41
+ else
42
+ super
43
+ end
44
+ end
45
+
46
+ def controller_permission
47
+ 'hosts'
48
+ end
49
+
50
+ def resource_class
51
+ Host
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,5 @@
1
1
  module ForemanSalt
2
- class SaltAutosignController < ApplicationController
3
-
2
+ class SaltAutosignController < ::ForemanSalt::ApplicationController
4
3
  def index
5
4
  setup
6
5
  autosign = @api.autosign_list
@@ -15,10 +14,10 @@ module ForemanSalt
15
14
  setup
16
15
 
17
16
  if @api.autosign_create(params[:id])
18
- process_success({:success_redirect => hash_for_smart_proxy_salt_autosign_index_path, :success_msg => _("Autosign created for #{params[:id]}"),
19
- :object_name => params[:id]})
17
+ process_success(:success_redirect => hash_for_smart_proxy_salt_autosign_index_path, :success_msg => _("Autosign created for #{params[:id]}"),
18
+ :object_name => params[:id])
20
19
  else
21
- process_error({:redirect => hash_for_smart_proxy_salt_autosign_index_path})
20
+ process_error(:redirect => hash_for_smart_proxy_salt_autosign_index_path)
22
21
  end
23
22
  end
24
23
 
@@ -26,10 +25,10 @@ module ForemanSalt
26
25
  setup
27
26
 
28
27
  if @api.autosign_remove(params[:id])
29
- process_success({:success_redirect => hash_for_smart_proxy_salt_autosign_index_path, :success_msg => _("Autosign deleted for #{params[:id]}"),
30
- :object_name => params[:id]})
28
+ process_success(:success_redirect => hash_for_smart_proxy_salt_autosign_index_path, :success_msg => _("Autosign deleted for #{params[:id]}"),
29
+ :object_name => params[:id])
31
30
  else
32
- process_error({:redirect => hash_for_smart_proxy_salt_autosign_index_path})
31
+ process_error(:redirect => hash_for_smart_proxy_salt_autosign_index_path)
33
32
  end
34
33
  end
35
34
 
@@ -37,7 +36,7 @@ module ForemanSalt
37
36
 
38
37
  def setup
39
38
  @proxy = SmartProxy.authorized(:view_smart_proxies_salt_autosign).find(params[:smart_proxy_id])
40
- @api = ProxyAPI::Salt.new({:url => @proxy.url})
39
+ @api = ProxyAPI::Salt.new(:url => @proxy.url)
41
40
  end
42
41
  end
43
42
  end
@@ -1,5 +1,5 @@
1
1
  module ForemanSalt
2
- class SaltEnvironmentsController < ApplicationController
2
+ class SaltEnvironmentsController < ::ForemanSalt::ApplicationController
3
3
  include Foreman::Controller::AutoCompleteSearch
4
4
 
5
5
  before_filter :find_resource, :only => [:edit, :update, :destroy]
@@ -1,6 +1,5 @@
1
1
  module ForemanSalt
2
- class SaltKeysController < ApplicationController
3
-
2
+ class SaltKeysController < ::ForemanSalt::ApplicationController
4
3
  def index
5
4
  @proxy = find_proxy
6
5
 
@@ -17,10 +16,10 @@ module ForemanSalt
17
16
  @proxy = find_proxy(:edit_smart_proxies_salt_keys)
18
17
  key = SmartProxies::SaltKeys.find(@proxy, params[:salt_key_id])
19
18
  if key.accept
20
- process_success({:success_redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true),
21
- :success_msg => _("Key accepted for #{key}"), :object_name => key.to_s})
19
+ process_success(:success_redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true),
20
+ :success_msg => _("Key accepted for #{key}"), :object_name => key.to_s)
22
21
  else
23
- process_error({:redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true)})
22
+ process_error(:redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true))
24
23
  end
25
24
  end
26
25
 
@@ -28,10 +27,10 @@ module ForemanSalt
28
27
  @proxy = find_proxy(:edit_smart_proxies_salt_keys)
29
28
  key = SmartProxies::SaltKeys.find(@proxy, params[:salt_key_id])
30
29
  if key.reject
31
- process_success({:success_redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true),
32
- :success_msg => _("Key rejected for #{key}"), :object_name => key.to_s})
30
+ process_success(:success_redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true),
31
+ :success_msg => _("Key rejected for #{key}"), :object_name => key.to_s)
33
32
  else
34
- process_error({:redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true)})
33
+ process_error(:redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true))
35
34
  end
36
35
  end
37
36
 
@@ -39,10 +38,10 @@ module ForemanSalt
39
38
  @proxy = find_proxy(:destroy_smart_proxies_salt_keys)
40
39
  key = SmartProxies::SaltKeys.find(@proxy, params[:id])
41
40
  if key.delete
42
- process_success({:success_redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true),
43
- :success_msg => _("Key deleted for #{key}"), :object_name => key.to_s})
41
+ process_success(:success_redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true),
42
+ :success_msg => _("Key deleted for #{key}"), :object_name => key.to_s)
44
43
  else
45
- process_error({:redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true)})
44
+ process_error(:redirect => hash_for_smart_proxy_salt_keys_path(:state => params[:state], :expire_cache => true))
46
45
  end
47
46
  end
48
47
 
@@ -1,5 +1,5 @@
1
1
  module ForemanSalt
2
- class SaltModulesController < ApplicationController
2
+ class SaltModulesController < ::ForemanSalt::ApplicationController
3
3
  include Foreman::Controller::AutoCompleteSearch
4
4
 
5
5
  before_filter :find_resource, :only => [:edit, :update, :destroy]
@@ -9,20 +9,20 @@ module ForemanSalt
9
9
 
10
10
  def show_appropriate_host_buttons_with_salt(host)
11
11
  (show_appropriate_host_buttons_without_salt(host) +
12
- [(link_to_if_authorized(_('Salt ENC'), {:controller => :hosts, :action => :salt_external_node, :name => host},
13
- :title => _('Salt external nodes YAML dump'), :class => 'btn btn-default') unless host.salt_master.blank?)]).flatten.compact
12
+ [(link_to_if_authorized(_('Salt ENC'), { :controller => :'foreman_salt/minions', :action => :node, :id => host },
13
+ :title => _('Salt external nodes YAML dump'), :class => 'btn btn-default') unless host.salt_master.blank?)]).flatten.compact
14
14
  end
15
15
 
16
16
  def host_title_actions_with_salt_run(host)
17
- title_actions(
18
- button_group(
19
- if host.try(:salt_proxy)
20
- link_to_if_authorized(_('Run Salt'), {:controller => :hosts, :action => :saltrun, :id => @host},
21
- :title => _('Trigger a state.highstate run on a node'))
22
- end
23
- )
17
+ title_actions(
18
+ button_group(
19
+ if host.try(:salt_proxy)
20
+ link_to_if_authorized(_('Run Salt'), { :controller => :'foreman_salt/minions', :action => :run, :id => host },
21
+ :title => _('Trigger a state.highstate run on a node'))
22
+ end
24
23
  )
25
- host_title_actions_without_salt_run(host)
24
+ )
25
+ host_title_actions_without_salt_run(host)
26
26
  end
27
27
  end
28
28
  end
@@ -10,11 +10,11 @@ module ForemanSalt
10
10
  salt = proxy.features.detect { |feature| feature.name == 'Salt' }
11
11
  [
12
12
  if salt
13
- display_link_if_authorized(_('Salt Keys'), {:controller => 'foreman_salt/salt_keys', :action => 'index', :smart_proxy_id => proxy})
13
+ display_link_if_authorized(_('Salt Keys'), :controller => 'foreman_salt/salt_keys', :action => 'index', :smart_proxy_id => proxy)
14
14
  end,
15
15
 
16
16
  if salt
17
- display_link_if_authorized(_('Salt Autosign'), {:controller => 'foreman_salt/salt_autosign', :action => 'index', :smart_proxy_id => proxy})
17
+ display_link_if_authorized(_('Salt Autosign'), :controller => 'foreman_salt/salt_autosign', :action => 'index', :smart_proxy_id => proxy)
18
18
  end
19
19
  ] + proxy_actions_without_salt_proxy(proxy, authorizer)
20
20
  end