puppetdb_foreman 0.0.4

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.
@@ -0,0 +1,37 @@
1
+ module PuppetdbForeman
2
+ module HostExtensions
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ after_destroy :deactivate_host
6
+
7
+ 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)
13
+ req['Accept'] = 'application/json'
14
+ 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
24
+ if Setting[:ssl_certificate] && Setting[:ssl_priv_key]
25
+ res.cert = OpenSSL::X509::Certificate.new(File.read(Setting[:ssl_certificate]))
26
+ 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
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module PuppetdbForeman
2
+ require 'puppetdb_foreman/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
+ end
@@ -0,0 +1,15 @@
1
+ module PuppetdbForeman
2
+ class Engine < ::Rails::Engine
3
+
4
+ config.to_prepare do
5
+ if SETTINGS[:version].to_f >= 1.2
6
+ # Foreman 1.2
7
+ Host::Managed.send :include, PuppetdbForeman::HostExtensions
8
+ else
9
+ # Foreman < 1.2
10
+ Host.send :include, PuppetdbForeman::HostExtensions
11
+ end
12
+ end
13
+
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppetdb_foreman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Lobato Garcia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: At the moment it basically disables hosts on puppetdb after they are
15
+ deleted in Foreman. Follow https://github.com/cernops/puppetdb_foreman and raise
16
+ an issue/submit a pull request if you need extra functionality
17
+ email: elobatocs@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - app/models/puppetdb_foreman/host_extensions.rb
23
+ - lib/puppetdb_foreman.rb
24
+ - lib/puppetdb_foreman/engine.rb
25
+ homepage: http://www.github.com/cernops/puppetdb_foreman
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.24
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: This is a foreman plugin to interact with puppetdb through callbacks.
49
+ test_files: []