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
@@ -1,9 +1,8 @@
1
1
  module ForemanSalt
2
2
  module SaltKeysHelper
3
3
  def salt_keys_state_filter
4
- select_tag 'Filter', options_for_select(['', _('Accepted'),_('Rejected'), _('Unaccepted')], params[:state]),
5
- :onchange => "window.location.href = location.protocol + '//' + location.host + location.pathname + (this.value == '' ? '' : ('?state=' + this.value))"
4
+ select_tag 'Filter', options_for_select(['', _('Accepted'), _('Rejected'), _('Unaccepted')], params[:state]),
5
+ :onchange => "window.location.href = location.protocol + '//' + location.host + location.pathname + (this.value == '' ? '' : ('?state=' + this.value))"
6
6
  end
7
7
  end
8
8
  end
9
-
@@ -2,7 +2,6 @@ module Actions
2
2
  module ForemanSalt
3
3
  if defined? ForemanTasks
4
4
  class ReportImport < Actions::EntryAction
5
-
6
5
  def resource_locks
7
6
  :report_import
8
7
  end
@@ -15,7 +14,7 @@ module Actions
15
14
  ::User.as_anonymous_admin do
16
15
  reports = ::ForemanSalt::ReportImporter.import(input[:report], input[:proxy_id])
17
16
 
18
- output[:state] = {:message => "Imported #{reports.count} new reports"}
17
+ output[:state] = { :message => "Imported #{reports.count} new reports" }
19
18
  output[:hosts] = reports.map { |report| report.host.name }
20
19
  end
21
20
  end
@@ -32,7 +32,7 @@ module ::ProxyAPI
32
32
  end
33
33
 
34
34
  def key_accept(name)
35
- parse(post('',"key/#{name}"))
35
+ parse(post('', "key/#{name}"))
36
36
  rescue => e
37
37
  raise ProxyException.new(url, e, N_('Unable to accept Salt key for %s'), name)
38
38
  end
@@ -43,16 +43,16 @@ module ForemanSalt
43
43
  logger.warn 'Unable to execute salt run, no salt proxies defined'
44
44
  return false
45
45
  end
46
- ProxyAPI::Salt.new({:url => salt_proxy.url}).highstate name
46
+ ProxyAPI::Salt.new(:url => salt_proxy.url).highstate name
47
47
  rescue => e
48
48
  errors.add(:base, _('Failed to execute state.highstate: %s') % e)
49
49
  false
50
50
  end
51
51
 
52
52
  def set_hostgroup_defaults_with_salt_proxy
53
- return unless hostgroup
54
- assign_hostgroup_attributes(%w{salt_proxy_id salt_environment_id})
55
- set_hostgroup_defaults_without_salt_proxy
53
+ return unless hostgroup
54
+ assign_hostgroup_attributes(%w(salt_proxy_id salt_environment_id))
55
+ set_hostgroup_defaults_without_salt_proxy
56
56
  end
57
57
 
58
58
  def smart_proxy_ids_with_salt_proxy
@@ -40,7 +40,7 @@ module ForemanSalt
40
40
  if ancestry.present?
41
41
  read_attribute(:salt_proxy_id) || self.class.sort_by_ancestry(ancestors.where('salt_proxy_id is not NULL')).last.try(:salt_proxy_id)
42
42
  else
43
- self.salt_proxy_id
43
+ salt_proxy_id
44
44
  end
45
45
  end
46
46
 
@@ -53,7 +53,7 @@ module ForemanSalt
53
53
  if ancestry.present?
54
54
  read_attribute(:salt_environment_id) || self.class.sort_by_ancestry(ancestors.where('salt_environment_id is not NULL')).last.try(:salt_environment_id)
55
55
  else
56
- self.salt_environment_id
56
+ salt_environment_id
57
57
  end
58
58
  end
59
59
 
@@ -7,7 +7,7 @@ module ForemanSalt
7
7
 
8
8
  included do
9
9
  after_validation :queue_salt_autosign
10
- before_destroy :queue_salt_destroy
10
+ before_destroy :queue_salt_destroy
11
11
  end
12
12
 
13
13
  def salt?
@@ -1,4 +1,3 @@
1
1
  module ForemanSalt
2
2
  class FactName < ::FactName; end
3
3
  end
4
-
@@ -2,6 +2,8 @@ module ForemanSalt
2
2
  class SaltEnvironment < ActiveRecord::Base
