tugboat 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d29e3739288b2b4fe84d466672dc840926521529
4
- data.tar.gz: 0431588980b59d18c1ef6dff0f22d17001c29c94
3
+ metadata.gz: 675f0544eb2cd135f849db7e54875a7997ff81ff
4
+ data.tar.gz: 5e7ef404c16d2b0b5da797927b0f4a93edb54d30
5
5
  SHA512:
6
- metadata.gz: ffa3baacba280f38ef8666561c319276e0197345575f333b47351b464b38111bacf2b02d63d76568a848de38f7aed5cfeb3ff8836f7efe1093c0886f9a06e688
7
- data.tar.gz: 32c0e440603dc9b66142519b5c30fd39845567179380a20cca65d90c28388cb7b1026466fcc43ecdbf5ca0cb21a137598910b8df2b2da043dc8a0cbf127c12b0
6
+ metadata.gz: 1d50761d516a571e9c996e73913677a253ae0323efb3b937db13602a19128245152f2773337630b3735891bd3d8b2a70a468c9d99f2790541034777cc5b1fa71
7
+ data.tar.gz: 6e79dcd03a37ffbed67c672d358c92174d7ca2faf19dfd3080328e1a3db1931e365fd21bad60a7be3dbb6e93cca951a72863408712530e2285bb77b943edfff8
data/CHANGELOG.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Change Log
2
2
 
3
- ## [Unreleased](https://github.com/pearkes/tugboat/tree/HEAD)
3
+ ## [v1.2.0](https://github.com/pearkes/tugboat/tree/v1.2.0) (2015-07-18)
4
4
 
