foreman_salt 10.0.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6a5c38ada1b7092ea56ff7da05ebdfd13bff174ddd00b04d61813ea3f18b367
4
- data.tar.gz: c559363f1e3a18b955b3707dc410cb094e6b4e4556ca99c4ae059c7cad09adb1
3
+ metadata.gz: a0d07824ea3e38fef2e9e0e6d29013dddc9e09d201144c0f2513e6afe482f8bb
4
+ data.tar.gz: a6bb3c8d79328b30ed8c0191274e71034c3f78140bd278d89679872e60373407
5
5
  SHA512:
6
- metadata.gz: 240c3e9a0d46d6cf4ddebe976129af37917a108d55be3aeb434262a9cddd824b06e0266f41cc528703acef7e0f6c4ea7db013fa9c5262de6004ed1820c0927f3
7
- data.tar.gz: 9eeb42cebc16d142a157c12e11da6121974516cd022e0efcdef841dc94d30b740f532ab730e491c0bb7e7eb6fb1b3dc366ecffcad749732c574d0d1d896c82d9
6
+ metadata.gz: 4f134063a3d744cdc69944c72de6cfb480758cd335b17448a207a818219f3426370500493fed8c449649631c7d54416d915c012730f021b0db5e271edfea81fc
7
+ data.tar.gz: a576753c9fe866c74c360214f3b8ef235144c596cde0df4bc6702d5cae2da2b3f8fd3307e524527a107c470a8ad2549a13efe92a2f0ce160615dc693c89544d0
data/README.md CHANGED
@@ -7,6 +7,13 @@
7
7
 
8
8
  This plug-in adds support for Salt to Foreman.
9
9
 
10
+ # Compatibility
11
+
12
+ | Foreman Version | Plugin Version |
13
+ | --------------- | --------------:|
14
+ | <= 1.16 | 10.0.0 |
15
+ | >= 1.17 | 10.1.0 |
16
+
10
17
  ## Documentation
11
18
 
12
19
  See the [Foreman Salt manuals](http://theforeman.org/plugins/foreman_salt/) on the Foreman web site.
@@ -19,6 +19,7 @@ module ForemanSalt
19
19
  param_group :job, :as => :upload
20
20
 
21
21
  def upload
22
+ params[:job].permit!
22
23
  Rails.logger.info("Processing job #{params[:job][:job_id]} from Salt.")
23
24
  case params[:job][:function]
24
25
  when 'state.highstate'
@@ -1,5 +1,5 @@
1
1
  module ForemanSalt
2
- class FactImporter < ::FactImporter
2
+ class FactImporter < ::StructuredFactImporter
3
3
  def fact_name_class
4
4
  ForemanSalt::FactName
5
5
  end
@@ -11,101 +11,5 @@ module ForemanSalt
11
11
  def self.authorized_smart_proxy_features
12
12
  'Salt'
13
13
  end
14
-
15
- private
16
-
17
- attr_accessor :original_facts
18
-
19
- def add_new_facts
20
- @counters[:added] = 0
21
- add_missing_facts(unsparse(original_facts))
22
- logger.debug("Merging facts for '#{host}': added #{@counters[:added]} facts")
23
- end
24
-
25
- def add_missing_facts(tree_hash, parent = nil, prefix = '')
26
- tree_hash.each do |name, value|
27
- name_with_prefix = prefix.empty? ? name : prefix + FactName::SEPARATOR + name
28
-
29
- compose = value.is_a?(Hash)
30
- if fact_names.is_a?(Hash) && fact_names[name_with_prefix].present?
31
- fact_name_id = fact_names[name_with_prefix]
32
- else
33
- fact_name_id = fact_name_class.create!(:name => name_with_prefix,
34
- :parent_id => parent,
35
- :compose => compose).id
36
- end
37
-
38
- if compose
39
- add_fact(name_with_prefix, nil, fact_name_id)
40
- add_missing_facts(value, fact_name_id, name_with_prefix)
41
- else
42
- add_fact(name_with_prefix, value, fact_name_id)
43
- end
44
- end
45
- end
46
-
47
- def add_fact(name, value, fact_name_id)
48
- if facts_to_create.include?(name)
49
- host.fact_values.send(method,
50
- :value => value, :fact_name_id => fact_name_id)
51
- @counters[:added] += 1
52
- end
53
- end
54
-
55
- def facts_to_create
56
- @facts_to_create ||= facts.keys - db_facts.pluck('fact_names.name')
57
- end
58
-
59
- def fact_names
60
- @fact_names ||= fact_name_class.group(:name).maximum(:id)
61
- end
62
-
63
- # if the host does not exists yet, we don't have an host_id to use the fact_values table.
64
- def method
65
- @method ||= host.new_record? ? :build : :create!
66
- end
67
-
68
- def normalize(facts)
69
- @original_facts = super(facts)
70
- @facts = completify(@original_facts)
71
- end
72
-
73
- def completify(hash)
74
- new_facts = hash.dup
75
- hash.each do |fact_name, value|
76
- name_parts = fact_name.split(FactName::SEPARATOR)
77
-
78
- name_parts.inject([]) do |memo, name|
79
- memo += [name]
80
- key = memo.join(FactName::SEPARATOR)
81
- new_facts[key] ||= name_parts == memo ? value : nil
82
- memo
83
- end
84
- end
85
- new_facts
86
- end
87
-
88
- def sort_by_key(hash)
89
- hash.sort_by { |k, _v| k.to_s }
90
- end
91
-
92
- def sparse(hash, options = {})
93
- hash.map do |k, v|
94
- prefix = (options.fetch(:prefix, []) + [k])
95
- next Sparsify.sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash
96
- { prefix.join(options.fetch(:separator, FactName::SEPARATOR)) => v }
97
- end.reduce(:merge) || {}
98
- end
99
-
100
- def unsparse(hash, options = {})
101
- ret = {}
102
- sparse(hash).each do |k, v|
103
- current = ret
104
- key = k.to_s.split(options.fetch(:separator, FactName::SEPARATOR))
105
- current = (current[key.shift] ||= {}) until (key.size <= 1)
106
- current[key.first] = v
107
- end
108
- ret
109
- end
110
14
  end
111
15
  end
@@ -56,20 +56,26 @@ module ForemanSalt
56
56
 
57
57
  facts.each do |fact, value|
58
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])
59
+ (_, interface_name, _) = fact.split(FactName::SEPARATOR)
60
+
61
+ next if (IPAddr.new('fe80::/10').include?(value) rescue false)
62
+
63
+ if !interface_name.blank? && interface_name != 'lo'
64
+ interface = interfaces.fetch(interface_name, {})
65
+ interface[:macaddress] = macs[interface_name]
66
+ if Net::Validations::validate_ip6(value)
67
+ interface[:ipaddress6] = value
68
+ else
69
+ interface[:ipaddress] = value
70
+ end
71
+ interfaces[interface_name] = interface
70
72
  end
71
73
  end
72
74
 
75
+ interfaces.each do |name, interface|
76
+ set_additional_attributes(interface, name)
77
+ end
78
+
73
79
  interfaces
74
80
  end
75
81
 
@@ -85,7 +91,7 @@ module ForemanSalt
85
91
  if name == 'CentOS'
86
92
  if sub
87
93
  minor += '.' + sub
88
- end
94
+ end
89
95
  end
90
96
  { :name => name, :major => major, :minor => minor }
91
97
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '10.0.0'
2
+ VERSION = '10.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Benjamin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-06 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -163,7 +163,7 @@ files:
163
163
  - test/unit/report_importer_test.rb
164
164
  - test/unit/salt_keys_test.rb
165
165
  - test/unit/salt_modules_test.rb
166
- homepage: http://github.com/theforeman/foreman_salt
166
+ homepage: https://github.com/theforeman/foreman_salt
167
167
  licenses:
168
168
  - GPL-3.0
169
169
  metadata: {}
@@ -183,27 +183,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.7.6
186
+ rubygems_version: 2.7.7
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: Foreman Plug-in for Salt
190
190
  test_files:
191
- - test/factories/foreman_salt_factories.rb
191
+ - test/integration/salt_environment_test.rb
192
+ - test/integration/salt_autosign_test.rb
193
+ - test/integration/salt_keys_test.rb
194
+ - test/integration/salt_module_test.rb
195
+ - test/functional/minions_controller_test.rb
192
196
  - test/functional/api/v2/salt_autosign_controller_test.rb
193
197
  - test/functional/api/v2/salt_environments_controller_test.rb
194
198
  - test/functional/api/v2/salt_keys_controller_test.rb
195
199
  - test/functional/api/v2/salt_states_controller_test.rb
196
- - test/functional/minions_controller_test.rb
197
- - test/integration/salt_autosign_test.rb
198
- - test/integration/salt_environment_test.rb
199
- - test/integration/salt_keys_test.rb
200
- - test/integration/salt_module_test.rb
200
+ - test/test_plugin_helper.rb
201
+ - test/factories/foreman_salt_factories.rb
202
+ - test/unit/host_extensions_test.rb
203
+ - test/unit/report_importer_test.rb
201
204
  - test/unit/grains_centos.json
202
205
  - test/unit/highstate.json
203
- - test/unit/salt_keys_test.rb
204
206
  - test/unit/salt_modules_test.rb
205
- - test/unit/grains_importer_test.rb
206
- - test/unit/host_extensions_test.rb
207
207
  - test/unit/hostgroup_extensions_test.rb
208
- - test/unit/report_importer_test.rb
209
- - test/test_plugin_helper.rb
208
+ - test/unit/salt_keys_test.rb
209
+ - test/unit/grains_importer_test.rb