3
3
  include Taxonomix
4
4
  include Authorizable
5
+ extend FriendlyId
6
+ friendly_id :name
5
7
 
6
8
  before_destroy EnsureNotUsedBy.new(:hosts, :hostgroups)
7
9
 
@@ -2,10 +2,12 @@ module ForemanSalt
2
2
  class SaltModule < ActiveRecord::Base
3
3
  include Taxonomix
4
4
  include Authorizable
5
+ extend FriendlyId
6
+ friendly_id :name
5
7
 
6
8
  before_destroy EnsureNotUsedBy.new(:hosts, :hostgroups)
7
9
  has_and_belongs_to_many :hosts, :class_name => '::Host::Managed', :join_table => 'hosts_salt_modules',
8
- :association_foreign_key => 'host_id'
10
+ :association_foreign_key => 'host_id'
9
11
 
10
12
  has_and_belongs_to_many :hostgroups, :class_name => '::Hostgroup', :join_table => 'hostgroups_salt_modules'
11
13
 
@@ -0,0 +1,12 @@
1
+ class Setting::Salt < Setting
2
+ def self.load_defaults
3
+ return unless super
4
+
5
+ transaction do
6
+ [
7
+ set('salt_namespace_pillars', N_("Namespace Foreman pillars under 'foreman' key"), false)
8
+ ].each { |s| self.create! s.update(:category => 'Setting::Salt') }
9
+ end
10
+ true
11
+ end
12
+ end
@@ -1,19 +1,19 @@
1
1
  Deface::Override.new(:virtual_path => 'hosts/_form',
2
- :name => 'add_salt_modules_tab_to_host',
3
- :insert_after => 'li.active',
4
- :partial => '../overrides/foreman/salt_modules/host_tab')
2
+ :name => 'add_salt_modules_tab_to_host',
3
+ :insert_after => 'li.active',
4
+ :partial => '../overrides/foreman/salt_modules/host_tab')
5
5
 
6
6
  Deface::Override.new(:virtual_path => 'hosts/_form',
7
- :name => 'add_salt_modules_tab_pane_to_host',
8
- :insert_before => 'div#puppet_klasses',
9
- :partial => '../overrides/foreman/salt_modules/host_tab_pane')
7
+ :name => 'add_salt_modules_tab_pane_to_host',
8
+ :insert_before => 'div#puppet_klasses',
9
+ :partial => '../overrides/foreman/salt_modules/host_tab_pane')
10
10
 
11
11
  Deface::Override.new(:virtual_path => 'hostgroups/_form',
12
- :name => 'add_salt_modules_tab_to_hg',
13
- :insert_after => 'li.active',
14
- :partial => '../overrides/foreman/salt_modules/host_tab')
12
+ :name => 'add_salt_modules_tab_to_hg',
13
+ :insert_after => 'li.active',
14
+ :partial => '../overrides/foreman/salt_modules/host_tab')
15
15
 
16
16
  Deface::Override.new(:virtual_path => 'hostgroups/_form',
17
- :name => 'add_salt_modules_tab_pane_to_hg',
18
- :insert_before => 'div#puppet_klasses',
19
- :partial => '../overrides/foreman/salt_modules/host_tab_pane')
17
+ :name => 'add_salt_modules_tab_pane_to_hg',
18
+ :insert_before => 'div#puppet_klasses',
19
+ :partial => '../overrides/foreman/salt_modules/host_tab_pane')
@@ -8,6 +8,10 @@ module ForemanSalt
8
8
  true
9
9
  end
10
10
 
11
+ def self.authorized_smart_proxy_features
12
+ 'Salt'
13
+ end
14
+
11
15
  private
12
16
 
13
17
  attr_accessor :original_facts
@@ -82,27 +86,26 @@ module ForemanSalt
82
86
  end
83
87
 
84
88
  def sort_by_key(hash)
85
- hash.sort_by { |k, v| k.to_s }
89
+ hash.sort_by { |k, _v| k.to_s }
86
90
  end
87
91
 
88
92
  def sparse(hash, options = {})
89
93
  hash.map do |k, v|
90
- prefix = (options.fetch(:prefix, [])+[k])
91
- next Sparsify::sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash
94
+ prefix = (options.fetch(:prefix, []) + [k])
95
+ next Sparsify.sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash
92
96
  { prefix.join(options.fetch(:separator, FactName::SEPARATOR)) => v }
93
- end.reduce(:merge) || Hash.new
97
+ end.reduce(:merge) || {}
94
98
  end
95
99
 
96
100
  def unsparse(hash, options = {})
97
- ret = Hash.new
101
+ ret = {}
98
102
  sparse(hash).each do |k, v|
99
103
  current = ret
100
104
  key = k.to_s.split(options.fetch(:separator, FactName::SEPARATOR))
101
- current = (current[key.shift] ||= Hash.new) until (key.size<=1)
105
+ current = (current[key.shift] ||= Hash.new) until (key.size <= 1)
102
106
  current[key.first] = v
103
107
  end
104
108
  ret
105
109
  end
106
110
  end
107
111
  end
108
-
@@ -0,0 +1,100 @@
1
+ module ForemanSalt
2
+ class FactParser < ::FactParser
3
+ attr_reader :facts
4
+
5
+ def operatingsystem
6
+ os = Operatingsystem.where(os_hash).first_or_initialize
7
+ if os.new_record?
8
+ os.deduce_family
9
+ os.release_name = facts[:lsb_distrib_codename]
10
+ os.save
11
+ end
12
+ os if os.persisted?
13
+ end
14
+
15
+ def architecture
16
+ name = facts[:osarch]
17
+ name = 'x86_64' if name == 'amd64'
18
+ Architecture.find_or_create_by_name name unless name.blank?
19
+ end
20
+
21
+ def environment
22
+ # Don't touch the Puppet environment field
23
+ end
24
+
25
+ def model
26
+ name = facts[:productname]
27
+ Model.find_or_create_by_name(name.strip) unless name.blank?
28
+ end
29
+
30
+ def domain
31
+ name = facts[:domain]
32
+ Domain.find_or_create_by_name name unless name.blank?
33
+ end
34
+
35
+ def ip
36
+ ip = facts.find { |fact, value| fact =~ /^fqdn_ip4/ && value && value != '127.0.0.1' }
37
+ ip[1] if ip
38
+ end
39
+
40
+ def primary_interface
41
+ interface = interfaces.find { |_, value| value[:ipaddress] == ip }
42
+ interface[0] if interface
43
+ end
44
+
45
+ def mac
46
+ interface = interfaces.find { |_, value| value[:ipaddress] == ip }
47
+ interface[1][:macaddress] if interface
48
+ end
49
+
50
+ def ipmi_interface
51
+ nil
52
+ end
53
+
54
+ def interfaces
55
+ interfaces = {}
56
+
57
+ facts.each do |fact, value|
58
+ next unless value && fact.to_s =~ /^ip_interfaces/
59
+ (_, interface, number) = fact.split(FactName::SEPARATOR)
60
+
61
+ interface_name = if number == '0' || number.nil?
62
+ interface
63
+ else
64
+ "#{interface}.#{number}"
65
+ end
66
+
67
+ if !interface.blank? && interface != 'lo'
68
+ interfaces[interface_name] = {} if interfaces[interface_name].blank?
69
+ interfaces[interface_name].merge!(:ipaddress => value, :macaddress => macs[interface])
70
+ end
71
+ end
72
+
73
+ interfaces
74
+ end
75
+
76
+ def support_interfaces_parsing?
77
+ true
78
+ end
79
+
80
+ private
81
+
82
+ def os_hash
83
+ (_, major, minor) = /(\d+)\.?(\d+)?\.?(\d+)?/.match(facts[:osrelease]).to_a
84
+ { :name => facts[:os], :major => major, :minor => minor }
85
+ end
86
+
87
+ def macs
88
+ unless @macs
89
+ @macs = {}
90
+ facts.each do |fact, value|
91
+ next unless value && fact.to_s =~ /^hwaddr_interfaces/
92
+ data = fact.split(FactName::SEPARATOR)
93
+ interface = data[1]
94
+ macs[interface] = value
95
+ end
96
+ end
97
+ @macs
98
+ end
99
+ end
100
+ end
@@ -106,34 +106,37 @@ module ForemanSalt
106
106
  end
107
107
  end
108
108
 
109
- time[resource] = result['duration'] if result['duration']
109
+ time[resource] = if result['duration'].is_a? String
110
+ Float(result['duration'].delete(' ms')) rescue nil
111
+ else
112
+ result['duration']
113
+ end
110
114
  end
111
115
 
112
116
  time[:total] = time.values.inject(&:+)
113
- events = {:total => changed + failed + restarted + restarted_failed, :success => success + restarted, :failure => failed + restarted_failed}
117
+ events = { :total => changed + failed + restarted + restarted_failed, :success => success + restarted, :failure => failed + restarted_failed }
114
118
 
115
- changes = {:total => changed + restarted}
119
+ changes = { :total => changed + restarted }
116
120
 
117
- resources = {'total' => @raw.size, 'applied' => changed, 'restarted' => restarted, 'failed' => failed,
118
- 'failed_restarts' => restarted_failed, 'skipped' => 0, 'scheduled' => 0}
121
+ resources = { 'total' => @raw.size, 'applied' => changed, 'restarted' => restarted, 'failed' => failed,
122
+ 'failed_restarts' => restarted_failed, 'skipped' => 0, 'scheduled' => 0 }
119
123
 
120
- {:events => events, :resources => resources, :changes => changes, :time => time}
124
+ { :events => events, :resources => resources, :changes => changes, :time => time }
121
125
  end
122
126
 
123
127
  def process_normal
124
- metrics = calculate_metrics
125
- status = ReportStatusCalculator.new(:counters => metrics[:resources].slice(*::Report::METRIC)).calculate
128
+ metrics = calculate_metrics
129
+ status = ReportStatusCalculator.new(:counters => metrics[:resources].slice(*::Report::METRIC)).calculate
126
130
 
127
- @host.puppet_status = status
131
+ @host.puppet_status = status
128
132
 
129
- @report = Report.new(:host => @host, :reported_at => start_time, :status => status, :metrics => metrics)
130
- return @report unless @report.save
131
- import_log_messages
133
+ @report = Report.new(:host => @host, :reported_at => start_time, :status => status, :metrics => metrics)
134
+ return @report unless @report.save
135
+ import_log_messages
132
136
  end
133
137
 
134
-
135
138
  def process_failures
136
- status = ReportStatusCalculator.new({:counters => {'failed' => @raw.size}}).calculate
139
+ status = ReportStatusCalculator.new(:counters => { 'failed' => @raw.size }).calculate
137
140
  @report = Report.create(:host => @host, :reported_at => Time.now, :status => status, :metrics => {})
138
141
 
139
142
  @host.puppet_status = status
@@ -1,56 +1,53 @@
1
1
  module ForemanSalt
2
2
  class SmartProxies::SaltKeys
3
-
4
3
  attr_reader :name, :state, :fingerprint, :smart_proxy_id
5
4
 
6
- def initialize(opts)
7
- @name, @state, @fingerprint, @smart_proxy_id = opts.flatten
8
- end
9
-
10
- class << self
5
+ def initialize(opts)
6
+ @name, @state, @fingerprint, @smart_proxy_id = opts.flatten
7
+ end
11
8
 
12
- def all(proxy)
13
- raise ::Foreman::Exception.new(N_('Must specify a Smart Proxy to use')) if proxy.nil?
9
+ class << self
10
+ def all(proxy)
11
+ raise ::Foreman::Exception.new(N_('Must specify a Smart Proxy to use')) if proxy.nil?
14
12
 
15
- unless (keys = Rails.cache.read("saltkeys_#{proxy.id}"))
16
- api = ProxyAPI::Salt.new({:url => proxy.url})
17
- keys = api.key_list.map do |name, properties|
18
- new([name.strip, properties['state'], properties['fingerprint'], proxy.id])
19
- end.compact
13
+ unless (keys = Rails.cache.read("saltkeys_#{proxy.id}"))
14
+ api = ProxyAPI::Salt.new(:url => proxy.url)
15
+ keys = api.key_list.map do |name, properties|
16
+ new([name.strip, properties['state'], properties['fingerprint'], proxy.id])
17
+ end.compact
20
18
 
21
- Rails.cache.write("saltkeys_#{proxy.id}", keys, {:expires_in => 1.minute }) if Rails.env.production?
22
- end
23
- keys
24
- end
19
+ Rails.cache.write("saltkeys_#{proxy.id}", keys, :expires_in => 1.minute) if Rails.env.production?
20
+ end
21
+ keys
22
+ end
25
23
 
26
- def find(proxy, name)
27
- all(proxy).select{|c| c.name == name}.first
28
- end
24
+ def find(proxy, name)
25
+ all(proxy).select { |c| c.name == name }.first
26
+ end
29
27
 
30
- def find_by_state(proxy, state)
31
- all(proxy).select{|c| c.state == state}
32
- end
33
- end
28
+ def find_by_state(proxy, state)
29
+ all(proxy).select { |c| c.state == state }
30
+ end
31
+ end
34
32
 
35
33
  def accept
36
34
  raise ::Foreman::Exception.new(N_('unable to re-accept an accepted key')) unless state == 'unaccepted'
37
35
  proxy = SmartProxy.find(smart_proxy_id)
38
36
  Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production?
39
- ProxyAPI::Salt.new({:url => proxy.url}).key_accept name
37
+ ProxyAPI::Salt.new(:url => proxy.url).key_accept name
40
38
  end
41
39
 
42
40
  def reject
43
41
  raise ::Foreman::Exception.new(N_('unable to reject an accepted key')) unless state == 'unaccepted'
44
42
  proxy = SmartProxy.find(smart_proxy_id)
45
43
  Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production?
46
- ProxyAPI::Salt.new({:url => proxy.url}).key_reject name
44
+ ProxyAPI::Salt.new(:url => proxy.url).key_reject name
47
45
  end
48
46
 
49
-
50
47
  def delete
51
48
  proxy = SmartProxy.find(smart_proxy_id)
52
49
  Rails.cache.delete("saltkeys_#{proxy.id}") if Rails.env.production?
53
- ProxyAPI::Salt.new({:url => proxy.url}).key_delete name
50
+ ProxyAPI::Salt.new(:url => proxy.url).key_delete name
54
51
  end
55
52
 
56
53
  def to_param
@@ -62,7 +59,7 @@ module ForemanSalt
62
59
  end
63
60
 
64
61
  def <=>(other)
65
- self.name <=> other.name
62
+ name <=> other.name
66
63
  end
67
64
  end
68
65
  end
@@ -0,0 +1,3 @@
1
+ object @salt_autosign
2
+
3
+ attributes :record
@@ -0,0 +1,3 @@
1
+ object @salt_autosign
2
+
3
+ extends "foreman_salt/api/v2/salt_autosign/main"
@@ -0,0 +1,3 @@
1
+ collection @salt_autosigns
2
+
3
+ extends 'foreman_salt/api/v2/salt_autosign/main'
@@ -0,0 +1,3 @@
1
+ object @salt_autosign
2
+
3
+ extends 'foreman_salt/api/v2/salt_autosign/base'
@@ -0,0 +1,3 @@
1
+ object @salt_environment
2
+
3
+ attributes :id, :name
@@ -0,0 +1,3 @@
1
+ object @salt_environment
2
+
3
+ extends "foreman_salt/api/v2/salt_environments/main"
@@ -0,0 +1,3 @@
1
+ collection @salt_environments
2
+
3
+ extends 'foreman_salt/api/v2/salt_environments/main'
@@ -0,0 +1,3 @@
1
+ object @salt_environment
2
+
3
+ extends 'foreman_salt/api/v2/salt_environments/base'
@@ -0,0 +1,3 @@
1
+ object @salt_environment
2
+
3
+ extends "foreman_salt/api/v2/salt_environments/base"
@@ -0,0 +1,3 @@
1
+ object @salt_key
2
+
3
+ attributes :name, :state, :fingerprint
@@ -0,0 +1,3 @@
1
+ collection @salt_keys
2
+
3
+ extends 'foreman_salt/api/v2/salt_keys/main'
@@ -0,0 +1,3 @@
1
+ object @salt_key
2
+
3
+ extends 'foreman_salt/api/v2/salt_keys/base'
@@ -0,0 +1,3 @@
1
+ object @salt_key
2
+
3
+ extends "foreman_salt/api/v2/salt_keys/main"
@@ -0,0 +1,3 @@
1
+ object @salt_minion
2
+
3
+ attributes :id, :name, :salt_environment_id, :salt_environment_name, :salt_proxy_name, :salt_proxy_id
@@ -0,0 +1,3 @@
1
+ collection @salt_minions
2
+
3
+ extends 'foreman_salt/api/v2/salt_minions/base'
@@ -0,0 +1,3 @@
1
+ object @salt_minion
2
+
3
+ extends 'foreman_salt/api/v2/salt_minions/base'
@@ -0,0 +1,8 @@
1
+ object @salt_minion
2
+
3
+ extends "foreman_salt/api/v2/salt_minions/main"
4
+
5
+ child :salt_modules => :salt_states do
6
+ extends "foreman_salt/api/v2/salt_states/base"
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ object @salt_state
2
+
3
+ attributes :id, :name
@@ -0,0 +1,3 @@
1
+ object @salt_state
2
+
3
+ extends "foreman_salt/api/v2/salt_states/main"
@@ -0,0 +1,3 @@
1
+ collection @salt_states
2
+
3
+ extends 'foreman_salt/api/v2/salt_states/main'
@@ -0,0 +1,3 @@
1
+ object @salt_state
2
+
3
+ extends 'foreman_salt/api/v2/salt_states/base'
@@ -0,0 +1,3 @@
1
+ object @salt_state
2
+
3
+ extends "foreman_salt/api/v2/salt_states/base"
data/config/routes.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  Rails.application.routes.draw do
2
-
3
2
  scope :salt, :path => '/salt' do
4
- match '/node/:name' => 'hosts#salt_external_node', :constraints => { :name => /[^\.][\w\.-]+/ }
3
+ constraints(:id => /[\w\.-]+/) do
4
+ match '/node/:id' => 'foreman_salt/minions#node'
5
+ match '/run/:id' => 'foreman_salt/minions#run'
6
+ end
5
7
 
6
8
  resources :salt_environments, :controller => 'foreman_salt/salt_environments' do
7
9
  collection do
@@ -15,8 +17,27 @@ Rails.application.routes.draw do
15
17
  end
16
18
  end
17
19
 
18
- scope :api, :defaults => {:format => 'json'}, :constraints => ApiConstraints.new(:version => 2) do
19
- match 'api/v2/jobs/upload' => 'foreman_salt/api/v2/jobs#upload', :via => :post
20
+ scope :api, :path => '/api', :defaults => { :format => 'json' } do
21
+ scope '(:apiv)', :defaults => { :apiv => 'v2' },
22
+ :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2) do
23
+ match '/jobs/upload' => 'foreman_salt/api/v2/jobs#upload', :via => :post
24
+
25
+ constraints(:smart_proxy_id => /[\w\.-]+/, :name => /[\w\.-]+/, :record => /[^\/]+/) do
26
+ match '/salt_keys/:smart_proxy_id' => 'foreman_salt/api/v2/salt_keys#index', :via => :get
27
+ match '/salt_keys/:smart_proxy_id/:name' => 'foreman_salt/api/v2/salt_keys#update', :via => :put
28
+ match '/salt_keys/:smart_proxy_id/:name' => 'foreman_salt/api/v2/salt_keys#destroy', :via => :delete
29
+
30
+ match '/salt_autosign/:smart_proxy_id' => 'foreman_salt/api/v2/salt_autosign#index', :via => :get
31
+ match '/salt_autosign/:smart_proxy_id' => 'foreman_salt/api/v2/salt_autosign#create', :via => :post
32
+ match '/salt_autosign/:smart_proxy_id/:record' => 'foreman_salt/api/v2/salt_autosign#destroy', :via => :delete
33
+ end
34
+
35
+ constraints(:id => /[\w\.-]+/) do
36
+ resources :salt_environments, :only => [:show, :index, :create, :destroy], :controller => 'foreman_salt/api/v2/salt_environments'
37
+ resources :salt_minions, :only => [:show, :index, :update], :controller => 'foreman_salt/api/v2/salt_minions'
38
+ resources :salt_states, :only => [:show, :index, :create, :destroy], :controller => 'foreman_salt/api/v2/salt_states'
39
+ end
40
+ end
20
41
  end
21
42
  end
22
43
 
@@ -31,12 +52,4 @@ Rails.application.routes.draw do
31
52
  end
32
53
  end
33
54
  end
34
-
35
- constraints(:id => /[^\/]+/) do
36
- resources :hosts do
37
- member do
38
- get :saltrun
39
- end
40
- end
41
- end
42
55
  end
@@ -8,5 +8,4 @@ class AddSaltProxyToHostAndHostGroup < ActiveRecord::Migration
8
8
  remove_column :hosts, :salt_proxy_id
9
9
  remove_column :hostgroups, :salt_proxy_id
10
10
  end
11
-
12
11
  end