Chef_Solo_Nodes 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Chef_Solo_Nodes.gemspec +1 -3
- data/LICENSE +22 -0
- data/README.md +41 -3
- data/bin/IP +12 -0
- data/bin/SSH +23 -0
- data/lib/Chef_Solo_Nodes/version.rb +1 -1
- data/lib/Chef_Solo_Nodes.rb +12 -8
- data/spec/data/nodes/Vagrant.json +1 -0
- data/spec/data/nodes/with_login.json +1 -0
- data/spec/data/nodes/with_port.json +1 -0
- data/spec/data/nodes/with_user.json +1 -0
- data/spec/tests/IP.rb +31 -0
- data/spec/tests/SSH.rb +42 -0
- data/spec/tests/bin.rb +11 -8
- metadata +14 -3
data/Chef_Solo_Nodes.gemspec
CHANGED
@@ -24,7 +24,5 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'Bacon_Colored'
|
25
25
|
s.add_development_dependency 'pry'
|
26
26
|
|
27
|
-
|
28
|
-
# specify any dependencies here; for example:
|
29
|
-
s.add_runtime_dependency "json"
|
27
|
+
s.add_runtime_dependency "trollop"
|
30
28
|
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 da99
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -10,8 +10,8 @@ Installation
|
|
10
10
|
|
11
11
|
gem install Chef_Solo_Nodes
|
12
12
|
|
13
|
-
Usage
|
14
|
-
|
13
|
+
Ruby Usage
|
14
|
+
----------
|
15
15
|
|
16
16
|
require "Chef_Solo_Nodes"
|
17
17
|
|
@@ -19,11 +19,49 @@ Usage
|
|
19
19
|
Chef_Solo_Nodes('role_name') # ===> [ Hash, Hash ]
|
20
20
|
Chef_Solo_IPs('db') # ===> [ String, String ]
|
21
21
|
|
22
|
+
Capistrano Usage
|
23
|
+
----------------
|
24
|
+
|
25
|
+
require "Chef_Solo_Nodes"
|
26
|
+
role :app, *Chef_Solo_IPs('app')
|
27
|
+
role :db, *Chef_Solo_IPs('db')
|
28
|
+
|
29
|
+
Executable Usage: IP
|
30
|
+
--------------------
|
31
|
+
|
32
|
+
$ IP file_glob
|
33
|
+
127.0.0.1
|
34
|
+
|
35
|
+
$ IP file_with_specified_port
|
36
|
+
127.0.0.1:2222
|
37
|
+
|
38
|
+
$ IP file_with_specified_user_and_port
|
39
|
+
127.0.0.1:2222 # user is not included
|
40
|
+
|
41
|
+
Executable Usage: SSH
|
42
|
+
--------------------
|
43
|
+
|
44
|
+
$ SSH file_glob
|
45
|
+
127.0.0.1
|
46
|
+
|
47
|
+
$ SSH file_with_specified_user_or_login
|
48
|
+
vagrant@127.0.0.1
|
49
|
+
|
50
|
+
$ SSH file_with_specified_port
|
51
|
+
-p 2222 vagrant@127.0.0.1
|
52
|
+
|
53
|
+
$ ssh `SSH vagrant`
|
54
|
+
ssh -p 2222 vagrant@127.0.0.1
|
55
|
+
|
56
|
+
$ knife `SSH file_name`
|
57
|
+
knife vagrant@localhost:2222
|
58
|
+
|
59
|
+
|
22
60
|
Implementation
|
23
61
|
--------------
|
24
62
|
|
25
63
|
It grabs all your files using Dir.glob("./nodes/\*.json").
|
26
64
|
Chef\_Solo\_IPS() also does some magic. It's easier to
|
27
65
|
understand if you see the code.
|
28
|
-
[It's just one page long.
|
66
|
+
[It's just one page long.](https://github.com/da99/Chef_Solo_Nodes/blob/master/lib/Chef_Solo_Nodes.rb)
|
29
67
|
|
data/bin/IP
ADDED
data/bin/SSH
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "Chef_Solo_Nodes"
|
4
|
+
|
5
|
+
n = Chef_Solo_Nodes(Dir.glob("nodes/#{ARGV.first}.json")).first
|
6
|
+
|
7
|
+
unless n
|
8
|
+
print "xx.xx.xx.xx"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
str = ""
|
13
|
+
if n['port']
|
14
|
+
str += "-p #{n['port']} "
|
15
|
+
end
|
16
|
+
|
17
|
+
login = n['user'] || n['login']
|
18
|
+
if login
|
19
|
+
str += "#{login}@"
|
20
|
+
end
|
21
|
+
|
22
|
+
str += "#{n['ipaddress']}"
|
23
|
+
print str
|
data/lib/Chef_Solo_Nodes.rb
CHANGED
@@ -2,17 +2,21 @@ require 'Chef_Solo_Nodes/version'
|
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
def Chef_Solo_Nodes raw_role = '*'
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
if raw_role.is_a?(Array)
|
7
|
+
role = '*'
|
8
|
+
targets = raw_role
|
9
|
+
else
|
10
|
+
role = raw_role.to_s
|
11
|
+
targets = Dir.glob("nodes/*.json")
|
12
|
+
end
|
13
|
+
|
14
|
+
targets.map { |str|
|
7
15
|
h = JSON(File.read(str))
|
16
|
+
next if role != '*' && !(h['roles'] || []).include?(role)
|
8
17
|
h['ipaddress'] ||= File.basename(str).sub(".json", "")
|
9
18
|
h
|
10
|
-
}
|
11
|
-
return all if role == '*'
|
12
|
-
|
13
|
-
all.select { |h|
|
14
|
-
(h['roles'] || []).include?(role)
|
15
|
-
}
|
19
|
+
}.compact
|
16
20
|
end
|
17
21
|
|
18
22
|
def Chef_Solo_IPs *args
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "ipaddress": "localhost", "port":2222, "roles": ["dev"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "ipaddress": "localhost", "login": "log_RjD2", "roles": ["login"] }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "ipaddress": "ben_and_jerry", "port":2222, "roles": ["port"] }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "ipaddress": "localhost", "user": "RjD2", "roles": ["user"] }
|
data/spec/tests/IP.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
describe "IP" do
|
3
|
+
|
4
|
+
it "prints xx.xx.xx.xx if file is not found" do
|
5
|
+
chdir {
|
6
|
+
`IP not.found.json`.should == "xx.xx.xx.xx"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "exists with 1 if not found" do
|
11
|
+
chdir {
|
12
|
+
`IP not.found.json`
|
13
|
+
$?.exitstatus.should == 1
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns only one result" do
|
18
|
+
chdir {
|
19
|
+
`bundle exec IP "*"`.should == "freemont"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not include user if specified" do
|
24
|
+
chdir {
|
25
|
+
`bundle exec IP "with_user"`.should == "localhost"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end # === IP
|
31
|
+
|
data/spec/tests/SSH.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
describe "SSH" do
|
3
|
+
|
4
|
+
it "prints xx.xx.xx.xx if file is not found" do
|
5
|
+
chdir {
|
6
|
+
`SSH not.found.json`.should == "xx.xx.xx.xx"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "exists with 1 if not found" do
|
11
|
+
chdir {
|
12
|
+
`SSH not.found.json`
|
13
|
+
$?.exitstatus.should == 1
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns one result" do
|
18
|
+
chdir {
|
19
|
+
`SSH "*"`.should == File.basename(Dir.glob("nodes/*.json").first).sub(".json", '')
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "adds -p argument if port is specified" do
|
24
|
+
chdir {
|
25
|
+
`SSH "with_port"`.should == "-p 2222 ben_and_jerry"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "adds includes user if \"user\" is specified" do
|
30
|
+
chdir {
|
31
|
+
`SSH "with_user"`.should == "RjD2@localhost"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "adds user if \"user\" is specified" do
|
36
|
+
chdir {
|
37
|
+
`SSH "with_login"`.should == "log_RjD2@localhost"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
end # === SSH
|
42
|
+
|
data/spec/tests/bin.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
4
|
-
it "should be 750" do
|
5
|
-
`stat -c %a bin`.strip
|
6
|
-
.should.be == "750"
|
7
|
-
end
|
8
|
-
|
9
|
-
end # === permissions of bin/
|
2
|
+
bins = Dir.glob("bin/*")
|
10
3
|
|
4
|
+
unless bins.empty?
|
5
|
+
describe "permissions of bin/" do
|
6
|
+
bins.each { |file|
|
7
|
+
it "should chmod 755 for: #{file}" do
|
8
|
+
`stat -c %a #{file}`.strip
|
9
|
+
.should.be == "755"
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end # === permissions of bin/
|
13
|
+
end # === unless bins.empty?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Chef_Solo_Nodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: trollop
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -95,26 +95,37 @@ description: ! "\n Use with Chef-Solo. Grabs node info as array of Hashes or
|
|
95
95
|
ips.\n "
|
96
96
|
email:
|
97
97
|
- i-hate-spam-45671204@mailinator.com
|
98
|
-
executables:
|
98
|
+
executables:
|
99
|
+
- IP
|
100
|
+
- SSH
|
99
101
|
extensions: []
|
100
102
|
extra_rdoc_files: []
|
101
103
|
files:
|
102
104
|
- .gitignore
|
103
105
|
- Chef_Solo_Nodes.gemspec
|
104
106
|
- Gemfile
|
107
|
+
- LICENSE
|
105
108
|
- README.md
|
106
109
|
- Rakefile
|
110
|
+
- bin/IP
|
111
|
+
- bin/SSH
|
107
112
|
- lib/Chef_Solo_Nodes.rb
|
108
113
|
- lib/Chef_Solo_Nodes/version.rb
|
114
|
+
- spec/data/nodes/Vagrant.json
|
109
115
|
- spec/data/nodes/custom_port.json
|
110
116
|
- spec/data/nodes/freemont.json
|
111
117
|
- spec/data/nodes/localhost.json
|
112
118
|
- spec/data/nodes/no_ip.json
|
113
119
|
- spec/data/nodes/no_roles.json
|
120
|
+
- spec/data/nodes/with_login.json
|
121
|
+
- spec/data/nodes/with_port.json
|
122
|
+
- spec/data/nodes/with_user.json
|
114
123
|
- spec/helper.rb
|
115
124
|
- spec/main.rb
|
116
125
|
- spec/tests/Chef_Solo_IPs.rb
|
117
126
|
- spec/tests/Chef_Solo_Nodes.rb
|
127
|
+
- spec/tests/IP.rb
|
128
|
+
- spec/tests/SSH.rb
|
118
129
|
- spec/tests/bin.rb
|
119
130
|
homepage: https://www.github.com/da99/chef_solo_nodes
|
120
131
|
licenses: []
|