vmware-vra 2.1.0 → 2.1.1
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 +4 -4
- data/.rubocop.yml +5 -14
- data/CHANGELOG.md +8 -1
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +8 -5
- data/lib/vra.rb +11 -11
- data/lib/vra/catalog.rb +3 -3
- data/lib/vra/catalog_item.rb +14 -14
- data/lib/vra/catalog_request.rb +9 -9
- data/lib/vra/client.rb +29 -27
- data/lib/vra/exceptions.rb +5 -5
- data/lib/vra/http.rb +9 -9
- data/lib/vra/request.rb +6 -6
- data/lib/vra/request_parameters.rb +7 -7
- data/lib/vra/requests.rb +2 -2
- data/lib/vra/resource.rb +69 -69
- data/lib/vra/resources.rb +1 -1
- data/lib/vra/version.rb +1 -1
- data/spec/catalog_item_spec.rb +61 -61
- data/spec/catalog_request_spec.rb +61 -61
- data/spec/catalog_spec.rb +58 -58
- data/spec/client_spec.rb +187 -187
- data/spec/http_spec.rb +59 -59
- data/spec/request_spec.rb +43 -43
- data/spec/requests_spec.rb +15 -15
- data/spec/resource_spec.rb +163 -163
- data/spec/resources_spec.rb +15 -15
- data/spec/spec_helper.rb +2 -2
- data/vmware-vra.gemspec +18 -18
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c8bf64641b851d74d4d1ce864096bdc9cd7c4a8
|
4
|
+
data.tar.gz: 90ecdf6de5c11fadeb6c3662ea193e4505c5318c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1cdacf633b38f21eeec6f0223809d13808187844d04e5913f19b4134fa1a92fa0fdbe118a152b8bb44ed31a51b7b35b547321d728a23e51ab61fba97943565b
|
7
|
+
data.tar.gz: dcb8daf0f3ede01d089e7a55ff7f4ce32010079e64924a7f792cc7f9714b57a7174845981f39b87dd11a4e325617eaa381d6d7102bd0d72bbe31b1c72951b015
|
data/.rubocop.yml
CHANGED
@@ -1,14 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Max: 30
|
7
|
-
Style/Documentation:
|
8
|
-
Enabled: false
|
9
|
-
Style/SignalException:
|
10
|
-
Enabled: false
|
11
|
-
Style/SpaceAroundEqualsInParameterDefault:
|
12
|
-
EnforcedStyle: no_space
|
13
|
-
Style/SpaceInsideBrackets:
|
14
|
-
Enabled: false
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "spec/data/**/*"
|
4
|
+
- "vendor/**/*"
|
5
|
+
- "pkg/**/*"
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v2.1
|
3
|
+
## [v2.2.1](https://github.com/chef-partners/vmware-vra-gem/tree/)
|
4
4
|
|
5
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.1.0...v2.1.1)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Converted to chefstyle [\#41](https://github.com/chef-partners/vmware-vra-gem/pull/41) ([jjasghar](https://github.com/jjasghar))
|
10
|
+
|
11
|
+
## [v2.1.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.1.0) (2017-03-14)
|
5
12
|
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.0.0...v2.1.0)
|
6
13
|
|
7
14
|
**Merged pull requests:**
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# VMware vRA Gem
|
2
|
-
[](http://badge.fury.io/rb/vmware-vra)
|
3
3
|
[](https://travis-ci.org/chef-partners/vmware-vra-gem)
|
4
4
|
|
5
5
|
Client gem for interacting with VMware's vRealize Automation application.
|
data/Rakefile
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require "chefstyle"
|
5
|
+
require "rubocop/rake_task"
|
5
6
|
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
RuboCop::RakeTask.new
|
8
|
+
RuboCop::RakeTask.new do |task|
|
9
|
+
task.options << "--display-cop-names"
|
10
|
+
end
|
8
11
|
|
9
|
-
task default: [ :spec, :
|
12
|
+
task default: [ :spec, :rubocop ]
|
data/lib/vra.rb
CHANGED
@@ -17,14 +17,14 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
20
|
+
require "vra/catalog"
|
21
|
+
require "vra/catalog_item"
|
22
|
+
require "vra/catalog_request"
|
23
|
+
require "vra/client"
|
24
|
+
require "vra/exceptions"
|
25
|
+
require "vra/request"
|
26
|
+
require "vra/request_parameters"
|
27
|
+
require "vra/requests"
|
28
|
+
require "vra/resource"
|
29
|
+
require "vra/resources"
|
30
|
+
require "vra/version"
|
data/lib/vra/catalog.rb
CHANGED
@@ -26,13 +26,13 @@ module Vra
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def all_items
|
29
|
-
client.http_get_paginated_array!(
|
29
|
+
client.http_get_paginated_array!("/catalog-service/api/consumer/catalogItems")
|
30
30
|
.map! { |x| Vra::CatalogItem.new(client, data: x) }
|
31
31
|
end
|
32
32
|
|
33
33
|
def entitled_items
|
34
|
-
client.http_get_paginated_array!(
|
35
|
-
.map! { |x| Vra::CatalogItem.new(client, data: x[
|
34
|
+
client.http_get_paginated_array!("/catalog-service/api/consumer/entitledCatalogItems")
|
35
|
+
.map! { |x| Vra::CatalogItem.new(client, data: x["catalogItem"]) }
|
36
36
|
end
|
37
37
|
|
38
38
|
def request(*args)
|
data/lib/vra/catalog_item.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "ffi_yajl"
|
21
21
|
|
22
22
|
module Vra
|
23
23
|
class CatalogItem
|
@@ -28,17 +28,17 @@ module Vra
|
|
28
28
|
@catalog_item_data = opts[:data]
|
29
29
|
|
30
30
|
if @id.nil? && @catalog_item_data.nil?
|
31
|
-
raise ArgumentError,
|
31
|
+
raise ArgumentError, "must supply an id or a catalog item data hash"
|
32
32
|
end
|
33
33
|
|
34
34
|
if !@id.nil? && !@catalog_item_data.nil?
|
35
|
-
raise ArgumentError,
|
35
|
+
raise ArgumentError, "must supply an id OR a catalog item data hash, not both"
|
36
36
|
end
|
37
37
|
|
38
38
|
if @catalog_item_data.nil?
|
39
39
|
fetch_catalog_item
|
40
40
|
else
|
41
|
-
@id = @catalog_item_data[
|
41
|
+
@id = @catalog_item_data["id"]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -49,41 +49,41 @@ module Vra
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def name
|
52
|
-
@catalog_item_data[
|
52
|
+
@catalog_item_data["name"]
|
53
53
|
end
|
54
54
|
|
55
55
|
def description
|
56
|
-
@catalog_item_data[
|
56
|
+
@catalog_item_data["description"]
|
57
57
|
end
|
58
58
|
|
59
59
|
def status
|
60
|
-
@catalog_item_data[
|
60
|
+
@catalog_item_data["status"]
|
61
61
|
end
|
62
62
|
|
63
63
|
def organization
|
64
|
-
return {} if @catalog_item_data[
|
64
|
+
return {} if @catalog_item_data["organization"].nil?
|
65
65
|
|
66
|
-
@catalog_item_data[
|
66
|
+
@catalog_item_data["organization"]
|
67
67
|
end
|
68
68
|
|
69
69
|
def tenant_id
|
70
|
-
organization[
|
70
|
+
organization["tenantRef"]
|
71
71
|
end
|
72
72
|
|
73
73
|
def tenant_name
|
74
|
-
organization[
|
74
|
+
organization["tenantLabel"]
|
75
75
|
end
|
76
76
|
|
77
77
|
def subtenant_id
|
78
|
-
organization[
|
78
|
+
organization["subtenantRef"]
|
79
79
|
end
|
80
80
|
|
81
81
|
def subtenant_name
|
82
|
-
organization[
|
82
|
+
organization["subtenantLabel"]
|
83
83
|
end
|
84
84
|
|
85
85
|
def blueprint_id
|
86
|
-
@catalog_item_data[
|
86
|
+
@catalog_item_data["providerBinding"]["bindingId"]
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/vra/catalog_request.rb
CHANGED
@@ -23,7 +23,7 @@ module Vra
|
|
23
23
|
attr_writer :subtenant_id
|
24
24
|
attr_accessor :cpus, :memory, :requested_for, :lease_days, :notes
|
25
25
|
|
26
|
-
def initialize(client, catalog_id, opts={})
|
26
|
+
def initialize(client, catalog_id, opts = {})
|
27
27
|
@client = client
|
28
28
|
@catalog_id = catalog_id
|
29
29
|
@cpus = opts[:cpus]
|
@@ -64,16 +64,16 @@ module Vra
|
|
64
64
|
|
65
65
|
def merge_payload(payload)
|
66
66
|
hash_payload = JSON.parse(payload)
|
67
|
-
blueprint_name = hash_payload[
|
67
|
+
blueprint_name = hash_payload["data"].select { |_k, v| v.is_a?(Hash) }.keys.first
|
68
68
|
|
69
|
-
hash_payload[
|
70
|
-
hash_payload[
|
71
|
-
hash_payload[
|
72
|
-
hash_payload[
|
73
|
-
hash_payload[
|
69
|
+
hash_payload["data"][blueprint_name]["data"]["cpu"] = @cpus
|
70
|
+
hash_payload["data"][blueprint_name]["data"]["memory"] = @memory
|
71
|
+
hash_payload["requestedFor"] = @requested_for
|
72
|
+
hash_payload["data"]["_leaseDays"] = @lease_days
|
73
|
+
hash_payload["description"] = @notes
|
74
74
|
|
75
75
|
parameters.each do |param|
|
76
|
-
hash_payload[
|
76
|
+
hash_payload["data"][blueprint_name]["data"][param.key] = param.value
|
77
77
|
end
|
78
78
|
|
79
79
|
JSON.pretty_generate(hash_payload)
|
@@ -91,7 +91,7 @@ module Vra
|
|
91
91
|
raise
|
92
92
|
end
|
93
93
|
|
94
|
-
request_id = JSON.parse(post_response.body)[
|
94
|
+
request_id = JSON.parse(post_response.body)["id"]
|
95
95
|
Vra::Request.new(client, request_id)
|
96
96
|
end
|
97
97
|
end
|
data/lib/vra/client.rb
CHANGED
@@ -17,9 +17,9 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
20
|
+
require "ffi_yajl"
|
21
|
+
require "passwordmasker"
|
22
|
+
require "vra/http"
|
23
23
|
|
24
24
|
module Vra
|
25
25
|
# rubocop:disable ClassLength
|
@@ -70,24 +70,24 @@ module Vra
|
|
70
70
|
|
71
71
|
def bearer_token_request_body
|
72
72
|
{
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
"username" => @username,
|
74
|
+
"password" => @password.value,
|
75
|
+
"tenant" => @tenant,
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
79
|
def request_headers
|
80
80
|
headers = {}
|
81
|
-
headers[
|
82
|
-
headers[
|
83
|
-
headers[
|
81
|
+
headers["Accept"] = "application/json"
|
82
|
+
headers["Content-Type"] = "application/json"
|
83
|
+
headers["Authorization"] = "Bearer #{@bearer_token.value}" unless @bearer_token.value.nil?
|
84
84
|
headers
|
85
85
|
end
|
86
86
|
|
87
87
|
def authorize!
|
88
88
|
generate_bearer_token unless authorized?
|
89
89
|
|
90
|
-
raise Vra::Exception::Unauthorized,
|
90
|
+
raise Vra::Exception::Unauthorized, "Unable to authorize against vRA" unless authorized?
|
91
91
|
end
|
92
92
|
|
93
93
|
def authorized?
|
@@ -101,21 +101,21 @@ module Vra
|
|
101
101
|
@bearer_token.value = nil
|
102
102
|
validate_client_options!
|
103
103
|
|
104
|
-
response = http_post(
|
104
|
+
response = http_post("/identity/api/tokens",
|
105
105
|
FFI_Yajl::Encoder.encode(bearer_token_request_body),
|
106
106
|
:skip_auth)
|
107
107
|
unless response.success_ok?
|
108
108
|
raise Vra::Exception::Unauthorized, "Unable to get bearer token: #{response.body}"
|
109
109
|
end
|
110
110
|
|
111
|
-
@bearer_token.value = FFI_Yajl::Parser.parse(response.body)[
|
111
|
+
@bearer_token.value = FFI_Yajl::Parser.parse(response.body)["id"]
|
112
112
|
end
|
113
113
|
|
114
114
|
def full_url(path)
|
115
115
|
"#{@base_url}#{path}"
|
116
116
|
end
|
117
117
|
|
118
|
-
def http_fetch(method, path, skip_auth=nil)
|
118
|
+
def http_fetch(method, path, skip_auth = nil)
|
119
119
|
authorize! unless skip_auth
|
120
120
|
|
121
121
|
response = Vra::Http.execute(method: method,
|
@@ -128,11 +128,11 @@ module Vra
|
|
128
128
|
response
|
129
129
|
end
|
130
130
|
|
131
|
-
def http_head(path, skip_auth=nil)
|
131
|
+
def http_head(path, skip_auth = nil)
|
132
132
|
http_fetch(:head, path, skip_auth)
|
133
133
|
end
|
134
134
|
|
135
|
-
def http_get(path, skip_auth=nil)
|
135
|
+
def http_get(path, skip_auth = nil)
|
136
136
|
http_fetch(:get, path, skip_auth)
|
137
137
|
end
|
138
138
|
|
@@ -152,22 +152,24 @@ module Vra
|
|
152
152
|
|
153
153
|
loop do
|
154
154
|
response = get_parsed("#{base_path}&page=#{page}")
|
155
|
-
items += response[
|
155
|
+
items += response["content"]
|
156
156
|
|
157
|
-
break if page >= response[
|
157
|
+
break if page >= response["metadata"]["totalPages"]
|
158
158
|
page += 1
|
159
159
|
end
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
161
|
+
if items.uniq!
|
162
|
+
raise Vra::Exception::DuplicateItemsDetected,
|
163
|
+
"Duplicate items were returned by the vRA API. " \
|
164
|
+
"Increase your page size to avoid this vRA API bug. " \
|
165
|
+
"See https://github.com/chef-partners/vmware-vra-gem#pagination " \
|
166
|
+
"for more information."
|
167
|
+
end
|
166
168
|
|
167
169
|
items
|
168
170
|
end
|
169
171
|
|
170
|
-
def http_post(path, payload, skip_auth=nil)
|
172
|
+
def http_post(path, payload, skip_auth = nil)
|
171
173
|
authorize! unless skip_auth
|
172
174
|
|
173
175
|
response = Vra::Http.execute(method: :post,
|
@@ -200,14 +202,14 @@ module Vra
|
|
200
202
|
klass: caught_exception.class,
|
201
203
|
path: path)
|
202
204
|
|
203
|
-
message = exception.errors.empty? ? caught_exception.message : exception.errors.join(
|
205
|
+
message = exception.errors.empty? ? caught_exception.message : exception.errors.join(", ")
|
204
206
|
raise exception, message
|
205
207
|
end
|
206
208
|
|
207
209
|
def validate_client_options!
|
208
|
-
raise ArgumentError,
|
209
|
-
raise ArgumentError,
|
210
|
-
raise ArgumentError,
|
210
|
+
raise ArgumentError, "Username and password are required" if @username.nil? || @password.value.nil?
|
211
|
+
raise ArgumentError, "A tenant is required" if @tenant.nil?
|
212
|
+
raise ArgumentError, "A base URL is required" if @base_url.nil?
|
211
213
|
raise ArgumentError, "Base URL #{@base_url} is not a valid URI." unless valid_uri?(@base_url)
|
212
214
|
end
|
213
215
|
|
data/lib/vra/exceptions.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "ffi_yajl"
|
21
21
|
|
22
22
|
module Vra
|
23
23
|
module Exception
|
@@ -28,7 +28,7 @@ module Vra
|
|
28
28
|
|
29
29
|
class HTTPError < RuntimeError
|
30
30
|
attr_accessor :klass, :code, :body, :errors, :path
|
31
|
-
def initialize(opts={})
|
31
|
+
def initialize(opts = {})
|
32
32
|
@code = opts[:code]
|
33
33
|
@body = opts[:body]
|
34
34
|
@path = opts[:path]
|
@@ -46,10 +46,10 @@ module Vra
|
|
46
46
|
end
|
47
47
|
|
48
48
|
return if data.nil?
|
49
|
-
return unless data[
|
49
|
+
return unless data["errors"].respond_to?(:each)
|
50
50
|
|
51
|
-
data[
|
52
|
-
@errors << error[
|
51
|
+
data["errors"].each do |error|
|
52
|
+
@errors << error["systemMessage"]
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/lib/vra/http.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "net/http"
|
3
3
|
|
4
4
|
module Vra
|
5
5
|
module Http
|
@@ -7,7 +7,7 @@ module Vra
|
|
7
7
|
request = Request.new(params)
|
8
8
|
response = request.call
|
9
9
|
response = response.forward(request).call until response.final?
|
10
|
-
|
10
|
+
raise error(response) unless response.success?
|
11
11
|
response
|
12
12
|
end
|
13
13
|
|
@@ -35,15 +35,15 @@ module Vra
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def call
|
38
|
-
uri = URI(params[:url]) ||
|
38
|
+
uri = URI(params[:url]) || raise(":url required")
|
39
39
|
|
40
|
-
ssl_params = { use_ssl: uri.scheme ==
|
40
|
+
ssl_params = { use_ssl: uri.scheme == "https" }
|
41
41
|
ssl_params[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless verify_ssl?
|
42
42
|
|
43
43
|
Net::HTTP.start(uri.host, uri.port, ssl_params) do |http|
|
44
44
|
request = http_request(params[:method], uri)
|
45
45
|
request.initialize_http_header(params[:headers] || {})
|
46
|
-
request.body = params[:payload] ||
|
46
|
+
request.body = params[:payload] || ""
|
47
47
|
|
48
48
|
Response.new(http.request(request))
|
49
49
|
end
|
@@ -53,10 +53,10 @@ module Vra
|
|
53
53
|
type = {
|
54
54
|
get: Net::HTTP::Get,
|
55
55
|
head: Net::HTTP::Head,
|
56
|
-
post: Net::HTTP::Post
|
56
|
+
post: Net::HTTP::Post,
|
57
57
|
}.fetch(method, nil)
|
58
58
|
|
59
|
-
|
59
|
+
raise "Unknown HTTP method #{method}!" unless type
|
60
60
|
|
61
61
|
type.new(uri)
|
62
62
|
end
|
@@ -82,7 +82,7 @@ module Vra
|
|
82
82
|
|
83
83
|
def forward(request)
|
84
84
|
if redirect?
|
85
|
-
|
85
|
+
raise Http.error(self) unless request.redirectable?
|
86
86
|
request.redirect_to(location)
|
87
87
|
elsif see_other?
|
88
88
|
request.see_other(location)
|
@@ -92,7 +92,7 @@ module Vra
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def location
|
95
|
-
@response[
|
95
|
+
@response["location"]
|
96
96
|
end
|
97
97
|
|
98
98
|
def body
|