puppetdb_foreman 0.0.5 → 0.0.6

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDJmZTBhM2Q1YTc2Zjg5ZjU4YjMwZGNiYzE0OTE0NjY3ZTMzMmMxZQ==
5
+ data.tar.gz: !binary |-
6
+ NmZlNTY3OWQ3MzI2ZDRjNDI1ZjI2NTZjYmI1M2VhYTRkODliMGU3MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTVkMmVmMmZkMjJmZGRmNDYyNDZmMmI5M2ExYTZhMjg3MDAxYWFkNDEzYTA1
10
+ NzEwZTdjMTQ0MTEzNjJjMjNlOWViYzExY2FjYmVkNWNjMDFkZmQ1OTY5MjM5
11
+ MzNiZGI5NzcwMjQ2NDc1ODkxMGQ1N2EwZjJkN2JjNTY0NzYxYmI=
12
+ data.tar.gz: !binary |-
13
+ ZTZmMzhmZjE3Zjk0N2RlYjZjMGE2OGZiZjI1NmIxM2Q3Y2Y1YTJlNjUyZTc0
14
+ ZjNjOTU4ZmY0YzdlNzg4MWY0YjkxYWJmYzUzOWQwOTgwMDQzNTYyZjI4NTNk
15
+ MzE1OTk0NDJmOTZjNTRjMTgwZGU2ZDE1YzJjMDQ5OWQzODBlOWY=
@@ -1,36 +1,64 @@
1
+ #
2
+ # Copyright 2013 CERN, Switzerland
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  module PuppetdbForeman
2
- module HostExtensions
18
+ module HostExtensions
3
19
  extend ActiveSupport::Concern
4
20
  included do
5
- after_destroy :deactivate_host
21
+ before_destroy :deactivate_host
6
22
 
7
23
  def deactivate_host
8
- logger.debug "Deactivating host #{name} in Puppetdb"
9
- if SETTINGS[:puppetdb][:enabled] && SETTINGS[:puppetdb][:address].present?
10
- begin
11
- uri = URI.parse(SETTINGS[:puppetdb][:address])
12
- req = Net::HTTP::Post.new(uri.path)
24
+ logger.debug "Deactivating host #{name} in Puppetdb"
25
+ return false unless configured?
26
+
27
+ if Setting[:puppetdb_enabled]
28
+ begin
29
+ uri = URI.parse(Setting[:puppetdb_address])
30
+ req = Net::HTTP::Post.new(uri.path)
13
31
  req['Accept'] = 'application/json'
14
32
  req.body = 'payload={"command":"deactivate node","version":1,"payload":"\"'+name+'\""}'
15
- res = Net::HTTP.new(uri.host, uri.port)
16
- res.use_ssl = uri.scheme == 'https'
17
- if res.use_ssl?
18
- if Setting[:ssl_ca_file]
19
- res.ca_file = Setting[:ssl_ca_file]
20
- res.verify_mode = OpenSSL::SSL::VERIFY_PEER
21
- else
22
- res.verify_mode = OpenSSL::SSL::VERIFY_NONE
23
- end
33
+ res = Net::HTTP.new(uri.host, uri.port)
34
+ res.use_ssl = uri.scheme == 'https'
35
+ if res.use_ssl?
36
+ if Setting[:ssl_ca_file]
37
+ res.ca_file = Setting[:ssl_ca_file]
38
+ res.verify_mode = OpenSSL::SSL::VERIFY_PEER
39
+ else
40
+ res.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
+ end
24
42
  if Setting[:ssl_certificate] && Setting[:ssl_priv_key]
25
43
  res.cert = OpenSSL::X509::Certificate.new(File.read(Setting[:ssl_certificate]))
26
44
  res.key = OpenSSL::PKey::RSA.new(File.read(Setting[:ssl_priv_key]), nil)
27
- end
28
- end
29
- res.start { |http| http.request(req) }
30
- rescue => e
31
- raise "Could not deactivate host: #{e}"
32
- end
45
+ end
46
+ end
47
+ res.start { |http| http.request(req) }
48
+ rescue => e
49
+ errors.add(:base, _("Could not deactivate host on PuppetDB: #{e}"))
50
+ end
51
+ errors.empty?
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def configured?
58
+ if Setting[:puppetdb_enabled] && Setting[:puppetdb_address].blank?
59
+ errors.add(:base, _("PuppetDB plugin is enabled but not configured. Please configure it before trying to delete a host."))
33
60
  end
61
+ errors.empty?
34
62
  end
35
63
  end
36
64
  end
@@ -0,0 +1,17 @@
1
+ class Setting::Puppetdb < ::Setting
2
+ BLANK_ATTRS << 'puppetdb_address'
3
+
4
+ def self.load_defaults
5
+ Setting.transaction do
6
+ [
7
+ self.set('puppetdb_enabled', _("Integration with PuppetDB, enabled will deactivate a host in PuppetDB when it's deleted in Foreman"), 'false'),
8
+ ].compact.each { |s| self.create s.update(:category => 'Setting::Puppetdb')}
9
+ end
10
+
11
+ Setting.transaction do
12
+ [
13
+ self.set('puppetdb_address', _('Foreman will send PuppetDB requests to this address'), ''),
14
+ ].compact.each { |s| self.create s.update(:category => 'Setting::Puppetdb')}
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,19 @@
1
+ #
2
+ # Copyright 2013 CERN, Switzerland
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
1
17
  module PuppetdbForeman
2
18
  require 'puppetdb_foreman/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
19
  end
@@ -1,6 +1,31 @@
1
+ #
2
+ # Copyright 2013 CERN, Switzerland
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  module PuppetdbForeman
2
17
  class Engine < ::Rails::Engine
3
18
 
19
+ initializer 'puppetdb_foreman.load_default_settings', :before => :load_config_initializers do |app|
20
+ require_dependency File.expand_path("../../../app/models/setting/puppetdb.rb", __FILE__) if (Setting.table_exists? rescue(false))
21
+ end
22
+
23
+ initializer 'puppetdb_foreman.register_plugin', :after=> :finisher_hook do |app|
24
+ Foreman::Plugin.register :puppetdb_foreman do
25
+ requires_foreman '> 1.0'
26
+ end
27
+ end
28
+
4
29
  config.to_prepare do
5
30
  if SETTINGS[:version].to_s.to_f >= 1.2
6
31
  # Foreman 1.2
@@ -10,6 +35,5 @@ module PuppetdbForeman
10
35
  Host.send :include, PuppetdbForeman::HostExtensions
11
36
  end
12
37
  end
13
-
14
38
  end
15
39
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel Lobato Garcia
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-07-20 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: At the moment it basically disables hosts on puppetdb after they are
15
14
  deleted in Foreman. Follow https://github.com/cernops/puppetdb_foreman and raise
@@ -20,31 +19,32 @@ extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
21
  - app/models/puppetdb_foreman/host_extensions.rb
22
+ - app/models/setting/puppetdb.rb
23
23
  - lib/puppetdb_foreman.rb
24
24
  - lib/puppetdb_foreman/engine.rb
25
25
  homepage: http://www.github.com/cernops/puppetdb_foreman
26
- licenses: []
26
+ licenses:
27
+ - Apache-2.0
28
+ metadata: {}
27
29
  post_install_message:
28
30
  rdoc_options: []
29
31
  require_paths:
30
32
  - lib
31
33
  required_ruby_version: !ruby/object:Gem::Requirement
32
- none: false
33
34
  requirements:
34
35
  - - ! '>='
35
36
  - !ruby/object:Gem::Version
36
37
  version: '0'
37
38
  required_rubygems_version: !ruby/object:Gem::Requirement
38
- none: false
39
39
  requirements:
40
40
  - - ! '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  requirements: []
44
44
  rubyforge_project:
45
- rubygems_version: 1.8.25
45
+ rubygems_version: 2.4.1
46
46
  signing_key:
47
- specification_version: 3
47
+ specification_version: 4
48
48
  summary: This is a foreman plugin to interact with puppetdb through callbacks.
49
49
  test_files: []
50
50
  has_rdoc: