foreman_param_lookup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Add dependencies here.
4
+
5
+ group :development do
6
+ gem "bundler"
7
+ gem "jeweler"
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Red Hat Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # foreman_param_lookup
2
+
3
+ Foreman engine plugin that exposes smart class parameter lookups for any host
4
+ and class.
5
+
6
+ The ENC YAML output that Foreman generates only provides parameters for classes
7
+ that are included on the node through the host or hostgroup records. However
8
+ any smart class parameter can be evaluated for a host, so this exposes an API
9
+ to do that.
10
+
11
+ It's designed to be used with the `foreman_data_binding` Puppet module, which
12
+ uses this API to resolve class parameters using the matchers configured in
13
+ Foreman. It effectively works in the same way as the Hiera integration in
14
+ Puppet 3.
15
+
16
+ Get the foreman_data_binding module from [Puppet Forge](http://forge.puppetlabs.com/domcleal/foreman_data_binding)
17
+ or [GitHub](https://github.com/domcleal/foreman_data_binding).
18
+
19
+ # Installation:
20
+
21
+ Include in your `~foreman/bundler.d/foreman_param_lookup.rb`
22
+
23
+ gem 'foreman_param_lookup'
24
+
25
+ Or from git:
26
+
27
+ gem 'foreman_param_lookup', :git => "https://github.com/domcleal/foreman_param_lookup.git"
28
+
29
+ As Foreman user:
30
+
31
+ bundle install
32
+
33
+ To upgrade to newest version of the plugin:
34
+
35
+ bundle update foreman_param_lookup
36
+
37
+ Don't forget to install the Puppet module to use that functionality.
38
+
39
+ # Usage
40
+
41
+ The URL requires the host (that will be used as context for the smart class
42
+ parameter lookup) and the class. It'll return all parameters for the class in
43
+ YAML format.
44
+
45
+ $ curl http://foreman/param_lookup?host=host.example.net&class=module::class
46
+ ---
47
+ module::class:
48
+ param1: value
49
+ param2: "another value"
50
+
51
+ # Copyright
52
+
53
+ Copyright (c) 2013 Red Hat Inc. See LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "foreman_param_lookup"
17
+ gem.homepage = "http://github.com/domcleal/foreman_param_lookup"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Exposes smart class parameters lookups as an API}
20
+ gem.description = %Q{Exposes smart class parameters lookups as an API}
21
+ gem.email = "dcleal@redhat.com"
22
+ gem.authors = ["Dominic Cleal"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+
26
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,22 @@
1
+ module ForemanParamLookup
2
+ class ClassificationsController < ::ApplicationController
3
+ skip_before_filter :require_login, :only => :lookup
4
+ skip_before_filter :require_ssl, :only => :lookup
5
+ skip_before_filter :authorize, :only => :lookup
6
+ skip_before_filter :set_taxonomy, :only => :lookup
7
+ skip_before_filter :session_expiry, :update_activity_time, :only => :lookup
8
+ before_filter :set_admin_user, :only => :lookup
9
+
10
+ def lookup
11
+ host = Host.find_by_name(params[:host])
12
+ ppclass = Puppetclass.find_by_name(params[:class])
13
+ unless host and ppclass
14
+ head :status => 404
15
+ return
16
+ end
17
+ render :text => AnyClassification.new(
18
+ :host => host, :classes => [ppclass].flatten
19
+ ).enc.to_yaml
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ class AnyClassification < Classification
2
+ def initialize args = { }
3
+ super args
4
+ @classes = args[:classes]
5
+ end
6
+
7
+ private
8
+
9
+ def puppetclass_ids
10
+ @classes.map {|c| c.id}
11
+ end
12
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ match 'param_lookup', :to => 'foreman_param_lookup/classifications#lookup'
3
+ end
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "foreman_param_lookup"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dominic Cleal"]
12
+ s.date = "2013-01-18"
13
+ s.description = "Exposes smart class parameters lookups as an API"
14
+ s.email = "dcleal@redhat.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "app/controllers/foreman_param_lookup/classifications_controller.rb",
26
+ "app/models/foreman_param_lookup/any_classification.rb",
27
+ "config/routes.rb",
28
+ "foreman_param_lookup.gemspec",
29
+ "lib/foreman_param_lookup.rb",
30
+ "lib/foreman_param_lookup/engine.rb"
31
+ ]
32
+ s.homepage = "http://github.com/domcleal/foreman_param_lookup"
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = "1.8.24"
36
+ s.summary = "Exposes smart class parameters lookups as an API"
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_development_dependency(%q<bundler>, [">= 0"])
43
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
44
+ else
45
+ s.add_dependency(%q<bundler>, [">= 0"])
46
+ s.add_dependency(%q<jeweler>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<bundler>, [">= 0"])
50
+ s.add_dependency(%q<jeweler>, [">= 0"])
51
+ end
52
+ end
53
+
@@ -0,0 +1,6 @@
1
+ require 'foreman_param_lookup'
2
+
3
+ module ForemanParamLookup
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ForemanParamLookup
2
+ require 'foreman_param_lookup/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman_param_lookup
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Dominic Cleal
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
31
+ name: bundler
32
+ prerelease: false
33
+ type: :development
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ version_requirements: *id002
45
+ name: jeweler
46
+ prerelease: false
47
+ type: :development
48
+ description: Exposes smart class parameters lookups as an API
49
+ email: dcleal@redhat.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.md
57
+ files:
58
+ - Gemfile
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - VERSION
63
+ - app/controllers/foreman_param_lookup/classifications_controller.rb
64
+ - app/models/foreman_param_lookup/any_classification.rb
65
+ - config/routes.rb
66
+ - foreman_param_lookup.gemspec
67
+ - lib/foreman_param_lookup.rb
68
+ - lib/foreman_param_lookup/engine.rb
69
+ homepage: http://github.com/domcleal/foreman_param_lookup
70
+ licenses:
71
+ - MIT
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Exposes smart class parameters lookups as an API
102
+ test_files: []
103
+