awful 0.0.95 → 0.0.96

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: 34dbb29593ea88811949beec598cfc225de269bc
4
- data.tar.gz: 7e123a61645aed0bedbe3675755f368950b572e2
3
+ metadata.gz: 20cf14fecdfbb426f917378fdb87a71c3d03b06d
4
+ data.tar.gz: 08cc9b0dc46451f3d57156272996521bcd5044ba
5
5
  SHA512:
6
- metadata.gz: 1a9ef4276d0c04d62f9c0dbf66311bdc3e1bcbf0c522766e406bbeddd014b6cfdf422506ea2d59482bab5535acba107271163a716e95efe8ed55457c4e6fd993
7
- data.tar.gz: 423f56071f4be30f7da82d9975d740a61ee9e12fc11f941688c4ad3989c9efb6a17d95cee8ecc7736ba6602356f168848c5dacf284ab97decb61e8b07a194b9d
6
+ metadata.gz: 6b38dbe10ec76867dcdcad38513053d6394aabef26d46b79f15ad2a34c2513e129823a3e0096c223a247c413cae5ddeaaa2555c2c445036a85ced8be5915cffc
7
+ data.tar.gz: d0aea0c0acbe2ad27c93e55eeadd1fabe2e5fec205ce5e45294a57a651032e6c86ebac64aa881ad8082ea813a56bc9f8f67a901ebcd744b5c520589b0f5027c0
@@ -82,18 +82,53 @@ module Awful
82
82
  end
83
83
 
84
84
  desc 'throughput NAME', 'get or update provisioned throughput for table NAME'
85
- method_option :read_capacity_units, aliases: '-r', type: :numeric, default: nil, desc: 'Read capacity units'
86
- method_option :write_capacity_units, aliases: '-w', type: :numeric, default: nil, desc: 'Write capacity units'
85
+ method_option :read_capacity_units, aliases: '-r', type: :numeric, default: nil, desc: 'Read capacity units'
86
+ method_option :write_capacity_units, aliases: '-w', type: :numeric, default: nil, desc: 'Write capacity units'
87
+ method_option :gsi, aliases: '-g', type: :array, default: [], desc: 'GSIs to update'
88
+ method_option :all, type: :boolean, default: false, desc: 'Update all GSIs for the table'
89
+ method_option :table, type: :boolean, default: true, desc: 'Update througput on table'
87
90
  def throughput(name)
88
- provisioned = dynamodb.describe_table(table_name: name).table.provisioned_throughput.to_h
89
- provisioned.merge!(symbolize_keys(options))
90
- if options.empty? # just print current throughput
91
- provisioned.tap do |p|
92
- puts YAML.dump(stringify_keys(p))
93
- end
94
- else # update from options
95
- dynamodb.update_table(table_name: name, provisioned_throughput: only_keys_matching(provisioned, %i[read_capacity_units write_capacity_units]))
91
+ table = dynamodb.describe_table(table_name: name).table
92
+
93
+ ## current is hash of current provisioned throughput
94
+ current = table.provisioned_throughput.to_h
95
+ table.global_secondary_indexes.each do |gsi|
96
+ current[gsi.index_name] = gsi.provisioned_throughput.to_h
97
+ end
98
+
99
+ ## if no updates requested, just print throughput and return table details
100
+ unless options[:read_capacity_units] or options[:write_capacity_units]
101
+ puts YAML.dump(stringify_keys(current))
102
+ return table
96
103
  end
104
+
105
+ ## parameters for update request
106
+ params = { table_name: name }
107
+
108
+ ## add table throughput unless told not to
109
+ params[:provisioned_throughput] = {
110
+ read_capacity_units: options[:read_capacity_units] || current[:read_capacity_units],
111
+ write_capacity_units: options[:write_capacity_units] || current[:write_capacity_units]
112
+ } if options[:table]
113
+
114
+ ## list of requested GSIs, or all for this table
115
+ gsis = options[:gsi]
116
+ gsis = table.global_secondary_indexes.map(&:index_name) if options[:all]
117
+ params[:global_secondary_index_updates] = gsis.map do |gsi|
118
+ {
119
+ update: {
120
+ index_name: gsi,
121
+ provisioned_throughput: {
122
+ read_capacity_units: options[:read_capacity_units] || current[gsi][:read_capacity_units],
123
+ write_capacity_units: options[:write_capacity_units] || current[gsi][:write_capacity_units]
124
+ }
125
+ }
126
+ }
127
+ end
128
+
129
+ ## make the update request
130
+ params.reject! { |_,v| v.empty? } # sdk hates empty global_secondary_index_updates
131
+ dynamodb.update_table(params)
97
132
  end
98
133
 
99
134
  desc 'enable_streams NAME', 'enable/disable streams on the table'
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.95'
2
+ VERSION = '0.0.96'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.95
4
+ version: 0.0.96
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler