awsutils 2.0.0 → 2.0.1

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: 25454bd61f99733507c1ac9114d7ca2cb75a5a24
4
- data.tar.gz: 95f9939aa14df55f5030b1e6b09ae29beff911f2
3
+ metadata.gz: a5f6821233efc5b2ccae58b7e1704ca710677d7f
4
+ data.tar.gz: b410ed5b1d984f78502e6a1644e52b633f23ced6
5
5
  SHA512:
6
- metadata.gz: 5b7af2b65be1b1c134e14c563de43d5b6782d7bd1279fb5f52dcc5e2eddc5a174dd793e22fefa7cfd0da6ab084335c5d7fac272f068d081807a5ae3de53551ea
7
- data.tar.gz: f3ac8a2bb402f90729536d5b323c4b926ddc106653be044b62736c9812c7133d016305e8cfb8d972bb6b3dbc33ce907c98e5f09ef8ac32129915855a2f137bce
6
+ metadata.gz: dc700cf9f38ef4160a961960c6dec9a2a68841743c829c00fab076bbb6ed8590d4a756257e6cbfd05320cf3ea35bb1a8bf3dfad79592d739c7b03034a9cf9989
7
+ data.tar.gz: cf9fd37811b4847d91739efbf9ada4b8b5690c646f164330824d625e9bb62f680cc0dc0339f6510bbe307d89a122b8b28d3e43d446791a648b700d64aab5a545
@@ -1,374 +1,250 @@
1
1
  require 'rubygems'
2
- require 'fog'
2
+ require 'fog/aws'
3
3
 
4
- class Array
4
+ class String
5
+ def title_case
6
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
7
+ split('_').map { |e| e.capitalize }.join(' ')
8
+ end
9
+ end
5
10
 
6
- def longest
7
- length = 0
8
- val = String.new
9
- self.each do |a|
10
- len_new = a.length
11
- if len_new > length
12
- length = len_new
13
- val = a
14
- end
15
- end
16
- return val
17
- end
11
+ class Array
12
+ def longest
13
+ length = 0
14
+ val = ''
15
+ each do |a|
16
+ len_new = a.length
17
+ if len_new > length
18
+ length = len_new
19
+ val = a
20
+ end
21
+ end
22
+ val
23
+ end
18
24
  end
19
25
 
20
26
  module AwsUtils
21
-
22
27
  class Ec2Info
28
+ attr_reader :search_terms
23
29
 
24
- def connect()
25
-
26
- conn = Fog::Compute.new(:provider => 'AWS')
27
-
28
- if $DEBUG
29
-
30
- puts "Inspect connection result:"
31
- puts conn.inspect
32
-
33
- end
34
-
35
- #puts conn.inspect
36
-
37
- return conn
38
-
39
- end
40
-
41
- def get_instance_id(conn,search_terms)
42
-
43
- if $DEBUG
44
-
45
- puts "Entering get_instance_id"
46
- puts "Search Term: #{search_terms.inspect}"
47
-
48
- end
49
-
50
- instance_ids = Array.new
51
-
52
- search_terms.each do |search_term|
53
-
54
- if (/^i-/ =~ search_term) && (!(/\./ =~ search_term))
55
-
56
- instance_ids[0] = search_term
57
-
58
- else
59
-
60
- conn.servers.each do |server|
61
-
62
- if (server.tags.has_key?("Name")) \
63
- && (server.tags["Name"] != "") \
64
- && (/#{search_term}/i =~ server.tags["Name"])
30
+ def ec2
31
+ @ec2 ||= Fog::Compute.new(provider: 'AWS')
32
+ end
65
33
 
66
- instance_ids << server.id
34
+ def instance_ids
35
+ @instance_ids ||= begin
36
+ if $DEBUG
37
+ puts 'Entering instance_ids'
38
+ puts "Search Term: #{search_terms.inspect}"
39
+ end
67
40
 
41
+ results = search_terms.each_with_object([]) do |search_term, m|
42
+ if (/^i-/ =~ search_term) && !(/\./ =~ search_term)
43
+ m << search_term
44
+ else
45
+ ec2.servers.each do |server|
46
+ next unless server.tags.key?('Name') \
47
+ && (server.tags['Name'] != '') \
48
+ && (/#{search_term}/i =~ server.tags['Name'])
49
+ m << server.id
68
50
  end
69
-
70
51
  end
71
-
72
52
  end
73
53
 
74
- end
75
-
76
- if (instance_ids.count < 1)
77
-
78
- puts "No instances by that Name/ID in this account"
79
-
80
- exit 1
81
-
82
- end
83
-
84
- if $DEBUG
54
+ if results.empty?
55
+ puts 'No instances by that Name/ID in this account'
56
+ exit 1
57
+ end
85
58
 
86
- puts "Found instances: #{instance_ids.inspect}"
59
+ puts "Found instances: #{results.inspect}" if $DEBUG
87
60
 
61
+ results
88
62
  end
89
-
90
- return instance_ids
91
-
92
63
  end
93
64
 
94
65
  def get_flavor_color(flavor)
66
+ fcolor =
67
+ case flavor
68
+ when 't1.micro'
69
+ '1;33'
70
+ when 'm1.large'
71
+ '0;33'
72
+ when 'm1.xlarge'
73
+ '0;34'
74
+ when 'm2.2xlarge'
75
+ '0;35'
76
+ when 'm2.4xlarge'
77
+ '0;31'
78
+ when 'm2.xlarge'
79
+ '0;36'
80
+ else
81
+ '0'
82
+ end
95
83
 
96
- case flavor
97
- when "t1.micro"
98
- fcolor = "1;33"
99
- when "m1.large"
100
- fcolor = "0;33"
101
- when "m1.xlarge"
102
- fcolor = "0;34"
103
- when "m2.2xlarge"
104
- fcolor = "0;35"
105
- when "m2.4xlarge"
106
- fcolor = "0;31"
107
- when "m2.xlarge"
108
- fcolor = "0;36"
109
- else
110
- fcolor = "0"
111
- end
112
-
113
- return "\033[#{fcolor}m"
114
-
84
+ "\033[#{fcolor}m"
115
85
  end
116
86
 
117
87
  def get_state_color(state)
88
+ scolor =
89
+ case state
90
+ when 'running'
91
+ '1;32'
92
+ when 'stopped'
93
+ '1;31'
94
+ when 'starting'
95
+ '5;32'
96
+ when 'stopping'
97
+ '5;31'
98
+ else
99
+ '0'
100
+ end
118
101
 
119
- case state
120
- when "running"
121
- scolor="1;32"
122
- when "stopped"
123
- scolor="1;31"
124
- when "starting"
125
- scolor="5;32"
126
- when "stopping"
127
- scolor="5;31"
128
- else
129
- scolor="0"
130
- end
131
-
132
- return "\033[#{scolor}m"
133
-
102
+ "\033[#{scolor}m"
134
103
  end
135
104
 
136
- def describe_instance_short(search_term)
137
-
138
- conn = connect()
139
-
140
- instance_ids = Array.new
141
-
142
- instance_ids = get_instance_id(conn,search_term)
143
-
144
- instance_attribute_index = Array.new
145
-
146
- conn.servers.first.class.attributes.each do |cur_attr|
147
-
148
- instance_attribute_index << cur_attr
149
-
150
- end
151
-
105
+ def describe_instance_short
152
106
  key_color = "\033[30;1m" # Style: Bold; Color: Default
153
107
  reset_color = "\033[0m"
154
108
 
155
109
  printf("#{key_color}%-50s %-11s %-12s %-13s %-10s %s#{reset_color}\n",
156
- "Name",
157
- "Zone",
158
- "ID",
159
- "Group",
160
- "Flavor",
161
- "State"
110
+ 'Name',
111
+ 'Zone',
112
+ 'ID',
113
+ 'Group',
114
+ 'Flavor',
115
+ 'State'
162
116
  )
163
117
 
164
118
  instance_ids.each do |instance_id|
119
+ inst = ec2.servers.get(instance_id)
165
120
 
166
- inst = conn.servers.get(instance_id)
167
-
168
121
  s_color = get_state_color(inst.state)
169
122
  f_color = get_flavor_color(inst.flavor_id)
170
123
 
171
- printf("%-50s %-11s %-12s %-13s #{f_color}%-10s#{reset_color} #{s_color}%s#{reset_color}",
172
- inst.tags['Name'],
173
- inst.availability_zone,
174
- inst.id,
175
- inst.groups.first,
176
- inst.flavor_id,
177
- inst.state
178
- )
179
-
124
+ printf(
125
+ "%-50s %-11s %-12s %-13s #{f_color}%-10s#{reset_color} #{s_color}%s#{reset_color}",
126
+ inst.tags['Name'],
127
+ inst.availability_zone,
128
+ inst.id,
129
+ inst.groups.first,
130
+ inst.flavor_id,
131
+ inst.state
132
+ )
180
133
  end
181
-
182
-
183
134
  end
184
-
185
- def describe_instance(search_term)
186
-
187
- conn = connect()
188
-
189
- instance_ids = Array.new
190
-
191
- instance_ids = get_instance_id(conn,search_term)
192
135
 
193
- instance_attribute_index = Array.new
136
+ def describe_instance
137
+ instance_attribute_index = ec2.servers.first.class.attributes
138
+ # ec2.servers.first.class.attributes.reject { |attr| attr == :vpc_id }
194
139
 
195
- conn.servers.first.class.attributes.each do |cur_attr|
196
-
197
- instance_attribute_index << cur_attr
198
-
199
- end
200
-
201
- if $DEBUG
202
-
203
- puts "Built attribute index: #{instance_attribute_index.inspect}"
204
-
205
- end
140
+ puts "Built attribute index: #{instance_attribute_index.inspect}" if $DEBUG
206
141
 
207
142
  col_green = "\033[32;1m" # Style: Bold; Color: Green
208
143
  col_red = "\033[31;1m" # Style: Bold; Color: Red
209
- col_blinking_red = "\033[31;5m"
144
+ # col_blinking_red = "\033[31;5m"
210
145
 
211
146
  key_color = "\033[30;1m" # Style: Bold; Color: Default
212
147
  reset_color = "\033[0m"
213
148
 
214
149
  instance_ids.each do |instance_id|
215
-
216
- instance = conn.servers.get(instance_id)
150
+ instance = ec2.servers.get instance_id
217
151
 
218
152
  puts "#{key_color}NAME:#{reset_color} #{instance.tags['Name']}"
219
- puts ""
220
-
221
- instance_attribute_index.delete("vpc_id")
153
+ puts
222
154
 
223
155
  instance_attribute_index.each do |instance_attribute|
224
-
225
- if $DEBUG
226
-
227
- puts "Instance attribute: #{instance_attribute}"
228
-
229
- end
156
+ puts "Instance attribute: #{instance_attribute}" if $DEBUG
230
157
 
231
158
  case instance_attribute
232
159
  when :id
233
-
234
160
  puts "#{key_color}ID:#{reset_color} #{instance.id}"
235
-
236
161
  when :ami_launch_index
237
-
238
162
  puts "#{key_color}AMI Launch Index:#{reset_color} #{instance.ami_launch_index}"
239
-
240
163
  when :availability_zone
241
-
242
164
  puts "#{key_color}Availability Zone:#{reset_color} #{instance.availability_zone}"
243
-
244
165
  when :block_device_mapping
245
-
246
166
  puts "#{key_color}Block Devices:#{reset_color} "
247
-
248
- instance.block_device_mapping.each do |vol|
249
167
 
250
- vol_obj = conn.volumes.get(vol['volumeId'])
168
+ instance.block_device_mapping.each do |vol|
169
+ vol_obj = ec2.volumes.get(vol['volumeId'])
251
170
 
252
171
  puts "\t#{key_color}Size:#{reset_color} #{vol_obj.size} GB"
253
172
  puts "\t#{key_color}Volume ID:#{reset_color} #{vol_obj.id}"
254
173
  puts "\t#{key_color}Device Name:#{reset_color} #{vol_obj.device}"
255
174
 
256
- if (vol_obj.delete_on_termination == true)
257
-
258
- puts "\t#{key_color}Delete on Termination:#{reset_color} " +
175
+ if vol_obj.delete_on_termination
176
+ puts "\t#{key_color}Delete on Termination:#{reset_color} " \
259
177
  "#{col_red}YES#{reset_color}"
260
-
261
178
  else
262
-
263
- puts "\t#{key_color}Delete on Termination:#{reset_color} " +
179
+ puts "\t#{key_color}Delete on Termination:#{reset_color} " \
264
180
  "#{col_green}NO#{reset_color}"
265
-
266
181
  end
267
182
 
268
183
  puts "\t#{key_color}Attach Time:#{reset_color} #{vol_obj.attached_at}"
269
184
  puts "\t#{key_color}Creation Time:#{reset_color} #{vol_obj.created_at}"
270
185
 
271
- if (vol_obj.snapshot_id != nil)
272
-
273
- snap_obj = conn.snapshots.get(vol_obj.snapshot_id)
186
+ if vol_obj.snapshot_id
187
+ snap_obj = ec2.snapshots.get(vol_obj.snapshot_id)
274
188
 
275
189
  print "\t#{key_color}Snapshot ID:#{reset_color} #{vol_obj.snapshot_id}"
276
190
 
277
- if (defined?snap_obj.created_at)
278
-
279
- puts " (Created: #{snap_obj.created_at})"
280
-
281
- end
282
-
283
- if (defined?snap_obj.tags) && (snap_obj.tags != {})
191
+ puts " (Created: #{snap_obj.created_at})" if defined?(snap_obj.created_at)
284
192
 
193
+ if defined?(snap_obj.tags) && snap_obj.tags != {}
285
194
  puts "\t\t#{key_color}Tags:#{reset_color}"
286
195
 
287
- snap_obj.tags.each do |snap_tag,snap_tag_value|
288
-
196
+ snap_obj.tags.each do |snap_tag, snap_tag_value|
289
197
  puts "\t\t\t#{key_color}#{snap_tag}:#{reset_color} #{snap_tag_value}"
290
-
291
198
  end
292
-
293
199
  end
294
-
295
- end
296
-
297
- if (vol_obj.state != "in-use")
298
-
299
- puts "\t#{key_color}State:#{reset_color} #{vol_obj.state}"
300
-
301
200
  end
302
201
 
303
- if (vol['status'] == "attached")
304
-
305
- status_color = col_green
306
-
307
- else
308
-
309
- status_color = col_red
202
+ puts "\t#{key_color}State:#{reset_color} #{vol_obj.state}" if vol_obj.state != 'in-use'
310
203
 
311
- end
204
+ status_color =
205
+ if vol['status'] == 'attached'
206
+ col_green
207
+ else
208
+ col_red
209
+ end
312
210
 
313
211
  puts "\t#{key_color}Status:#{reset_color} #{status_color}#{vol['status']}#{reset_color}"
314
212
 
315
- if (vol_obj.tags != {})
316
-
213
+ if vol_obj.tags != {}
317
214
  puts "\t#{key_color}Tags:#{reset_color}"
318
215
 
319
- vol_obj.tags.each do |vol_tag,vol_tag_value|
320
-
216
+ vol_obj.tags.each do |vol_tag, vol_tag_value|
321
217
  puts "\t\t#{key_color}#{vol_tag}:#{reset_color} #{vol_tag_value}"
322
-
323
218
  end
324
219
 
325
220
  end
326
221
 
327
- if (vol != instance.block_device_mapping.last)
328
-
222
+ if vol != instance.block_device_mapping.last
329
223
  puts "\t---------------------------------------"
330
-
331
224
  end
332
-
333
225
  end
334
226
 
335
227
  when :client_token
336
-
337
- if (instance.client_token != nil)
338
-
228
+ if instance.client_token
339
229
  puts "#{key_color}Client Token:#{reset_color} #{instance.client_token}"
340
-
341
230
  elsif $DEBUG
342
-
343
231
  puts "#{key_color}Client Token:#{reset_color} N/A"
344
-
345
232
  end
346
-
347
233
  when :dns_name
348
-
349
234
  puts "#{key_color}DNS Name:#{reset_color} #{instance.dns_name}"
350
-
351
235
  when :groups
352
-
353
236
  instance.groups.each do |group_id|
237
+ group = ec2.security_groups.get(group_id)
354
238
 
355
- group = conn.security_groups.get(group_id)
356
-
357
- if (group != nil)
358
-
359
- puts "#{key_color}Security Group:#{reset_color} #{group.name}"
360
- puts "\t#{key_color}Description:#{reset_color} #{group.description}"
361
- puts "\t#{key_color}ID:#{reset_color} #{group.group_id}"
362
-
363
- end
364
-
365
- break if group != nil
366
-
239
+ next unless group
240
+ puts "#{key_color}Security Group:#{reset_color} #{group.name}"
241
+ puts "\t#{key_color}Description:#{reset_color} #{group.description}"
242
+ puts "\t#{key_color}ID:#{reset_color} #{group.group_id}"
243
+ break
367
244
  end
368
245
 
369
246
  when :flavor_id
370
-
371
- instance_flavor = conn.flavors.get(instance.flavor_id)
247
+ instance_flavor = ec2.flavors.get(instance.flavor_id)
372
248
 
373
249
  puts "#{key_color}Flavor:#{reset_color} #{instance_flavor.id}"
374
250
 
@@ -377,325 +253,177 @@ module AwsUtils
377
253
  puts "\t#{key_color}Cores:#{reset_color} #{instance_flavor.cores}"
378
254
  puts "\t#{key_color}Instance Storage (in /mnt):#{reset_color} #{instance_flavor.disk} GB"
379
255
  puts "\t#{key_color}RAM:#{reset_color} #{instance_flavor.ram} MB"
380
-
381
256
  when :image_id
382
-
383
257
  puts "#{key_color}Image ID:#{reset_color} #{instance.image_id}"
384
-
385
- image_obj = conn.images.get(instance.image_id)
386
-
387
- if (defined?image_obj.name)
388
-
389
- puts "\t#{key_color}Name:#{reset_color} #{image_obj.name}"
390
258
 
391
- end
259
+ image_obj = ec2.images.get(instance.image_id)
392
260
 
393
- if (defined?image_obj.description)
261
+ puts "\t#{key_color}Name:#{reset_color} #{image_obj.name}" if defined?(image_obj.name)
394
262
 
263
+ if defined?(image_obj.description)
395
264
  puts "\t#{key_color}Description:#{reset_color} #{image_obj.description}"
396
-
397
265
  end
398
266
 
399
- if (defined?image_obj.location)
400
-
267
+ if defined?(image_obj.location)
401
268
  puts "\t#{key_color}Location:#{reset_color} #{image_obj.location}"
402
-
403
269
  end
404
270
 
405
- if (defined?image_obj.architecture)
406
-
271
+ if defined?(image_obj.architecture)
407
272
  puts "\t#{key_color}Arch:#{reset_color} #{image_obj.architecture}"
408
-
409
273
  end
410
-
411
- if (defined?image_obj.tags) && (image_obj.tags != {})
412
274
 
275
+ if defined?(image_obj.tags) && (image_obj.tags != {})
413
276
  puts "\t#{key_color}Tags:#{reset_color}"
414
277
 
415
- image_obj.tags.each do |image_tag,image_tag_value|
416
-
278
+ image_obj.tags.each do |image_tag, image_tag_value|
417
279
  puts "\t\t#{key_color}#{image_tag}: #{image_tag_value}"
418
-
419
280
  end
420
-
421
281
  end
422
-
423
-
424
282
  when :kernel_id
425
-
426
283
  puts "#{key_color}Kernel ID:#{reset_color} #{instance.kernel_id}"
427
-
428
284
  when :key_name
429
-
430
285
  puts "#{key_color}SSH Key:#{reset_color} #{instance.key_name}"
431
-
432
286
  when :created_at
433
-
434
287
  puts "#{key_color}Created Date:#{reset_color} #{instance.created_at}"
435
-
436
288
  when :monitoring
437
-
438
289
  puts "#{key_color}Monitoring:#{reset_color} #{instance.monitoring}"
439
-
440
290
  when :placement_group
441
-
442
- if (instance.placement_group != nil)
443
-
291
+ if instance.placement_group
444
292
  puts "#{key_color}Placement Group:#{reset_color} #{instance.placement_group}"
445
-
446
293
  elsif $DEBUG
447
-
448
294
  puts "#{key_color}Placement Group:#{reset_color} N/A"
449
-
450
295
  end
451
-
452
296
  when :platform
453
-
454
- if (instance.platform != nil)
455
-
297
+ if instance.platform
456
298
  puts "#{key_color}Platform:#{reset_color} #{instance.platform}"
457
-
458
299
  elsif $DEBUG
459
-
460
300
  puts "#{key_color}Platform:#{reset_color} N/A"
461
-
462
301
  end
463
-
464
302
  when :product_codes
465
-
466
- if (instance.product_codes.count > 0)
467
-
303
+ if instance.product_codes.any?
468
304
  puts "#{key_color}Product Codes:#{reset_color} #{instance.product_codes.join(',')}"
469
-
470
305
  elsif $DEBUG
471
-
472
306
  puts "#{key_color}Product Codes:#{reset_color} N/A"
473
-
474
307
  end
475
-
476
308
  when :private_dns_name
477
-
478
309
  puts "#{key_color}Private DNS Name:#{reset_color} #{instance.private_dns_name}"
479
-
480
310
  when :private_ip_address
481
-
482
311
  puts "#{key_color}Private IP Address:#{reset_color} #{instance.private_ip_address}"
483
-
484
312
  when :public_ip_address
485
-
486
- if conn.addresses.get(instance.public_ip_address)
487
-
488
- puts "#{key_color}Public IP Address:#{reset_color} " +
489
- "#{instance.public_ip_address} (#{col_green}STATIC#{reset_color})"
490
-
313
+ if ec2.addresses.get(instance.public_ip_address)
314
+ puts "#{key_color}Public IP Address:#{reset_color} " \
315
+ "#{instance.public_ip_address} (#{col_green}STATIC#{reset_color})"
491
316
  else
492
-
493
- puts "#{key_color}Public IP Address:#{reset_color} " +
494
- "#{instance.public_ip_address} (#{col_red}DYNAMIC#{reset_color})"
495
-
317
+ puts "#{key_color}Public IP Address:#{reset_color} " \
318
+ "#{instance.public_ip_address} (#{col_red}DYNAMIC#{reset_color})"
496
319
  end
497
-
498
320
  when :ramdisk_id
499
-
500
- if (instance.ramdisk_id != nil)
501
-
321
+ if instance.ramdisk_id
502
322
  puts "#{key_color}Ramdisk ID:#{reset_color} #{instance.ramdisk_id}"
503
-
504
323
  elsif $DEBUG
505
-
506
324
  puts "#{key_color}Ramdisk ID:#{reset_color} N/A"
507
-
508
325
  end
509
-
510
326
  when :reason
511
-
512
- if (instance.reason != nil)
513
-
327
+ if instance.reason
514
328
  puts "#{key_color}State Reason:#{reset_color} #{instance.reason}"
515
-
516
329
  elsif $DEBUG
517
-
518
330
  puts "#{key_color}State Reason:#{reset_color} N/A"
519
-
520
331
  end
521
-
522
332
  when :root_device_name
523
-
524
- if (instance.root_device_name != nil)
525
-
333
+ if instance.root_device_name
526
334
  puts "#{key_color}Root Device Name:#{reset_color} #{instance.root_device_name}"
527
-
528
335
  elsif $DEBUG
529
-
530
336
  puts "#{key_color}Root Device Name:#{reset_color} N/A"
531
-
532
337
  end
533
-
534
338
  when :root_device_type
535
-
536
- if (instance.root_device_type != nil)
537
-
339
+ if instance.root_device_type
538
340
  puts "#{key_color}Root Device Type:#{reset_color} #{instance.root_device_type}"
539
-
540
341
  elsif $DEBUG
541
-
542
342
  puts "#{key_color}Root Device Name:#{reset_color} N/A"
543
-
544
343
  end
545
-
546
344
  when :security_group_ids
547
-
548
- if (instance.security_group_ids != nil)
549
-
345
+ if instance.security_group_ids
550
346
  puts "#{key_color}Security Group IDs:#{reset_color} #{instance.security_group_ids}"
551
-
552
347
  elsif $DEBUG
553
-
554
348
  puts "#{key_color}Security Group IDs:#{reset_color} N/A"
555
-
556
349
  end
557
-
558
350
  when :state
559
-
560
351
  state_color = get_state_color(instance.state)
561
-
562
352
  puts "#{key_color}State:#{reset_color} #{state_color}#{instance.state}#{reset_color}"
563
-
564
353
  when :state_reason
565
-
566
- if (instance.state_reason != {})
567
-
354
+ if instance.state_reason.any?
568
355
  puts "#{key_color}State Reason Code:#{reset_color} #{instance.state_reason["Code"]}"
569
-
570
356
  elsif $DEBUG
571
-
572
357
  puts "#{key_color}State Reason Code:#{reset_color} N/A"
573
-
574
358
  end
575
-
576
359
  when :subnet_id
577
-
578
- if (instance.subnet_id != nil)
579
-
360
+ if instance.subnet_id
580
361
  puts "#{key_color}Subnet ID:#{reset_color} #{instance.subnet_id}"
581
-
582
362
  elsif $DEBUG
583
-
584
363
  puts "#{key_color}Subnet ID:#{reset_color} N/A"
585
-
586
364
  end
587
-
588
365
  when :tenancy
589
-
590
366
  puts "#{key_color}Tenancy:#{reset_color} #{instance.tenancy}"
591
-
592
367
  when :tags
593
-
594
- if (instance.tags.count > 0)
595
-
368
+ if instance.tags.any?
596
369
  puts "#{key_color}Tags:#{reset_color} "
597
370
 
598
- instance.tags.each do |tag,value|
599
-
371
+ instance.tags.each do |tag, value|
600
372
  puts "\t#{key_color}#{tag}:#{reset_color} #{value}"
601
-
602
373
  end
603
-
604
374
  else
605
-
606
375
  puts "#{key_color}Tags:#{reset_color} None"
607
-
608
376
  end
609
-
610
377
  when :user_data
611
-
612
- if (instance.user_data != nil)
613
-
378
+ if instance.user_data
614
379
  puts "#{key_color}User Data:#{reset_color} #{instance.user_data}"
615
-
616
380
  elsif $DEBUG
617
-
618
381
  puts "#{key_color}User Data:#{reset_color} N/A"
619
-
620
382
  end
621
-
622
383
  when :vpc_id
623
-
624
- if (instance.vpc_id != nil)
625
-
384
+ if instance.vpc_id
626
385
  puts "#{key_color}VPC ID:#{reset_color} #{instance.vpc_id}"
627
-
628
386
  elsif $DEBUG
629
-
630
387
  puts "#{key_color}VPC ID: #{reset_color} N/A"
631
-
632
388
  end
633
-
634
389
  else
635
-
636
- if instance.respond_to? :instance_attribute
637
-
638
- puts "#{key_color}#{instance_attribute.to_s}:#{reset_color} #{instance.instance_attribute}"
639
-
640
- else
641
-
642
- puts "#{key_color}#{instance_attribute.to_s}:#{reset_color} <NULL>"
643
-
644
- end
645
-
390
+ print "#{key_color}#{instance_attribute.to_s.title_case}:#{reset_color} "
391
+ puts instance.respond_to?(:instance_attribute) ? '' : '<NULL>'
646
392
  end
647
-
648
393
  end
649
394
 
650
- if instance.instance_initiated_shutdown_behavior == nil
651
-
652
- puts "#{key_color}Shutdown Behavior:#{reset_color} Do nothing"
653
-
395
+ if instance.instance_initiated_shutdown_behavior
396
+ puts "#{key_color}Shutdown Behavior:#{reset_color} " \
397
+ "#{instance.instance_initiated_shutdown_behavior}"
654
398
  else
655
-
656
- puts "#{key_color}Shutdown Behavior:#{reset_color} " +
657
- "#{instance.instance_initiated_shutdown_behavior}"
658
-
399
+ puts "#{key_color}Shutdown Behavior:#{reset_color} Do nothing"
659
400
  end
660
401
 
661
- if (instance_id != instance_ids.last)
662
-
663
- puts "------------------------------------------------------------------------------------"
664
-
402
+ if instance_id != instance_ids.last
403
+ puts '------------------------------------------------------------------------------------'
665
404
  end
666
-
667
405
  end
668
-
669
- end
670
-
671
- def initialize()
672
-
673
- if (ARGV[0] == "") || (ARGV[0] == nil)
406
+ end
674
407
 
675
- puts "Please specify a search term (Host Name or Instance ID)"
408
+ def initialize
409
+ if (ARGV[0] == '') || !ARGV[0]
410
+ puts 'Please specify a search term (Host Name or Instance ID)'
676
411
  exit 1
677
-
678
412
  end
679
413
 
680
414
  args = ARGV
681
415
 
682
- if args.include?("-s") || args.include?("--short")
683
-
684
- args.delete("-s")
685
- args.delete("--short")
416
+ if args.include?('-s') || args.include?('--short')
417
+ args.delete '-s'
418
+ args.delete '--short'
686
419
 
687
- describe_instance_short(args)
420
+ @search_terms = args
688
421
 
422
+ describe_instance_short
689
423
  else
690
-
691
- describe_instance(args)
692
-
424
+ @search_terms = args
425
+ describe_instance
693
426
  end
694
-
695
-
696
-
697
- end
698
-
427
+ end
699
428
  end
700
-
701
- end
429
+ end
@@ -1,3 +1,3 @@
1
1
  module AwsUtils
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Herot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -236,4 +236,3 @@ test_files:
236
236
  - spec/lib/awsutils/ec2addsg_spec.rb
237
237
  - spec/lib/awsutils/ec2lsgrp_spec.rb
238
238
  - spec/spec_helper.rb
239
- has_rdoc: