swa 0.3.3 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f67b72cbe913a6388331d39a0712396b0860ed53
4
- data.tar.gz: ba6e2d45513837f958df812a219a752fd4cc823b
3
+ metadata.gz: 857543d35465a009440daac9909f96f0e4c67f06
4
+ data.tar.gz: b0d79ccc8a742c1e31813646b1949d565b74d84d
5
5
  SHA512:
6
- metadata.gz: 6c52a78603d824cbcfc1c2326b573d333e1feda685fa3059daf2f90a0463e1365886c8810255e82d111ce4957fe347574ea958cad2f21d4ea0e58fabaf7834c8
7
- data.tar.gz: c229d344051e47fde3ba951a30eb0c0c638f7616d8bd4c0fe88fb1d32f6d2c22beb82bedbbdf5cfc7de20ee3646aedd3411013c0a7b5fc7cb150d790c3e9377f
6
+ metadata.gz: 9a3839446038c98f7de200cfc06a390ce6c556c2d5a3aa59d2a96b53a736172a48cb7912bb1a231a08d314944564f4c78e4a8adf86493fba509c9cfa667b5752
7
+ data.tar.gz: 3dec6acb79cda9077a2e02e0736b360c5de968fe0edd761eba2dbe9e4d6235b3fb3a85a0024daeb2810c3214c8e55a79ea6424cb6c8f775ecf66c7a1ce360c21
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  SWA is AWS, backwards.
4
4
 
5
- It's an alternative CLI for AWS. "Backwards" because commands put verbs at the end:
5
+ It's an alternative CLI for AWS.
6
+
7
+ "Backwards" because it puts verbs at the end:
6
8
 
7
9
  $ swa ec2 instance i-9336f049 terminate
8
10
 
@@ -65,7 +67,7 @@ The "item" sub-command can be ommitted, when it can be inferred from the resourc
65
67
 
66
68
  ## Contributing
67
69
 
68
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/swa.
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mdub/swa.
69
71
 
70
72
  ## License
71
73
 
@@ -3,6 +3,7 @@ require "clamp"
3
3
  require "console_logger"
4
4
  require "jmespath"
5
5
  require "multi_json"
6
+ require "swa/cli/data_output"
6
7
  require "yaml"
7
8
 
8
9
  module Swa
@@ -18,18 +19,7 @@ module Swa
18
19
  option "--session-token", "KEY", "AWS security token",
19
20
  :attribute_name => :session_token
20
21
 
21
- option "--format", "FORMAT", "format for data output",
22
- :attribute_name => :output_format,
23
- :environment_variable => "SWA_OUTPUT_FORMAT",
24
- :default => "YAML"
25
-
26
- option ["--json", "-J"], :flag, "output data in JSON format" do
27
- self.output_format = "JSON"
28
- end
29
-
30
- option ["--yaml", "-Y"], :flag, "output data in YAML format" do
31
- self.output_format = "YAML"
32
- end
22
+ include DataOutput
33
23
 
34
24
  option ["--debug"], :flag, "enable debugging"
35
25
 
@@ -70,34 +60,6 @@ module Swa
70
60
  super(arguments)
71
61
  end
72
62
 
73
- def output_format=(arg)
74
- arg = arg.upcase
75
- unless %w(JSON YAML).member?(arg)
76
- raise ArgumentError, "unrecognised data format: #{arg.inspect}"
77
- end
78
- @output_format = arg
79
- end
80
-
81
- def format_data(data)
82
- case output_format
83
- when "JSON"
84
- MultiJson.dump(data, :pretty => true)
85
- when "YAML"
86
- YAML.dump(data)
87
- else
88
- raise "bad output format: #{output_format}"
89
- end
90
- end
91
-
92
- def display_data(data, jmespath_expression = nil)
93
- unless jmespath_expression.nil?
94
- data = JMESPath.search(jmespath_expression, data)
95
- end
96
- puts format_data(data)
97
- rescue JMESPath::Errors::SyntaxError => e
98
- signal_error("invalid JMESPath expression")
99
- end
100
-
101
63
  def parse_datetime(datetime_string)
102
64
  result = Chronic.parse(datetime_string, :guess => false, :endian_precedence => :little)
103
65
  raise ArgumentError, "unrecognised date/time #{datetime_string.inspect}" unless result
@@ -0,0 +1,56 @@
1
+ require "clamp"
2
+
3
+ module Swa
4
+ module CLI
5
+
6
+ module DataOutput
7
+
8
+ extend Clamp::Option::Declaration
9
+
10
+ option "--format", "FORMAT", "format for data output",
11
+ :attribute_name => :output_format,
12
+ :environment_variable => "SWA_OUTPUT_FORMAT",
13
+ :default => "YAML"
14
+
15
+ option ["--json", "-J"], :flag, "output data in JSON format" do
16
+ self.output_format = "JSON"
17
+ end
18
+
19
+ option ["--yaml", "-Y"], :flag, "output data in YAML format" do
20
+ self.output_format = "YAML"
21
+ end
22
+
23
+ def output_format=(arg)
24
+ arg = arg.upcase
25
+ unless %w(JSON YAML).member?(arg)
26
+ raise ArgumentError, "unrecognised data format: #{arg.inspect}"
27
+ end
28
+ @output_format = arg
29
+ end
30
+
31
+ protected
32
+
33
+ def format_data(data)
34
+ case output_format
35
+ when "JSON"
36
+ MultiJson.dump(data, :pretty => true)
37
+ when "YAML"
38
+ YAML.dump(data)
39
+ else
40
+ raise "bad output format: #{output_format}"
41
+ end
42
+ end
43
+
44
+ def display_data(data, jmespath_expression = nil)
45
+ unless jmespath_expression.nil?
46
+ data = JMESPath.search(jmespath_expression, data)
47
+ end
48
+ puts format_data(data)
49
+ rescue JMESPath::Errors::SyntaxError => e
50
+ signal_error("invalid JMESPath expression")
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
@@ -8,7 +8,9 @@ require "swa/ec2/instance"
8
8
  require "swa/ec2/key_pair"
9
9
  require "swa/ec2/security_group"
10
10
  require "swa/ec2/snapshot"
11
+ require "swa/ec2/subnet"
11
12
  require "swa/ec2/volume"
13
+ require "swa/ec2/vpc"
12
14
 
13
15
  module Swa
14
16
  module CLI
@@ -289,6 +291,37 @@ module Swa
289
291
 
290
292
  end
291
293
 
294
+ subcommand ["subnet"], "Show subnet" do
295
+
296
+ parameter "SUBNET-ID", "subnet id"
297
+
298
+ include ItemBehaviour
299
+
300
+ private
301
+
302
+ def subnet
303
+ Swa::EC2::Subnet.new(ec2.subnet(subnet_id))
304
+ end
305
+
306
+ alias_method :item, :subnet
307
+
308
+ end
309
+
310
+ subcommand ["subnets"], "List subnets" do
311
+
312
+ include TagFilterOptions
313
+ include CollectionBehaviour
314
+
315
+ private
316
+
317
+ def subnets
318
+ query_for(:subnets, Swa::EC2::Subnet)
319
+ end
320
+
321
+ alias_method :collection, :subnets
322
+
323
+ end
324
+
292
325
  subcommand ["volume", "vol"], "Show volume" do
293
326
 
294
327
  parameter "VOLUME-ID", "volume id"
@@ -324,6 +357,41 @@ module Swa
324
357
 
325
358
  end
326
359
 
360
+ subcommand ["vpc"], "Show vpc" do
361
+
362
+ parameter "VPC-ID", "vpc id"
363
+
364
+ include ItemBehaviour
365
+
366
+ private
367
+
368
+ def vpc
369
+ Swa::EC2::Vpc.new(ec2.vpc(vpc_id))
370
+ end
371
+
372
+ alias_method :item, :vpc
373
+
374
+ end
375
+
376
+ subcommand ["vpcs"], "List vpcs" do
377
+
378
+ include TagFilterOptions
379
+ include CollectionBehaviour
380
+
381
+ option "--named", "NAME", "with matching name" do |name|
382
+ add_tag_filter("Name", name)
383
+ end
384
+
385
+ private
386
+
387
+ def vpcs
388
+ query_for(:vpcs, Swa::EC2::Vpc)
389
+ end
390
+
391
+ alias_method :collection, :vpcs
392
+
393
+ end
394
+
327
395
  protected
328
396
 
329
397
  def ec2
@@ -12,7 +12,7 @@ module Swa
12
12
  [
13
13
  pad(s.snapshot_id, 13),
14
14
  pad(s.volume_id, 12),
15
- sprintf("%4d", s.volume_size),
15
+ sprintf("%5d", s.volume_size),
16
16
  s.start_time.iso8601,
17
17
  rpad(s.progress, 4),
18
18
  quoted(s.description)
@@ -0,0 +1,32 @@
1
+ require "swa/ec2/tagged_resource"
2
+ require "swa/resource"
3
+
4
+ module Swa
5
+ module EC2
6
+
7
+ class Subnet < Resource
8
+
9
+ include TaggedResource
10
+
11
+ def summary
12
+ [
13
+ pad(subnet.subnet_id, 15),
14
+ pad(subnet.vpc_id, 12),
15
+ pad(subnet.availability_zone, 15),
16
+ pad(subnet.cidr_block, 18),
17
+ quoted(name)
18
+ ].join(" ")
19
+ end
20
+
21
+ def name
22
+ tags["Name"]
23
+ end
24
+
25
+ private
26
+
27
+ alias_method :subnet, :aws_resource
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -12,7 +12,7 @@ module Swa
12
12
  [
13
13
  pad(v.volume_id, 12),
14
14
  pad(v.snapshot_id, 13),
15
- sprintf("%4d", v.size),
15
+ sprintf("%5d", v.size),
16
16
  pad(v.volume_type, 9),
17
17
  pad(attachment.instance_id, 10),
18
18
  pad(attachment.device, 9),
@@ -0,0 +1,35 @@
1
+ require "swa/ec2/tagged_resource"
2
+ require "swa/resource"
3
+
4
+ module Swa
5
+ module EC2
6
+
7
+ class Vpc < Resource
8
+
9
+ include TaggedResource
10
+
11
+ def summary
12
+ [
13
+ pad(vpc.vpc_id, 12),
14
+ pad(default_marker, 1),
15
+ pad(vpc.cidr_block, 18),
16
+ quoted(name)
17
+ ].join(" ")
18
+ end
19
+
20
+ def name
21
+ tags["Name"]
22
+ end
23
+
24
+ def default_marker
25
+ "*" if vpc.is_default
26
+ end
27
+
28
+ private
29
+
30
+ alias_method :vpc, :aws_resource
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Swa
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-29 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,6 +143,7 @@ files:
143
143
  - lib/swa.rb
144
144
  - lib/swa/cli/base_command.rb
145
145
  - lib/swa/cli/collection_behaviour.rb
146
+ - lib/swa/cli/data_output.rb
146
147
  - lib/swa/cli/ec2_command.rb
147
148
  - lib/swa/cli/filter_options.rb
148
149
  - lib/swa/cli/item_behaviour.rb
@@ -155,8 +156,10 @@ files:
155
156
  - lib/swa/ec2/key_pair.rb
156
157
  - lib/swa/ec2/security_group.rb
157
158
  - lib/swa/ec2/snapshot.rb
159
+ - lib/swa/ec2/subnet.rb
158
160
  - lib/swa/ec2/tagged_resource.rb
159
161
  - lib/swa/ec2/volume.rb
162
+ - lib/swa/ec2/vpc.rb
160
163
  - lib/swa/resource.rb
161
164
  - lib/swa/version.rb
162
165
  - swa.gemspec