blender-chef 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02bfeb4a25b9c9ee8449472f569c2fa581ae6895
4
+ data.tar.gz: 3c73b3cbbc3b9c4244be213328c9b33965906bd3
5
+ SHA512:
6
+ metadata.gz: 22813586dd6ec066baaabc5b667f209fe7db62be786a85a2a0019de206574df54da987f6f6d180a5f12231bd3659b5dd9b9d86f7ddf639ffdda65fcb5a8bfc25
7
+ data.tar.gz: b5f89d15b5f7398232ab5a8d61a7b45cbf07fc6a2d803f51d3b9b63cd335d79479292aed9f0631cafd7d33177d1dc53c991b92f23ebd21bc99ad85ae99e3d870
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,10 @@
1
+ before_install:
2
+ - bundle install --path .bundle
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.1.0
6
+ - 2.1.2
7
+ branches:
8
+ only:
9
+ - master
10
+ script: "bundle exec rake spec"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
4
+ require 'yard'
5
+
6
+ YARD::Rake::YardocTask.new do |t|
7
+ t.files = ['lib/**/*.rb']
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = %w{spec/**/*_spec.rb}
12
+ end
13
+
14
+ RuboCop::RakeTask.new(:rubocop) do |t|
15
+ t.patterns = %w{Rakefile Gemfile lib/**/*.rb}
16
+ t.fail_on_error = true
17
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'blender-chef'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Ranjib Dey']
9
+ spec.email = ['ranjib@pagerduty.com']
10
+ spec.summary = %q{Chef search based host discovery for blender}
11
+ spec.description = %q{Discover hosts using chef search for blender}
12
+ spec.homepage = 'http://github.com/PagerDuty/blender-chef'
13
+ spec.license = 'Apache 2'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.test_files = spec.files.grep(%r{^spec/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'pd-blender'
20
+ spec.add_dependency 'chef'
21
+
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rubocop'
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'yard'
28
+ end
@@ -0,0 +1 @@
1
+ require 'blender/discoveries/chef'
@@ -0,0 +1,69 @@
1
+ #
2
+ # Author:: Ranjib Dey (<ranjib@pagerduty.com>)
3
+ # Copyright:: Copyright (c) 2014 PagerDuty, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'chef/search/query'
19
+
20
+ module Blender
21
+ module Discovery
22
+ class Chef
23
+ attr_reader :options
24
+
25
+ def initialize(options = {})
26
+ @options = options
27
+ end
28
+
29
+ def search(search_term = '*:*')
30
+ if options[:config_file]
31
+ ::Chef::Config.from_file options[:config_file]
32
+ end
33
+ if options[:node_name]
34
+ ::Chef::Config[:node_name] = options[:node_name]
35
+ end
36
+ if options[:client_key]
37
+ ::Chef::Config[:client_key] = options[:client_key]
38
+ end
39
+ if options[:chef_server_url]
40
+ ::Chef::Config[:chef_server_url] = options[:chef_server_url]
41
+ end
42
+ attr = options[:attribute] || 'fqdn'
43
+ q = ::Chef::Search::Query.new
44
+ res = q.search(:node, search_term)
45
+ res.first.collect{|n| node_attribute(n, attr)}
46
+ end
47
+
48
+ private
49
+ def node_attribute(data, nested_value_spec)
50
+ nested_value_spec.split(".").each do |attr|
51
+ if data.nil?
52
+ nil # don't get no method error on nil
53
+ elsif data.respond_to?(attr.to_sym)
54
+ data = data.send(attr.to_sym)
55
+ elsif data.respond_to?(:[])
56
+ data = data[attr]
57
+ else
58
+ data = begin
59
+ data.send(attr.to_sym)
60
+ rescue NoMethodError
61
+ nil
62
+ end
63
+ end
64
+ end
65
+ ( !data.kind_of?(Array) && data.respond_to?(:to_hash) ) ? data.to_hash : data
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'blender/discoveries/chef'
3
+
4
+ describe Blender::Discovery::Chef do
5
+ let(:discovery){described_class.new}
6
+ it '#search' do
7
+ query = double(Chef::Search::Query)
8
+ node = Chef::Node.new
9
+ node.set['fqdn'] = 'a'
10
+ expect(query).to receive(:search).with(:node, '*:*').and_return([[node]])
11
+ expect(Chef::Search::Query).to receive(:new).and_return(query)
12
+ expect(discovery.search).to eq(['a'])
13
+ end
14
+ it '#search with options' do
15
+ disco = described_class.new(
16
+ config_file: 'foo.rb',
17
+ node_name: 'bar',
18
+ client_key: 'baz.rb',
19
+ attribute: 'x.y.z'
20
+ )
21
+ query = double(Chef::Search::Query)
22
+ node = Chef::Node.new
23
+ node.set['x'] = { 'y' => { 'z' => 123 } }
24
+ expect(Chef::Config).to receive(:from_file).with('foo.rb')
25
+ expect(query).to receive(:search).with(:node, 'name:x').and_return([[node]])
26
+ expect(Chef::Search::Query).to receive(:new).and_return(query)
27
+ expect(disco.search('name:x')).to eq([123])
28
+ expect(Chef::Config[:client_key]).to eq('baz.rb')
29
+ expect(Chef::Config[:node_name]).to eq('bar')
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ require 'blender'
2
+
3
+ RSpec.configure do |config|
4
+ config.mock_with :rspec do |mocks|
5
+ mocks.verify_doubled_constant_names = true
6
+ end
7
+ config.backtrace_exclusion_patterns = []
8
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blender-chef
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ranjib Dey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pd-blender
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Discover hosts using chef search for blender
126
+ email:
127
+ - ranjib@pagerduty.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - Rakefile
136
+ - blender-chef.gemspec
137
+ - lib/blender/chef.rb
138
+ - lib/blender/discoveries/chef.rb
139
+ - spec/blender/discoveries/chef_spec.rb
140
+ - spec/spec_helper.rb
141
+ homepage: http://github.com/PagerDuty/blender-chef
142
+ licenses:
143
+ - Apache 2
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.2.2
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Chef search based host discovery for blender
165
+ test_files:
166
+ - spec/blender/discoveries/chef_spec.rb
167
+ - spec/spec_helper.rb
168
+ has_rdoc: