Chef_Solo_Nodes 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -70,8 +70,7 @@ Usage: Shell
70
70
 
71
71
  Provides 2 executables: IP and SSH
72
72
 
73
- All they do is print out to standard output. They are meant to
74
- generate arguments for other programs:
73
+ They are meant to generate arguments for other programs:
75
74
 
76
75
  $ ping -c 3 $( IP --no-user file_name )
77
76
  ping -c 3 my.ip.address
@@ -85,21 +84,14 @@ generate arguments for other programs:
85
84
  **Tip:** the last example above uses
86
85
  [knife-solo](https://github.com/matschaffer/knife-solo).
87
86
 
88
- Usage: Errors for IP, SSH
89
- -------------------------
90
-
91
- If the file name does not exist:
92
-
93
- $ IP missing_file
94
- $ SSH missing_file
95
- xx.xx.xx.xx
96
- # exit status = 1
87
+ **Errors:** If the file is not found, they print **xx.xx.xx.xx**
88
+ to standard output and exit 1. Unexpected, unplanned errors
89
+ are printed to standard error.
97
90
 
98
91
  Usage: IP, IP --no-user
99
92
  --------------------
100
93
 
101
- $ IP file_name
102
- # Parses "nodes/file_name.json"
94
+ $ IP file_name # parses node/file_name.json
103
95
 
104
96
  Depending on whether the attributes exist, the results could take
105
97
  any form of the following:
@@ -108,16 +100,12 @@ any form of the following:
108
100
  127.0.0.1:2222
109
101
  user@127.0.0.1:2222
110
102
 
111
- With **--no-user**:
112
-
113
- 127.0.0.1
114
- 127.0.0.1:2222
103
+ Remove **user@** with: **IP --no-user file_name**
115
104
 
116
105
  Usage: SSH, SSH --no-user
117
106
  --------------------
118
107
 
119
- $ SSH file_name
120
- # Parses "nodes/file_name.json"
108
+ $ SSH file_name # parses node/file_name.json
121
109
 
122
110
  Depending on whether the attributes exist, the results could take
123
111
  any form of the following:
@@ -126,10 +114,7 @@ any form of the following:
126
114
  user@127.0.0.1
127
115
  -p 2222 user@127.0.0.1
128
116
 
129
- With **--no-user**:
130
-
131
- 127.0.0.1
132
- -p 2222 127.0.0.1
117
+ Remove **user@** with: **SSH --no-user file_name**
133
118
 
134
119
  Run Tests
135
120
  ---------
data/bin/IP CHANGED
@@ -1,20 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require "Chef_Solo_Nodes"
3
- require "trollop"
4
2
 
5
- opts = Trollop::options do
6
- opt :no_user, "Avoid printing any user/login value", :default=>false
7
- end
8
-
9
- n = Chef_Solo_IPs(Dir.glob("nodes/#{ARGV.first}.json")).first
10
-
11
- if !n
12
- print 'xx.xx.xx.xx'
13
- exit 1
14
- end
15
-
16
- uri = URI.parse("ssh://#{n}")
17
-
18
- print "#{uri.user}@" if uri.user && !opts[:no_user]
19
- print "#{uri.host}"
20
- print ":#{uri.port}" if uri.port
3
+ require "Chef_Solo_Nodes/shell"
data/bin/SSH CHANGED
@@ -1,29 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require "Chef_Solo_Nodes"
3
- require "trollop"
4
2
 
5
- opts = Trollop::options do
6
- opt :no_user, "Avoid printing any user/login value", :default=>false
7
- end
8
-
9
- n = Chef_Solo_IPs(Dir.glob("nodes/#{ARGV.first}.json")).first
10
-
11
- unless n
12
- print "xx.xx.xx.xx"
13
- exit 1
14
- end
15
-
16
- uri = URI.parse("ssh://#{n}")
17
-
18
- str = ""
19
-
20
- if uri.port
21
- str << "-p #{uri.port} "
22
- end
23
-
24
- if uri.user && !opts[:no_user]
25
- str << "#{uri.user}@"
26
- end
27
-
28
- str << "#{uri.host}"
29
- print str
3
+ require "Chef_Solo_Nodes/shell"
4
+
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+
5
+ require "Chef_Solo_Nodes"
6
+ require "trollop"
7
+
8
+ opts = Trollop::options do
9
+ opt :no_user, "Avoid printing any user/login value", :default=>false
10
+ end
11
+
12
+ opts[ :format ] = File.basename($0)
13
+
14
+ glob = "nodes/#{ARGV.first}.json"
15
+ n = Chef_Solo_IPs(Dir.glob glob).first
16
+
17
+ raise RuntimeError, "Not found: #{glob}" unless n
18
+
19
+ uri = URI.parse("ssh://#{n}")
20
+
21
+ case opts.format
22
+ when "IP"
23
+ print "#{uri.user}@" if uri.user && !opts[:no_user]
24
+ print "#{uri.host}"
25
+ print ":#{uri.port}" if uri.port
26
+ when "SSH"
27
+ print "-p #{uri.port} " if uri.port
28
+ print "#{uri.user}@" if uri.user && !opts[:no_user]
29
+ print "#{uri.host}"
30
+ else
31
+ raise ArgumentError, "Unknown format: #{opts.format.inspect}"
32
+ end
33
+
34
+ rescue Object => e
35
+ print 'xx.xx.xx.xx'
36
+ raise e
37
+
38
+ end
@@ -1,3 +1,3 @@
1
1
  class Chef_Solo_Nodes
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -3,13 +3,13 @@ describe "IP" do
3
3
 
4
4
  it "prints xx.xx.xx.xx if file is not found" do
5
5
  chdir {
6
- `IP not.found.json`.should == "xx.xx.xx.xx"
6
+ `IP wrong.droids 2>/dev/null`.should == "xx.xx.xx.xx"
7
7
  }
8
8
  end
9
9
 
10
10
  it "exists with 1 if not found" do
11
11
  chdir {
12
- `IP not.found.json`
12
+ `IP dana.carveys.billions 2>/dev/null`
13
13
  $?.exitstatus.should == 1
14
14
  }
15
15
  end
@@ -3,13 +3,13 @@ describe "SSH" do
3
3
 
4
4
  it "prints xx.xx.xx.xx if file is not found" do
5
5
  chdir {
6
- `SSH not.found.json`.should == "xx.xx.xx.xx"
6
+ `SSH mr.x.is.homer 2>/dev/null`.should == "xx.xx.xx.xx"
7
7
  }
8
8
  end
9
9
 
10
10
  it "exists with 1 if not found" do
11
11
  chdir {
12
- `SSH not.found.json`
12
+ `SSH murray.rothbards.diet.plans 2>/dev/null`
13
13
  $?.exitstatus.should == 1
14
14
  }
15
15
  end
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.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -110,6 +110,7 @@ files:
110
110
  - bin/IP
111
111
  - bin/SSH
112
112
  - lib/Chef_Solo_Nodes.rb
113
+ - lib/Chef_Solo_Nodes/shell.rb
113
114
  - lib/Chef_Solo_Nodes/version.rb
114
115
  - spec/data/nodes/Vagrant.json
115
116
  - spec/data/nodes/custom_port.json