Chef_Solo_Nodes 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -16
- data/bin/CAP_IP +11 -0
- data/bin/IP +5 -1
- data/bin/SSH +9 -7
- data/lib/Chef_Solo_Nodes.rb +8 -1
- data/lib/Chef_Solo_Nodes/version.rb +1 -1
- data/spec/data/nodes/with_port.json +1 -1
- data/spec/tests/CAP_IP.rb +31 -0
- data/spec/tests/Chef_Solo_IPs.rb +7 -0
- data/spec/tests/SSH.rb +2 -2
- metadata +4 -1
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Installation
|
|
10
10
|
|
11
11
|
gem install Chef_Solo_Nodes
|
12
12
|
|
13
|
-
Ruby
|
13
|
+
Usage: Ruby
|
14
14
|
----------
|
15
15
|
|
16
16
|
require "Chef_Solo_Nodes"
|
@@ -19,31 +19,45 @@ Ruby Usage
|
|
19
19
|
Chef_Solo_Nodes('role_name') # ===> [ Hash, Hash ]
|
20
20
|
Chef_Solo_IPs('db') # ===> [ String, String ]
|
21
21
|
|
22
|
-
Capistrano
|
22
|
+
Usage: Capistrano
|
23
23
|
----------------
|
24
24
|
|
25
25
|
require "Chef_Solo_Nodes"
|
26
26
|
role :app, *Chef_Solo_IPs('app')
|
27
27
|
role :db, *Chef_Solo_IPs('db')
|
28
28
|
|
29
|
-
|
29
|
+
Usage: CAP\_IP
|
30
30
|
--------------------
|
31
31
|
|
32
|
-
$
|
33
|
-
127.0.0.1
|
32
|
+
$ CAP_IP file_name
|
33
|
+
127.0.0.1
|
34
|
+
# Read from nodes/file_name.json
|
34
35
|
|
35
|
-
$
|
36
|
+
$ CAP_IP file_with_port
|
36
37
|
127.0.0.1:2222
|
37
38
|
|
38
|
-
$
|
39
|
-
127.0.0.1:2222
|
39
|
+
$ CAP_IP file_with_user_and_port
|
40
|
+
vagrant@127.0.0.1:2222
|
40
41
|
|
41
|
-
|
42
|
+
Usage: IP
|
42
43
|
--------------------
|
43
44
|
|
44
|
-
|
45
|
+
The user is excluded in the final print out, unlike with CAP\_IP.
|
46
|
+
|
47
|
+
$ IP file_with_user_and_port
|
48
|
+
127.0.0.1:2222
|
49
|
+
# Read from nodes/file_with_user_and_port.json
|
50
|
+
|
51
|
+
$ IP file_with_no_port
|
45
52
|
127.0.0.1
|
46
53
|
|
54
|
+
Usage: SSH
|
55
|
+
--------------------
|
56
|
+
|
57
|
+
$ SSH file_name
|
58
|
+
127.0.0.1
|
59
|
+
# Read from nodes/file_name.json
|
60
|
+
|
47
61
|
$ SSH file_with_specified_user_or_login
|
48
62
|
vagrant@127.0.0.1
|
49
63
|
|
@@ -60,12 +74,7 @@ Executable Usage: SSH
|
|
60
74
|
Implementation
|
61
75
|
--------------
|
62
76
|
|
63
|
-
It's easier to
|
64
|
-
understand if you see the code.
|
77
|
+
It's easier to understand if you see the code.
|
65
78
|
[It's just one page long.](https://github.com/da99/Chef_Solo_Nodes/blob/master/lib/Chef_Solo_Nodes.rb)
|
66
79
|
|
67
|
-
[bin/SSH](https://github.com/da99/Chef_Solo_Nodes/blob/master/bin/SSH)
|
68
|
-
|
69
|
-
[bin/IP](https://github.com/da99/Chef_Solo_Nodes/blob/master/bin/IP)
|
70
|
-
|
71
80
|
|
data/bin/CAP_IP
ADDED
data/bin/IP
CHANGED
data/bin/SSH
CHANGED
@@ -2,22 +2,24 @@
|
|
2
2
|
|
3
3
|
require "Chef_Solo_Nodes"
|
4
4
|
|
5
|
-
n =
|
5
|
+
n = Chef_Solo_IPs(Dir.glob("nodes/#{ARGV.first}.json")).first
|
6
6
|
|
7
7
|
unless n
|
8
8
|
print "xx.xx.xx.xx"
|
9
9
|
exit 1
|
10
10
|
end
|
11
11
|
|
12
|
+
uri = URI.parse("ssh://#{n}")
|
13
|
+
|
12
14
|
str = ""
|
13
|
-
|
14
|
-
|
15
|
+
|
16
|
+
if uri.port
|
17
|
+
str << "-p #{uri.port} "
|
15
18
|
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
str += "#{login}@"
|
20
|
+
if uri.user
|
21
|
+
str << "#{uri.user}@"
|
20
22
|
end
|
21
23
|
|
22
|
-
str
|
24
|
+
str << "#{uri.host}"
|
23
25
|
print str
|
data/lib/Chef_Solo_Nodes.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'Chef_Solo_Nodes/version'
|
2
|
+
require "uri"
|
2
3
|
require "json"
|
3
4
|
|
4
5
|
#
|
@@ -40,7 +41,13 @@ end
|
|
40
41
|
#
|
41
42
|
def Chef_Solo_IPs *args
|
42
43
|
Chef_Solo_Nodes(*args).map { |h|
|
43
|
-
|
44
|
+
u = h['user'] || h['login']
|
45
|
+
a = h['ipaddress'] || h['hostname']
|
46
|
+
p = h['port']
|
47
|
+
|
48
|
+
final = [u, a].compact.join('@')
|
49
|
+
final = [final, p].compact.join(':')
|
50
|
+
final
|
44
51
|
}
|
45
52
|
end
|
46
53
|
|
@@ -1 +1 @@
|
|
1
|
-
{ "ipaddress": "
|
1
|
+
{ "ipaddress": "BenNJer", "port":2222, "roles": ["port"] }
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
describe "CAP_IP" do
|
3
|
+
|
4
|
+
it "prints xx.xx.xx.xx if file is not found" do
|
5
|
+
chdir {
|
6
|
+
`CAP_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
|
+
`CAP_IP not.found.json`
|
13
|
+
$?.exitstatus.should == 1
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns only one result" do
|
18
|
+
chdir {
|
19
|
+
`bundle exec CAP_IP "*"`.should == "freemont"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "includes user if specified" do
|
24
|
+
chdir {
|
25
|
+
`bundle exec CAP_IP "with_user"`.should == "RjD2@localhost"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end # === IP
|
31
|
+
|
data/spec/tests/Chef_Solo_IPs.rb
CHANGED
@@ -21,6 +21,13 @@ describe "Chef_Solo_IPs()" do
|
|
21
21
|
.should == [ "custom_port:1234"]
|
22
22
|
}
|
23
23
|
end
|
24
|
+
|
25
|
+
it "includes user in address: user@address" do
|
26
|
+
chdir {
|
27
|
+
Chef_Solo_IPs('login').
|
28
|
+
should == [ "log_RjD2@localhost"]
|
29
|
+
}
|
30
|
+
end
|
24
31
|
|
25
32
|
end # === Chef_Solo_IPs
|
26
33
|
|
data/spec/tests/SSH.rb
CHANGED
@@ -22,11 +22,11 @@ describe "SSH" do
|
|
22
22
|
|
23
23
|
it "adds -p argument if port is specified" do
|
24
24
|
chdir {
|
25
|
-
`SSH "with_port"`.should == "-p 2222
|
25
|
+
`SSH "with_port"`.should == "-p 2222 BenNJer"
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
29
|
-
it "adds
|
29
|
+
it "adds user if \"user\" is specified" do
|
30
30
|
chdir {
|
31
31
|
`SSH "with_user"`.should == "RjD2@localhost"
|
32
32
|
}
|
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.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -96,6 +96,7 @@ description: ! "\n Use with Chef-Solo. Grabs node info as array of Hashes or
|
|
96
96
|
email:
|
97
97
|
- i-hate-spam-45671204@mailinator.com
|
98
98
|
executables:
|
99
|
+
- CAP_IP
|
99
100
|
- IP
|
100
101
|
- SSH
|
101
102
|
extensions: []
|
@@ -107,6 +108,7 @@ files:
|
|
107
108
|
- LICENSE
|
108
109
|
- README.md
|
109
110
|
- Rakefile
|
111
|
+
- bin/CAP_IP
|
110
112
|
- bin/IP
|
111
113
|
- bin/SSH
|
112
114
|
- lib/Chef_Solo_Nodes.rb
|
@@ -122,6 +124,7 @@ files:
|
|
122
124
|
- spec/data/nodes/with_user.json
|
123
125
|
- spec/helper.rb
|
124
126
|
- spec/main.rb
|
127
|
+
- spec/tests/CAP_IP.rb
|
125
128
|
- spec/tests/Chef_Solo_IPs.rb
|
126
129
|
- spec/tests/Chef_Solo_Nodes.rb
|
127
130
|
- spec/tests/IP.rb
|