foreman_chef 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 86ad6b2ae0637ad38d20096b96e2019571999bd3
4
- data.tar.gz: 9701a8976c16c4ccf4612512d79e6bd11620d4e4
2
+ SHA256:
3
+ metadata.gz: 3fedb5a89f5be407411bf40c5ce91252c61051bece15e3f3b4388fb794672ade
4
+ data.tar.gz: c9b41183e4474675c612ccb79e3cb94e207c1ecb3f14afd3150dc14853688ee8
5
5
  SHA512:
6
- metadata.gz: 269e56756c4ccb0be46a9809849dc7db1fe579bc5cfd8c3a1ebfe778085462b7fc7ae4685f662d8ad9f9490c5c58128577c0378c800d64c8106e412b2ab2adaf
7
- data.tar.gz: 294d12364166c3ff5257f0c93faf72f72dd4848682502b364e280908e54f1ff1bca6cc6cbaff66343f443f1a4c5df4b287dfbb86f0917a6ad7b2d60038418d36
6
+ metadata.gz: 73aa559fd56934944e8eafc4827337d4e25e26d6fd9a1201f5d21b063a8ab963bf3cdedc0144f1ae952d8967857d9181021be22f571ff68b661c9ab05129a3fd
7
+ data.tar.gz: 33b4941d7907d7c460b9646f1b9e7e74f5368e155ac77c0f3c222bf29c6f4710001aa0f46ae73192e3a72ac06045d849f5b190b35af347ba942f34a7bb34c2b2
@@ -0,0 +1,24 @@
1
+ module ForemanChef
2
+ module Concerns
3
+ module HostsControllerExtensions
4
+ extend ActiveSupport::Concern
5
+ include ForemanTasks::Triggers
6
+
7
+ module Overrides
8
+ def destroy
9
+ super
10
+ ::ForemanTasks.sync_task ::Actions::ForemanChef::Host::Destroy, @host
11
+ end
12
+
13
+ def update
14
+ super
15
+ ::ForemanTasks.sync_task ::Actions::ForemanChef::Host::Update, @host
16
+ end
17
+ end
18
+
19
+ included do
20
+ prepend Overrides
21
+ end
22
+ end
23
+ end
24
+ end
@@ -12,19 +12,18 @@ module ForemanChef
12
12
  @importer = ChefServerImporter.new(opts)
13
13
  @changed = @importer.changes
14
14
  if @changed.values.all?(&:empty?)
15
- notice _("Nothing to synchronize")
16
- redirect_to foreman_chef_environments_path
15
+ process_success :success_redirect => foreman_chef_environments_path, :success_msg => _("Nothing to synchronize")
17
16
  end
18
17
  end
19
18
 
20
19
  def synchronize
21
20
  proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
22
21
  if (errors = ChefServerImporter.new(:chef_proxy => proxy).obsolete_and_new(params[:changed])).empty?
23
- notice _("Successfully updated environments")
22
+ process_success :success_redirect => foreman_chef_environments_path, :success_msg => _("Successfully updated environments")
24
23
  else
25
- error _("Failed to update environments: %s") % errors.to_sentence
24
+ process_error :redirect => foreman_chef_environments_path, :error_msg => _("Failed to update environments: %s") % errors.to_sentence
26
25
  end
27
- redirect_to foreman_chef_environments_path
26
+
28
27
  end
29
28
 
30
29
  def index
@@ -0,0 +1,7 @@
1
+ module ForemanChef
2
+ module ChefReportsHelper
3
+ def chef_report_origin_icon
4
+ 'foreman_chef/Chef.png'
5
+ end
6
+ end
7
+ end
@@ -26,7 +26,7 @@ module Actions
26
26
  end
27
27
 
28
28
  def humanized_input
29
- input[:host][:name]
29
+ input.try(:[], :host).try(:[], :name) || 'with unknown name'
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,20 @@
1
+ module ForemanChef
2
+ # Scans ConfigReports after import for indicators of an Ansible report and
3
+ # sets the origin of the report to 'Ansible'
4
+ class ChefReportScanner
5
+ class << self
6
+ def scan(report, logs)
7
+ if (result = chef_report?(logs))
8
+ report.origin = 'Chef'
9
+ end
10
+
11
+ result
12
+ end
13
+
14
+ def chef_report?(logs)
15
+ return false if logs.blank?
16
+ logs.last['log']['sources']['source'] == 'Chef'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -63,6 +63,10 @@ module ForemanChef
63
63
  super.concat(%w(chef_proxy_id chef_environment_id))