5
- [Full Changelog](https://github.com/pearkes/tugboat/compare/v1.1.0...HEAD)
5
+ [Full Changelog](https://github.com/pearkes/tugboat/compare/v1.1.0...v1.2.0)
6
6
 
7
7
  **Fixed bugs:**
8
8
 
@@ -10,15 +10,23 @@
10
10
 
11
11
  **Closed issues:**
12
12
 
13
- - Unable to bundle to run tugboat from git repo version for testing [\#171](https://github.com/pearkes/tugboat/issues/171)
13
+ - Image list and authorize [\#163](https://github.com/pearkes/tugboat/issues/163)
14
14
 
15
15
  **Merged pull requests:**
16
16
 
17
- - Update ssh to private ip [\#172](https://github.com/pearkes/tugboat/pull/172) ([petems](https://github.com/petems))
17
+ - Adds flavour text for listing global images [\#167](https://github.com/pearkes/tugboat/pull/167) ([petems](https://github.com/petems))
18
+
19
+ ## [v1.1.0](https://github.com/pearkes/tugboat/tree/v1.1.0) (2015-07-18)
20
+
21
+ [Full Changelog](https://github.com/pearkes/tugboat/compare/v2.0.0.ALPHA...v1.1.0)
18
22
 
19
23
  **Closed issues:**
20
24
 
21
- - 1.0.0 Release [\#125](https://github.com/pearkes/tugboat/issues/125)
25
+ - Unable to bundle to run tugboat from git repo version for testing [\#171](https://github.com/pearkes/tugboat/issues/171)
26
+
27
+ **Merged pull requests:**
28
+
29
+ - Update ssh to private ip [\#172](https://github.com/pearkes/tugboat/pull/172) ([petems](https://github.com/petems))
22
30
 
23
31
  ## [v1.0.0](https://github.com/pearkes/tugboat/tree/v1.0.0) (2015-05-26)
24
32
 
data/README.md CHANGED
@@ -99,6 +99,24 @@ match.
99
99
  Size ID: 66
100
100
  Backups Active: false
101
101
 
102
+ Print info in machine-readable format. The ``--porcelain`` flag silences extra output for easy parsing. Fuzzy name matching is not supported with the ``--porcelain`` flag.
103
+
104
+ $ tugboat info -n pearkes-admin-001 --attribute ip --porcelain
105
+ name pearkes-admin-001
106
+ id 13231512
107
+ status active
108
+ ip 30.30.30.3
109
+ region_id 1
110
+ image_id 25489
111
+ size_id 66
112
+ backups_active false
113
+
114
+ Print a single attribute.
115
+
116
+ $ tugboat info -n pearkes-admin-001 --attribute ip --porcelain
117
+ 30.30.30.3
118
+
119
+
102
120
  ### Destroy a droplet
103
121
 
104
122
  $ tugboat destroy pearkes-www-002
data/lib/tugboat/cli.rb CHANGED
@@ -308,12 +308,21 @@ module Tugboat
308
308
  :type => :string,
309
309
  :aliases => "-n",
310
310
  :desc => "The exact name of the droplet"
311
+ method_option "attribute",
312
+ :type => :string,
313
+ :aliases => "-a",
314
+ :desc => "The name of the attribute to print."
315
+ method_option "porcelain",
316
+ :type => :boolean,
317
+ :desc => "Give the output in an easy-to-parse format for scripts."
311
318
  def info(name=nil)
312
319
  Middleware.sequence_info_droplet.call({
313
320
  "user_droplet_id" => options[:id],
314
321
  "user_droplet_name" => options[:name],
315
322
  "user_droplet_fuzzy_name" => name,
316
- "user_quiet" => options[:quiet]
323
+ "user_quiet" => options[:quiet],
324
+ "user_attribute" => options[:attribute],
325
+ "user_porcelain" => options[:porcelain]
317
326
  })
318
327
  end
319
328
 
@@ -7,6 +7,7 @@ module Tugboat
7
7
  user_fuzzy_name = env['user_droplet_fuzzy_name']
8
8
  user_droplet_name = env['user_droplet_name']
9
9
  user_droplet_id = env['user_droplet_id']
10
+ porcelain = env['user_porcelain']
10
11
 
11
12
  # First, if nothing is provided to us, we should quit and
12
13
  # let the user know.
@@ -15,6 +16,11 @@ module Tugboat
15
16
  exit 1
16
17
  end
17
18
 
19
+ if porcelain && (!(user_droplet_name || user_droplet_id) || user_fuzzy_name)
20
+ say "Tugboat expects an exact droplet ID or droplet name for porcelain mode.", :red
21
+ exit 1
22
+ end
23
+
18
24
  # If you were to `tugboat restart foo -n foo-server-001` then we'd use
19
25
  # 'foo-server-001' without looking up the fuzzy name.
20
26
  #
@@ -22,7 +28,9 @@ module Tugboat
22
28
 
23
29
  # Easy for us if they provide an id. Just set it to the droplet_id
24
30
  if user_droplet_id
25
- say "Droplet id provided. Finding Droplet...", nil, false
31
+ if !porcelain
32
+ say "Droplet id provided. Finding Droplet...", nil, false
33
+ end
26
34
  req = ocean.droplets.show user_droplet_id
27
35
 
28
36
  if req.status == "ERROR"
@@ -40,7 +48,9 @@ module Tugboat
40
48
  # If they provide a name, we need to get the ID for it.
41
49
  # This requires a lookup.
42
50
  if user_droplet_name && !env["droplet_id"]
43
- say "Droplet name provided. Finding droplet ID...", nil, false
51
+ if !porcelain
52
+ say "Droplet name provided. Finding droplet ID...", nil, false
53
+ end
44
54
 
45
55
  # Look for the droplet by an exact name match.
46
56
  ocean.droplets.list.droplets.each do |d|
@@ -115,7 +125,9 @@ module Tugboat
115
125
  end
116
126
 
117
127
  if !did_run_multiple
118
- say "done#{CLEAR}, #{env["droplet_id"]} #{env["droplet_name"]}", :green
128
+ if !porcelain
129
+ say "done#{CLEAR}, #{env["droplet_id"]} #{env["droplet_name"]}", :green
130
+ end
119
131
  end
120
132
  @app.call(env)
121
133
  end
@@ -19,20 +19,49 @@ module Tugboat
19
19
  status_color = RED
20
20
  end
21
21
 
22
- say
23
- say "Name: #{droplet.name}"
24
- say "ID: #{droplet.id}"
25
- say "Status: #{status_color}#{droplet.status}#{CLEAR}"
26
- say "IP: #{droplet.ip_address}"
27
-
28
- if droplet.private_ip_address
29
- say "Private IP: #{droplet.private_ip_address}"
30
- end
31
-
32
- say "Region ID: #{droplet.region_id}"
33
- say "Image ID: #{droplet.image_id}"
34
- say "Size ID: #{droplet.size_id}"
35
- say "Backups Active: #{droplet.backups_active || false}"
22
+ attribute = env["user_attribute"]
23
+
24
+ attributes_list = [
25
+ ["name", droplet.name],
26
+ ["id", droplet.id],
27
+ ["status", droplet.status],
28
+ ["ip", droplet.ip_address],
29
+ ["private_ip", droplet.private_ip_address],
30
+ ["region_id", droplet.region_id],
31
+ ["image_id", droplet.image_id],
32
+ ["size_id", droplet.size_id],
33
+ ["backups_active", (droplet.backups_active || false)]
34
+ ]
35
+ attributes = Hash[*attributes_list.flatten(1)]
36
+
37
+ if attribute
38
+ if attributes.has_key? attribute
39
+ say attributes[attribute]
40
+ else
41
+ say "Invalid attribute \"#{attribute}\"", :red
42
+ say "Provide one of the following:", :red
43
+ attributes_list.keys.each { |a| say " #{a[0]}", :red }
44
+ end
45
+ else
46
+ if env["user_porcelain"]
47
+ attributes_list.select{ |a| a[1] != nil }.each{ |a| say "#{a[0]} #{a[1]}"}
48
+ else
49
+ say
50
+ say "Name: #{droplet.name}"
51
+ say "ID: #{droplet.id}"
52
+ say "Status: #{status_color}#{droplet.status}#{CLEAR}"
53
+ say "IP: #{droplet.ip_address}"
54
+
55
+ if droplet.private_ip_address
56
+ say "Private IP: #{droplet.private_ip_address}"
57
+ end
58
+
59
+ say "Region ID: #{droplet.region_id}"
60
+ say "Image ID: #{droplet.image_id}"
61
+ say "Size ID: #{droplet.size_id}"
62
+ say "Backups Active: #{droplet.backups_active || false}"
63
+ end
64
+ end
36
65
 
37
66
  @app.call(env)
38
67
  end
@@ -1,3 +1,3 @@
1
1
  module Tugboat
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -104,7 +104,7 @@ Droplet fuzzy name provided. Finding droplet ID...Multiple droplets found.
104
104
  0) test222 (100823)
105
105
  1) test223 (100824)
106
106
 
107
- Please choose a droplet: ["0", "1"]
107
+ Please choose a droplet: ["0", "1"]\x20
108
108
  Name: test222
109
109
  ID: 100823
110
110
  Status: \e[32mactive\e[0m
@@ -121,4 +121,130 @@ Backups Active: false
121
121
 
122
122
  end
123
123
 
124
- end
124
+ it "shows a droplet with an id under porcelain mode" do
125
+ stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
126
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
127
+
128
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
129
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
130
+
131
+ @cli.options = @cli.options.merge(:id => droplet_id, :porcelain => true)
132
+ @cli.info
133
+
134
+ expect($stdout.string).to eq <<-eos
135
+ name foo
136
+ id 100823
137
+ status active
138
+ ip 33.33.33.10
139
+ private_ip 10.20.30.40
140
+ region_id 1
141
+ image_id 420
142
+ size_id 33
143
+ backups_active false
144
+ eos
145
+
146
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
147
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
148
+ end
149
+
150
+ it "shows a droplet with a name under porcelain mode" do
151
+ stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
152
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
153
+
154
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
155
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
156
+
157
+ @cli.options = @cli.options.merge(:name => droplet_name, :porcelain => true)
158
+ @cli.info
159
+
160
+ expect($stdout.string).to eq <<-eos
161
+ name foo
162
+ id 100823
163
+ status active
164
+ ip 33.33.33.10
165
+ private_ip 10.20.30.40
166
+ region_id 1
167
+ image_id 420
168
+ size_id 33
169
+ backups_active false
170
+ eos
171
+
172
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
173
+ expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
174
+ end
175
+
176
+ it "shows a droplet attribute with an id" do
177
+ stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
178
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
179
+
180
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
181
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
182
+
183
+ @cli.options = @cli.options.merge(:id => droplet_id, :attribute => "ip")
184
+ @cli.info
185
+
186
+ expect($stdout.string).to eq <<-eos
187
+ Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)
188
+ 33.33.33.10
189
+ eos
190
+
191
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
192
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
193
+ end
194
+
195
+ it "shows a droplet attribute with a name" do
196
+ stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
197
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
198
+
199
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
200
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
201
+
202
+ @cli.options = @cli.options.merge(:name => droplet_name, :attribute => "ip")
203
+ @cli.info
204
+
205
+ expect($stdout.string).to eq <<-eos
206
+ Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
207
+ 33.33.33.10
208
+ eos
209
+
210
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
211
+ expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
212
+ end
213
+
214
+ it "shows a droplet attribute with an id under porcelain mode" do
215
+ stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
216
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
217
+
218
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
219
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
220
+
221
+ @cli.options = @cli.options.merge(:id => droplet_id, :porcelain => true, :attribute => "ip")
222
+ @cli.info
223
+
224
+ expect($stdout.string).to eq <<-eos
225
+ 33.33.33.10
226
+ eos
227
+
228
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
229
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
230
+ end
231
+
232
+ it "shows a droplet attribute with a name under porcelain mode" do
233
+ stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
234
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
235
+
236
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
237
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
238
+
239
+ @cli.options = @cli.options.merge(:name => droplet_name, :porcelain => true, :attribute => "ip")
240
+ @cli.info
241
+
242
+ expect($stdout.string).to eq <<-eos
243
+ 33.33.33.10
244
+ eos
245
+
246
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
247
+ expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
248
+ end
249
+
250
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tugboat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Pearkes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-18 00:00:00.000000000 Z
11
+ date: 2015-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor