vmware-vra 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +14 -0
- data/lib/vra/client.rb +10 -3
- data/lib/vra/exceptions.rb +1 -0
- data/lib/vra/version.rb +1 -1
- data/spec/client_spec.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01f8978ee0a6e0ed1865001f50876e122b5ee30f
|
4
|
+
data.tar.gz: ff5897d229cc674c2f5b3310c29bbe7857f6b55c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe516b37bc68296e53500270d3ac357d52ed176974e55ae539ab302f3cffa6453be5cc264c27f0b41ba1813027145d2ad99641ee9f545704213e827ee55b67ae
|
7
|
+
data.tar.gz: b94a9d038ea6dbe094b601baedd89fc2c0c26b455613699ffc88cad4556c8117d2244204a3671c336252a51bfbd6eb50d490975785eac7268c47d03fd8636f0d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## v1.2.0
|
2
|
+
* [pr#11](https://github.com/chef-partners/vmware-vra-gem/pull/11) Ability to set paginated results page size, which is a workaround for issue reported in #10 regarding duplicate items returned in paginated results.
|
3
|
+
|
1
4
|
## v1.1.0
|
2
5
|
* [pr#9](https://github.com/chef-partners/vmware-vra-gem/pull/9) Mask password and bearer token in console/debug/log output.
|
3
6
|
Thanks to [@rubytester](https://github.com/rubytester) for the idea and initial proposal to address in [pr#7](https://github.com/chef-partners/vmware-vra-gem/pull/7)
|
data/README.md
CHANGED
@@ -170,6 +170,20 @@ vra.resources.all_resources
|
|
170
170
|
vra.requests.all_requests
|
171
171
|
```
|
172
172
|
|
173
|
+
### Pagination
|
174
|
+
|
175
|
+
vRA paginates API requests where lists of items are returned. By default, this gem will ask vRA to provide items in groups of 20. However, as reported in [Issue 10](https://github.com/chef-partners/vmware-vra-gem/issues/10), it appears vRA may have a pagination bug. You can change the default page size from 20 to a value of your choice by passing in a `page_size` option when setting up the client:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
vra = Vra::Client.new(username: 'devmgr@corp.local', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true, page_size: 100)
|
179
|
+
```
|
180
|
+
|
181
|
+
... or setting `page_size` on the client object after you've created it:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
client.page_size = 100
|
185
|
+
```
|
186
|
+
|
173
187
|
## License and Authors
|
174
188
|
|
175
189
|
Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
data/lib/vra/client.rb
CHANGED
@@ -23,7 +23,7 @@ require 'passwordmasker'
|
|
23
23
|
module Vra
|
24
24
|
# rubocop:disable ClassLength
|
25
25
|
class Client
|
26
|
-
attr_accessor :bearer_token
|
26
|
+
attr_accessor :bearer_token, :page_size
|
27
27
|
|
28
28
|
def initialize(opts)
|
29
29
|
@base_url = opts[:base_url]
|
@@ -32,6 +32,7 @@ module Vra
|
|
32
32
|
@tenant = opts[:tenant]
|
33
33
|
@verify_ssl = opts.fetch(:verify_ssl, true)
|
34
34
|
@bearer_token = PasswordMasker.new(nil)
|
35
|
+
@page_size = opts.fetch(:page_size, 20)
|
35
36
|
|
36
37
|
validate_client_options!
|
37
38
|
end
|
@@ -138,10 +139,10 @@ module Vra
|
|
138
139
|
response.body
|
139
140
|
end
|
140
141
|
|
141
|
-
def http_get_paginated_array!(path
|
142
|
+
def http_get_paginated_array!(path)
|
142
143
|
items = []
|
143
144
|
page = 1
|
144
|
-
base_path = path + "?limit=#{
|
145
|
+
base_path = path + "?limit=#{page_size}"
|
145
146
|
|
146
147
|
loop do
|
147
148
|
response = FFI_Yajl::Parser.parse(http_get!("#{base_path}&page=#{page}"))
|
@@ -151,6 +152,12 @@ module Vra
|
|
151
152
|
page += 1
|
152
153
|
end
|
153
154
|
|
155
|
+
raise Vra::Exception::DuplicateItemsDetected,
|
156
|
+
'Duplicate items were returned by the vRA API. ' \
|
157
|
+
'Increase your page size to avoid this vRA API bug. ' \
|
158
|
+
'See https://github.com/chef-partners/vmware-vra-gem#pagination ' \
|
159
|
+
'for more information.' if items.uniq!
|
160
|
+
|
154
161
|
items
|
155
162
|
end
|
156
163
|
|
data/lib/vra/exceptions.rb
CHANGED
data/lib/vra/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -275,11 +275,12 @@ describe Vra::Client do
|
|
275
275
|
|
276
276
|
describe '#http_get_paginated_array!' do
|
277
277
|
it 'allows a limit override' do
|
278
|
+
client.page_size = 10
|
278
279
|
expect(client).to receive(:http_get!)
|
279
280
|
.with('/test?limit=10&page=1')
|
280
281
|
.and_return({ 'content' => [], 'metadata' => { 'totalPages' => 1 } }.to_json)
|
281
282
|
|
282
|
-
client.http_get_paginated_array!('/test'
|
283
|
+
client.http_get_paginated_array!('/test')
|
283
284
|
end
|
284
285
|
|
285
286
|
it 'only calls http_get! once when total pages is 0 (no items)' do
|
@@ -313,6 +314,14 @@ describe Vra::Client do
|
|
313
314
|
|
314
315
|
client.http_get_paginated_array!('/test')
|
315
316
|
end
|
317
|
+
|
318
|
+
it 'raises an exception if duplicate items are returned by the API' do
|
319
|
+
allow(client).to receive(:http_get!)
|
320
|
+
.with('/test?limit=20&page=1')
|
321
|
+
.and_return({ 'content' => [ 1, 2, 3, 1 ], 'metadata' => { 'totalPages' => 1 } }.to_json)
|
322
|
+
|
323
|
+
expect { client.http_get_paginated_array!('/test') }.to raise_error(Vra::Exception::DuplicateItemsDetected)
|
324
|
+
end
|
316
325
|
end
|
317
326
|
|
318
327
|
describe '#http_post' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmware-vra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Leff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|