64
64
  end
65
65
 
66
+ def action_input_key
67
+ "host"
68
+ end
69
+
66
70
  private
67
71
 
68
72
  def load_node_data
@@ -73,5 +77,5 @@ module ForemanChef
73
77
  end
74
78
 
75
79
  class ::Host::Managed::Jail < Safemode::Jail
76
- allow :run_list
80
+ allow :run_list, :chef_proxy, :chef_environment, :chef_private_key
77
81
  end
@@ -16,93 +16,6 @@ module ForemanChef
16
16
 
17
17
  private
18
18
 
19
- attr_accessor :original_facts
20
-
21
- def logger
22
- Foreman::Logging.logger('foreman_chef')
23
- end
24
-
25
- def add_new_facts
26
- @counters[:added] = 0
27
- add_missing_facts(Sparser.new.unsparse(original_facts))
28
- logger.debug("Merging facts for '#{host}': added #{@counters[:added]} facts")
29
- end
30
-
31
- def add_missing_facts(tree_hash, parent = nil, prefix = '')
32
- tree_hash.each do |name, value|
33
- name_with_prefix = prefix.empty? ? name : prefix + FactName::SEPARATOR + name
34
-
35
- compose = value.is_a?(Hash)
36
- if fact_names[name_with_prefix].present?
37
- fact_name_id = fact_names[name_with_prefix]
38
- else
39
- # fact names didn't contain fact_name so we create new one
40
- fact_name = fact_name_class.new(:name => name_with_prefix,
41
- :parent_id => parent,
42
- :compose => compose)
43
- if fact_name.save
44
- fact_name_id = fact_name.id
45
- elsif fact_name.errors[:name].present?
46
- # saving could have failed because of raise condition with another import process,
47
- # so if the error is on name uniqueness, we try to reload conflicting name and use it
48
- conflicting_fact_name = fact_name_class.where(:name => fact_name.name).first
49
- fact_name_id = conflicting_fact_name.id
50
- else
51
- raise FactNameImportError, "unable to save fact name, errors: #{fact_name.errors.full_messages.join("\n")}"
52
- end
53
- fact_name_id
54
- end
55
-
56
- if compose
57
- add_fact(name_with_prefix, nil, fact_name_id)
58
- add_missing_facts(value, fact_name_id, name_with_prefix)
59
- else
60
- add_fact(name_with_prefix, value, fact_name_id)
61
- end
62
- end
63
- end
64
-
65
- def add_fact(name, value, fact_name_id)
66
- if facts_to_create.include?(name)
67
- host.fact_values.send(method,
68
- :value => value, :fact_name_id => fact_name_id)
69
- @counters[:added] += 1
70
- end
71
- end
72
-
73
- def facts_to_create
74
- @facts_to_create ||= facts.keys - db_facts.pluck('fact_names.name')
75
- end
76
-
77
- def fact_names
78
- @fact_names ||= fact_name_class.group(:name).maximum(:id)
79
- end
80
-
81
- # if the host does not exists yet, we don't have an host_id to use the fact_values table.
82
- def method
83
- @method ||= host.new_record? ? :build : :create!
84
- end
85
-
86
- def normalize(facts)
87
- @original_facts = super(facts)
88
- @facts = completify(@original_facts)
89
- end
90
-
91
- def completify(hash)
92
- new_facts = hash.dup
93
- hash.each do |fact_name, value|
94
- name_parts = fact_name.split(FactName::SEPARATOR)
95
-
96
- name_parts.inject([]) do |memo, name|
97
- memo = memo + [name]
98
- key = memo.join(FactName::SEPARATOR)
99
- new_facts[key] ||= name_parts == memo ? value : nil
100
- memo
101
- end
102
- end
103
- new_facts
104
- end
105
-
106
19
  class Sparser
107
20
  def sparse(hash, options={})
108
21
  hash.map do |k, v|
@@ -1,6 +1,10 @@
1
1
  module ForemanChef
2
2
  class FactName < ::FactName
3
3
  def origin
4
+ 'Chef'
5
+ end
6
+
7
+ def icon_path
4
8
  'foreman_chef/Chef'
5
9
  end
6
10
  end
@@ -22,6 +22,13 @@ module ForemanChef
22
22
  release_name = facts['lsb::codename']
23
23
  end
24
24
 
25
+ # convert OHAI names to Foreman common OS names
26
+ case os_name
27
+ when 'RedHatEnterpriseServer'
28
+ os_name = 'RedHat'
29
+ end
30
+
31
+
25
32
  # So far only CentOS needs exception
26
33
  case os_name
27
34
  when 'CentOS'
@@ -85,6 +92,10 @@ module ForemanChef
85
92
  support_interfaces_parsing? && !Setting['ignore_puppet_facts_for_provisioning']
86
93
  end
87
94
 
95
+ def boot_timestamp
96
+ Time.zone.now.to_i - facts['system_uptime::seconds'].to_i
97
+ end
98
+
88
99
  private
89
100
 
90
101
  def logger
@@ -122,11 +133,11 @@ module ForemanChef
122
133
  end
123
134
 
124
135
  def network_hash
125
- @network_hash ||= ForemanChef::FactImporter::Sparser.new.unsparse(facts.select { |k, v| k =~ /\Anetwork::interfaces::/})['network']
136
+ @network_hash ||= ForemanChef::FactImporter::Sparser.new.unsparse(facts.select { |k, v| k =~ /\Anetwork::interfaces::/}).try(:[], 'network') || {}
126
137
  end
127
138
 
128
139
  def interfaces_hash
129
- @interfaces_hash ||= network_hash['interfaces']
140
+ @interfaces_hash ||= network_hash.try(:[], 'interfaces') || {}
130
141
  end
131
142
 
132
143
  # adds attributes like virtual
@@ -6,6 +6,7 @@ class Setting::ForemanChef < Setting
6
6
 
7
7
  self.transaction do
8
8
  [
9
+ self.set('chef_interval', N_("Duration in minutes after servers reporting via Chef are classed as out of sync."), 60),
9
10
  self.set('auto_deletion', N_("Enable the auto deletion of mapped objects in chef-server through foreman-proxy (currently node and client upon host deletion, client on host rebuild)"), true),
10
11
  self.set('validation_bootstrap_method', N_("Use validation.pem or create client directly storing private key in Foreman DB)"), true),
11
12
  ].each { |s| self.create! s.update(:category => "Setting::ForemanChef")}
@@ -13,7 +13,7 @@ module ForemanChef
13
13
  end
14
14
  end
15
15
 
16
- config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
16
+ config.autoload_paths += Dir["#{config.root}/app/helpers"]
17
17
 
18
18
  # Precompile any JS or CSS files under app/assets/
19
19
  # If requiring files from each other, list them explicitly here to avoid precompiling the same
@@ -47,7 +47,7 @@ module ForemanChef
47
47
 
48
48
  initializer 'foreman_chef.register_plugin', :before => :finisher_hook do |app|
49
49
  Foreman::Plugin.register :foreman_chef do
50
- requires_foreman '>= 1.17'
50
+ requires_foreman '>= 1.24'
51
51
  extend_template_helpers ForemanChef::Concerns::Renderer
52
52
 
53
53
  permission :import_chef_environments, { :environments => [:import, :synchronize] }, :resource_type => 'ForemanChef::Environment'
@@ -69,6 +69,9 @@ module ForemanChef
69
69
  if ForemanChef.with_remote_execution? && Gem::Version.new(ForemanRemoteExecution::VERSION) >= Gem::Version.new('1.2.3')
70
70
  RemoteExecutionFeature.register(:foreman_chef_run_chef_client, N_("Run chef-client Once"), :description => N_("Run chef-client once"), :host_action_button => true)
71
71
  end
72
+
73
+ register_report_scanner ForemanChef::ChefReportScanner
74
+ register_report_origin 'Chef', 'ConfigReport'
72
75
  end
73
76
  end
74
77
 
@@ -76,6 +79,10 @@ module ForemanChef
76
79
  ActionView::Base.send :include, ChefProxyForm
77
80
  end
78
81
 
82
+ initializer 'foreman_chef.chef_reports_helper' do |app|
83
+ ActionView::Base.send :include, ChefReportsHelper
84
+ end
85
+
79
86
  initializer 'foreman_chef.dynflow_world', :before => 'foreman_tasks.initialize_dynflow' do |app|
80
87
  ForemanTasks.dynflow.require!
81
88
  end
@@ -93,8 +100,9 @@ module ForemanChef
93
100
  ::Host::Managed.send :prepend, ForemanChef::Concerns::HostExtensions
94
101
  ::Hostgroup.send :include, ForemanChef::Concerns::HostgroupExtensions
95
102
  ::SmartProxy.send :prepend, ForemanChef::Concerns::SmartProxyExtensions
96
- ::Host::Managed.send :prepend, ForemanChef::Concerns::HostActionSubject
97
103
  ::Host::Managed.send :prepend, ForemanChef::Concerns::HostBuild
104
+ ::HostsController.send :include, ForemanChef::Concerns::HostsControllerExtensions
105
+ ::Api::V2::HostsController.send :include, ForemanChef::Concerns::HostsControllerExtensions
98
106
  ::HostsController.send :prepend, ForemanChef::Concerns::HostsControllerRescuer
99
107
 
100
108
  ::Host::Managed.send :include, ForemanChef::Concerns::Renderer
@@ -1,3 +1,3 @@
1
1
  module ForemanChef
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-11 00:00:00.000000000 Z
11
+ date: 2019-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -69,9 +69,11 @@ files:
69
69
  - app/assets/javascripts/foreman_chef/jsoneditor.js.map
70
70
  - app/controllers/foreman_chef/application_controller.rb
71
71
  - app/controllers/foreman_chef/concerns/environment_parameters.rb
72
+ - app/controllers/foreman_chef/concerns/hosts_controller_extensions.rb
72
73
  - app/controllers/foreman_chef/concerns/hosts_controller_rescuer.rb
73
74
  - app/controllers/foreman_chef/environments_controller.rb
74
75
  - app/helpers/foreman_chef/chef_proxy_form.rb
76
+ - app/helpers/foreman_chef/chef_reports_helper.rb
75
77
  - app/lib/actions/foreman_chef/client/create.rb
76
78
  - app/lib/actions/foreman_chef/client/destroy.rb
77
79
  - app/lib/actions/foreman_chef/host/destroy.rb
@@ -79,7 +81,7 @@ files:
79
81
  - app/lib/actions/foreman_chef/node/update.rb
80
82
  - app/lib/proxy_api/foreman_chef/chef_proxy.rb
81
83
  - app/models/foreman_chef/cached_run_list.rb
82
- - app/models/foreman_chef/concerns/host_action_subject.rb
84
+ - app/models/foreman_chef/chef_report_scanner.rb
83
85
  - app/models/foreman_chef/concerns/host_and_hostgroup_extensions.rb
84
86
  - app/models/foreman_chef/concerns/host_build.rb
85
87
  - app/models/foreman_chef/concerns/host_extensions.rb
@@ -139,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.6.8
144
+ rubygems_version: 3.0.3
144
145
  signing_key:
145
146
  specification_version: 4
146
147
  summary: Plugin for Chef integration with Foreman
@@ -1,23 +0,0 @@
1
- module ForemanChef
2
- module Concerns
3
- module HostActionSubject
4
- def update_action
5
- sync_action!
6
- ::Actions::ForemanChef::Host::Update
7
- end
8
-
9
- def destroy_action
10
- sync_action!
11
- ::Actions::ForemanChef::Host::Destroy
12
- end
13
-
14
- def action_input_key
15
- "host"
16
- end
17
- end
18
- end
19
- end
20
-
21
- class ::Host::Managed::Jail < Safemode::Jail
22
- allow :chef_proxy, :chef_environment, :chef_private_key
23
- end