Chef_Solo_Nodes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Chef_Solo_Nodes.gemspec +30 -0
- data/Gemfile +6 -0
- data/README.md +29 -0
- data/Rakefile +3 -0
- data/lib/Chef_Solo_Nodes.rb +24 -0
- data/lib/Chef_Solo_Nodes/version.rb +3 -0
- data/spec/data/nodes/custom_port.json +5 -0
- data/spec/data/nodes/freemont.json +3 -0
- data/spec/data/nodes/localhost.json +1 -0
- data/spec/data/nodes/no_ip.json +4 -0
- data/spec/data/nodes/no_roles.json +4 -0
- data/spec/helper.rb +15 -0
- data/spec/main.rb +20 -0
- data/spec/tests/Chef_Solo_IPs.rb +26 -0
- data/spec/tests/Chef_Solo_Nodes.rb +24 -0
- data/spec/tests/bin.rb +10 -0
- metadata +143 -0
data/.gitignore
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "Chef_Solo_Nodes/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "Chef_Solo_Nodes"
|
8
|
+
s.version = Chef_Solo_Nodes::VERSION
|
9
|
+
s.authors = ["da99"]
|
10
|
+
s.email = ["i-hate-spam-45671204@mailinator.com"]
|
11
|
+
s.homepage = "https://www.github.com/da99/chef_solo_nodes"
|
12
|
+
s.summary = %q{Grab node info from ./nodes/*.json}
|
13
|
+
s.description = %q{
|
14
|
+
Use with Chef-Solo. Grabs node info as array of Hashes or String ips.
|
15
|
+
}
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "bacon"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency 'Bacon_Colored'
|
25
|
+
s.add_development_dependency 'pry'
|
26
|
+
|
27
|
+
# s.rubyforge_project = "Chef_Solo_Nodes"
|
28
|
+
# specify any dependencies here; for example:
|
29
|
+
s.add_runtime_dependency "json"
|
30
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
Chef\_Solo\_Nodes
|
3
|
+
===============
|
4
|
+
|
5
|
+
Provides two functions: Chef\_Solo\_Nodes(), Chef\_Solo\_IPs()
|
6
|
+
|
7
|
+
|
8
|
+
Installation
|
9
|
+
-----------
|
10
|
+
|
11
|
+
gem install Chef_Solo_Nodes
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
require "Chef_Solo_Nodes"
|
17
|
+
|
18
|
+
Chef_Solo_Nodes() # ===> [ Hash, Hash ]
|
19
|
+
Chef_Solo_Nodes('role_name') # ===> [ Hash, Hash ]
|
20
|
+
Chef_Solo_IPs('db') # ===> [ String, String ]
|
21
|
+
|
22
|
+
Implementation
|
23
|
+
--------------
|
24
|
+
|
25
|
+
It grabs all your files using Dir.glob("./nodes/\*.json").
|
26
|
+
Chef\_Solo\_IPS() also does some magic. It's easier to
|
27
|
+
understand if you see the code.
|
28
|
+
[It's just one page long.'](https://github.com/da99/Chef_Solo_Nodes/blob/master/lib/Chef_Solo_Nodes.rb)
|
29
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'Chef_Solo_Nodes/version'
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
def Chef_Solo_Nodes raw_role = '*'
|
5
|
+
role = raw_role.to_s
|
6
|
+
all = Dir.glob("nodes/*.json").map { |str|
|
7
|
+
h = JSON(File.read(str))
|
8
|
+
h['ipaddress'] ||= File.basename(str).sub(".json", "")
|
9
|
+
h
|
10
|
+
}
|
11
|
+
return all if role == '*'
|
12
|
+
|
13
|
+
all.select { |h|
|
14
|
+
(h['roles'] || []).include?(role)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def Chef_Solo_IPs *args
|
19
|
+
Chef_Solo_Nodes(*args).map { |h|
|
20
|
+
[ h['ipaddress'] || h['hostname'], h['port'] ].compact.join(':')
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "roles": ["app"] }
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.print e.message, "\n"
|
7
|
+
$stderr.print "Run `bundle install` to install missing gems\n"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'bacon'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
|
15
|
+
Bacon.summary_on_exit
|
data/spec/main.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('spec/helper')
|
3
|
+
require 'Chef_Solo_Nodes'
|
4
|
+
require 'Bacon_Colored'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
|
8
|
+
def chdir
|
9
|
+
Dir.chdir("spec/data/") { yield }
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# ======== Include the tests.
|
14
|
+
if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
|
15
|
+
# Do nothing. Bacon grabs the file.
|
16
|
+
else
|
17
|
+
Dir.glob('spec/tests/*.rb').each { |file|
|
18
|
+
require File.expand_path(file.sub('.rb', '')) if File.file?(file)
|
19
|
+
}
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
describe "Chef_Solo_IPs()" do
|
3
|
+
|
4
|
+
it "returns the ip addresses of all nodes" do
|
5
|
+
chdir {
|
6
|
+
Chef_Solo_IPs().size
|
7
|
+
.should == Dir.glob("nodes/*.json").size
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "selects ip addresses from specified role" do
|
12
|
+
chdir {
|
13
|
+
Chef_Solo_IPs('no_ip')
|
14
|
+
.should == [ "no_ip:1234" ]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "includes custom port in ip address" do
|
19
|
+
chdir{
|
20
|
+
Chef_Solo_IPs('custom_port')
|
21
|
+
.should == [ "custom_port:1234"]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
end # === Chef_Solo_IPs
|
26
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
describe "Chef_Solo_Nodes()" do
|
3
|
+
|
4
|
+
it "returns an Array of Hashes from ./nodes/*.json" do
|
5
|
+
chdir {
|
6
|
+
Chef_Solo_Nodes().map(&:class).uniq.should == [Hash]
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "sets default :ipaddress to filename" do
|
11
|
+
chdir {
|
12
|
+
Chef_Solo_Nodes('no_ip').first['ipaddress'].should == "no_ip"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "selects nodes based on given role name" do
|
17
|
+
chdir {
|
18
|
+
Chef_Solo_Nodes('app').map { |h| h['ipaddress'] }.sort
|
19
|
+
.should == %w{ custom_port freemont localhost }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end # === Chef_Solo_Nodes()
|
24
|
+
|
data/spec/tests/bin.rb
ADDED
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Chef_Solo_Nodes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- da99
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: Bacon_Colored
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: json
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! "\n Use with Chef-Solo. Grabs node info as array of Hashes or String
|
95
|
+
ips.\n "
|
96
|
+
email:
|
97
|
+
- i-hate-spam-45671204@mailinator.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Chef_Solo_Nodes.gemspec
|
104
|
+
- Gemfile
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/Chef_Solo_Nodes.rb
|
108
|
+
- lib/Chef_Solo_Nodes/version.rb
|
109
|
+
- spec/data/nodes/custom_port.json
|
110
|
+
- spec/data/nodes/freemont.json
|
111
|
+
- spec/data/nodes/localhost.json
|
112
|
+
- spec/data/nodes/no_ip.json
|
113
|
+
- spec/data/nodes/no_roles.json
|
114
|
+
- spec/helper.rb
|
115
|
+
- spec/main.rb
|
116
|
+
- spec/tests/Chef_Solo_IPs.rb
|
117
|
+
- spec/tests/Chef_Solo_Nodes.rb
|
118
|
+
- spec/tests/bin.rb
|
119
|
+
homepage: https://www.github.com/da99/chef_solo_nodes
|
120
|
+
licenses: []
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.19
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Grab node info from ./nodes/*.json
|
143
|
+
test_files: []
|