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:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a0d07824ea3e38fef2e9e0e6d29013dddc9e09d201144c0f2513e6afe482f8bb
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a6bb3c8d79328b30ed8c0191274e71034c3f78140bd278d89679872e60373407
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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.
         
     | 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ForemanSalt
         
     | 
| 
       2 
     | 
    
         
            -
              class 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 
     | 
    
         
            -
                    (_,  
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                     
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                       
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 94 
     | 
    
         
            +
                    end
         
     | 
| 
       89 
95 
     | 
    
         
             
                  end
         
     | 
| 
       90 
96 
     | 
    
         
             
                  { :name => name, :major => major, :minor => minor }
         
     | 
| 
       91 
97 
     | 
    
         
             
                end
         
     | 
    
        data/lib/foreman_salt/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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:  
     | 
| 
      
 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. 
     | 
| 
      
 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/ 
     | 
| 
      
 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/ 
     | 
| 
       197 
     | 
    
         
            -
            - test/ 
     | 
| 
       198 
     | 
    
         
            -
            - test/ 
     | 
| 
       199 
     | 
    
         
            -
            - test/ 
     | 
| 
       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/ 
     | 
| 
       209 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 208 
     | 
    
         
            +
            - test/unit/salt_keys_test.rb
         
     | 
| 
      
 209 
     | 
    
         
            +
            - test/unit/grains_importer_test.rb
         
     |