vmware-vra 2.7.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +79 -144
  5. data/Rakefile +0 -11
  6. data/lib/vra/catalog.rb +39 -8
  7. data/lib/vra/catalog_base.rb +62 -0
  8. data/lib/vra/catalog_item.rb +28 -74
  9. data/lib/vra/catalog_source.rb +116 -0
  10. data/lib/vra/catalog_type.rb +56 -0
  11. data/lib/vra/client.rb +62 -54
  12. data/lib/vra/deployment.rb +155 -0
  13. data/lib/vra/deployment_request.rb +117 -0
  14. data/lib/vra/{resources.rb → deployments.rb} +26 -17
  15. data/lib/vra/exceptions.rb +1 -1
  16. data/lib/vra/http.rb +11 -6
  17. data/lib/vra/request.rb +28 -36
  18. data/lib/vra/request_parameters.rb +12 -12
  19. data/lib/vra/resource.rb +32 -203
  20. data/lib/vra/version.rb +2 -2
  21. data/lib/vra.rb +15 -12
  22. data/spec/catalog_item_spec.rb +64 -222
  23. data/spec/catalog_source_spec.rb +178 -0
  24. data/spec/catalog_spec.rb +112 -72
  25. data/spec/catalog_type_spec.rb +114 -0
  26. data/spec/client_spec.rb +271 -226
  27. data/spec/deployment_request_spec.rb +192 -0
  28. data/spec/deployment_spec.rb +227 -0
  29. data/spec/deployments_spec.rb +80 -0
  30. data/spec/fixtures/resource/sample_catalog_item.json +18 -0
  31. data/spec/fixtures/resource/sample_catalog_item_2.json +18 -0
  32. data/spec/fixtures/resource/sample_catalog_source.json +20 -0
  33. data/spec/fixtures/resource/sample_catalog_type.json +49 -0
  34. data/spec/fixtures/resource/sample_dep_actions.json +58 -0
  35. data/spec/fixtures/resource/sample_dep_request.json +19 -0
  36. data/spec/fixtures/resource/sample_dep_resource.json +112 -0
  37. data/spec/fixtures/resource/sample_deployment.json +26 -0
  38. data/spec/fixtures/resource/sample_entitlements.json +25 -0
  39. data/spec/http_spec.rb +63 -61
  40. data/spec/request_spec.rb +62 -68
  41. data/spec/resource_spec.rb +71 -390
  42. data/spec/spec_helper.rb +10 -4
  43. data/vmware-vra.gemspec +0 -1
  44. metadata +40 -30
  45. data/.travis.yml +0 -14
  46. data/lib/vra/catalog_request.rb +0 -137
  47. data/lib/vra/requests.rb +0 -41
  48. data/spec/catalog_request_spec.rb +0 -268
  49. data/spec/requests_spec.rb +0 -60
  50. data/spec/resources_spec.rb +0 -71
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmware-vra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Leff
8
8
  - JJ Asghar
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-26 00:00:00.000000000 Z
12
+ date: 2022-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl
@@ -67,20 +67,6 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: github_changelog_generator
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: pry
86
72
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +134,6 @@ files:
148
134
  - ".github/PULL_REQUEST_TEMPLATE.md"
149
135
  - ".gitignore"
150
136
  - ".rubocop.yml"
151
- - ".travis.yml"
152
137
  - CHANGELOG.md
153
138
  - Gemfile
154
139
  - LICENSE.txt
@@ -156,21 +141,28 @@ files:
156
141
  - Rakefile
157
142
  - lib/vra.rb
158
143
  - lib/vra/catalog.rb
144
+ - lib/vra/catalog_base.rb
159
145
  - lib/vra/catalog_item.rb
160
- - lib/vra/catalog_request.rb
146
+ - lib/vra/catalog_source.rb
147
+ - lib/vra/catalog_type.rb
161
148
  - lib/vra/client.rb
149
+ - lib/vra/deployment.rb
150
+ - lib/vra/deployment_request.rb
151
+ - lib/vra/deployments.rb
162
152
  - lib/vra/exceptions.rb
163
153
  - lib/vra/http.rb
164
154
  - lib/vra/request.rb
165
155
  - lib/vra/request_parameters.rb
166
- - lib/vra/requests.rb
167
156
  - lib/vra/resource.rb
168
- - lib/vra/resources.rb
169
157
  - lib/vra/version.rb
170
158
  - spec/catalog_item_spec.rb
171
- - spec/catalog_request_spec.rb
159
+ - spec/catalog_source_spec.rb
172
160
  - spec/catalog_spec.rb
161
+ - spec/catalog_type_spec.rb
173
162
  - spec/client_spec.rb
163
+ - spec/deployment_request_spec.rb
164
+ - spec/deployment_spec.rb
165
+ - spec/deployments_spec.rb
174
166
  - spec/fixtures/catalog_request_template.json
175
167
  - spec/fixtures/resource/catalog_request.json
176
168
  - spec/fixtures/resource/ip_address.txt
@@ -178,21 +170,28 @@ files:
178
170
  - spec/fixtures/resource/no_ip_address.txt
179
171
  - spec/fixtures/resource/non_vm_resource.json
180
172
  - spec/fixtures/resource/resource_response.json
173
+ - spec/fixtures/resource/sample_catalog_item.json
174
+ - spec/fixtures/resource/sample_catalog_item_2.json
175
+ - spec/fixtures/resource/sample_catalog_source.json
176
+ - spec/fixtures/resource/sample_catalog_type.json
177
+ - spec/fixtures/resource/sample_dep_actions.json
178
+ - spec/fixtures/resource/sample_dep_request.json
179
+ - spec/fixtures/resource/sample_dep_resource.json
180
+ - spec/fixtures/resource/sample_deployment.json
181
+ - spec/fixtures/resource/sample_entitlements.json
181
182
  - spec/fixtures/resource/vm_properties.json
182
183
  - spec/fixtures/resource/vm_resource.json
183
184
  - spec/fixtures/resource/vm_resource_no_operations.json
184
185
  - spec/http_spec.rb
185
186
  - spec/request_spec.rb
186
- - spec/requests_spec.rb
187
187
  - spec/resource_spec.rb
188
- - spec/resources_spec.rb
189
188
  - spec/spec_helper.rb
190
189
  - vmware-vra.gemspec
191
190
  homepage: https://github.com/chef-partners/vmware-vra-gem
192
191
  licenses:
193
192
  - Apache 2.0
194
193
  metadata: {}
195
- post_install_message:
194
+ post_install_message:
196
195
  rdoc_options: []
197
196
  require_paths:
198
197
  - lib
@@ -207,15 +206,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
206
  - !ruby/object:Gem::Version
208
207
  version: '0'
209
208
  requirements: []
210
- rubygems_version: 3.1.2
211
- signing_key:
209
+ rubygems_version: 3.2.32
210
+ signing_key:
212
211
  specification_version: 4
213
212
  summary: Client gem for interacting with VMware vRealize Automation.
214
213
  test_files:
215
214
  - spec/catalog_item_spec.rb
216
- - spec/catalog_request_spec.rb
215
+ - spec/catalog_source_spec.rb
217
216
  - spec/catalog_spec.rb
217
+ - spec/catalog_type_spec.rb
218
218
  - spec/client_spec.rb
219
+ - spec/deployment_request_spec.rb
220
+ - spec/deployment_spec.rb
221
+ - spec/deployments_spec.rb
219
222
  - spec/fixtures/catalog_request_template.json
220
223
  - spec/fixtures/resource/catalog_request.json
221
224
  - spec/fixtures/resource/ip_address.txt
@@ -223,12 +226,19 @@ test_files:
223
226
  - spec/fixtures/resource/no_ip_address.txt
224
227
  - spec/fixtures/resource/non_vm_resource.json
225
228
  - spec/fixtures/resource/resource_response.json
229
+ - spec/fixtures/resource/sample_catalog_item.json
230
+ - spec/fixtures/resource/sample_catalog_item_2.json
231
+ - spec/fixtures/resource/sample_catalog_source.json
232
+ - spec/fixtures/resource/sample_catalog_type.json
233
+ - spec/fixtures/resource/sample_dep_actions.json
234
+ - spec/fixtures/resource/sample_dep_request.json
235
+ - spec/fixtures/resource/sample_dep_resource.json
236
+ - spec/fixtures/resource/sample_deployment.json
237
+ - spec/fixtures/resource/sample_entitlements.json
226
238
  - spec/fixtures/resource/vm_properties.json
227
239
  - spec/fixtures/resource/vm_resource.json
228
240
  - spec/fixtures/resource/vm_resource_no_operations.json
229
241
  - spec/http_spec.rb
230
242
  - spec/request_spec.rb
231
- - spec/requests_spec.rb
232
243
  - spec/resource_spec.rb
233
- - spec/resources_spec.rb
234
244
  - spec/spec_helper.rb
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
- rvm:
5
- - 2.6.3
6
- branches:
7
- only:
8
- - master
9
- notifications:
10
- slack:
11
- on_success: change
12
- on_failure: always
13
- rooms:
14
- secure: SPX5JlKrlL3dpWUIRd/xxjId06D9OT7ig6qNlTH8bSoszw2t0QQ4X/m4iNmQ7ksMoqkvknc6y8HRVD7oJUgVYelBjZR+ayAdI+tlRvtU+CQdij+Xeamix3TwHgTWPzFmMoQl6zNkoLWRaXZ1DCRZi3/BPhXF0A9wGel4ToD6nBUe5chvvhWUltVFTxL0YmA537LWLqF+JyFWbr45Eo4EJXqo0i3Mz/1w1Ct7cDZjzIDsmPhchVYOdW1VA+rVC0oWiwGkx7KuX/QTs/D2XuL6xSRy/ftulgF+j/W8P3hgdjZaBlfm7UmEr/Df7nml8SXuo44hUB964EfLgTjg/EN8qYaZ9GhQ6xVuRuDGpoTc22kCUJqDWUFzlAbs/Og4qNP0FdZkofZPkvMG+C3JLwIKTDBNaG+DO+/19UZpcofPouQ5UOolFCkZcCwdMBHg2AecWFd4yMJ68giKd/zPdN/+ALxxK1RrOyk8JecvpolN/lhjnmR+zktJXaUikCzK3Zr2f2hXMVXULiGkMw5IRwiMor7nCIEBW5FqNP6mhV8JIDQguyLXy2wfCUBauhDR2VkV4pEFCCdRu+uPW8C80R1B3JmZn7q2KcX0WfsSoAntZh5ZedAXW+YoUKSnZR/X6RpxvRi/VSaX529BkyU07S52mS2xNW1HWgY2/laShHtMaAM=
@@ -1,137 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- require "vra/catalog_item"
20
-
21
- class ::Hash
22
- def deep_merge(second)
23
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
24
- merge(second, &merger)
25
- end
26
- end
27
-
28
- module Vra
29
- class CatalogRequest
30
- attr_reader :catalog_id, :catalog_item, :client, :custom_fields
31
- attr_writer :subtenant_id, :template_payload
32
- attr_accessor :cpus, :memory, :shirt_size, :requested_for, :lease_days, :notes
33
-
34
- def initialize(client, catalog_id, opts = {})
35
- @client = client
36
- @catalog_id = catalog_id
37
- @cpus = opts[:cpus]
38
- @memory = opts[:memory]
39
- @shirt_size = opts[:shirt_size]
40
- @requested_for = opts[:requested_for]
41
- @lease_days = opts[:lease_days]
42
- @notes = opts[:notes]
43
- @subtenant_id = opts[:subtenant_id]
44
- @additional_params = opts[:additional_params] || Vra::RequestParameters.new
45
- @catalog_item = Vra::CatalogItem.new(client, id: catalog_id)
46
- end
47
-
48
- # @param payload_file [String] - A json payload that represents the catalog template you want to merge with this request
49
- # @param client [Vra::Client] - a vra client object
50
- # @return [Vra::CatalogRequest] - a request with the given payload merged
51
- def self.request_from_payload(client, payload_file)
52
- hash_payload = JSON.parse(File.read(payload_file))
53
- catalog_id = hash_payload["catalogItemId"]
54
- blueprint_name = hash_payload["data"].select { |_k, v| v.is_a?(Hash) }.keys.first
55
- blueprint_data = hash_payload["data"][blueprint_name]
56
- opts = {}
57
- opts[:cpus] = blueprint_data["data"]["cpu"]
58
- opts[:memory] = blueprint_data["data"]["memory"]
59
- opts[:shirt_size] = blueprint_data["data"]["size"]
60
- opts[:requested_for] = hash_payload["requestedFor"]
61
- opts[:lease_days] = blueprint_data.fetch("leaseDays", nil) || hash_payload["data"].fetch("_lease_days", 1)
62
- opts[:description] = hash_payload["description"]
63
- opts[:subtenant_id] = hash_payload["businessGroupId"]
64
- cr = Vra::CatalogRequest.new(client, catalog_id, opts)
65
- cr.template_payload = File.read(payload_file)
66
- cr
67
- end
68
-
69
- def set_parameter(key, type, value)
70
- @additional_params.set(key, type, value)
71
- end
72
-
73
- def set_parameters(key, value_data)
74
- @additional_params.set_parameters(key, value_data)
75
- end
76
-
77
- def delete_parameter(key)
78
- @additional_params.delete(key)
79
- end
80
-
81
- def parameters
82
- @additional_params.to_vra
83
- end
84
-
85
- def subtenant_id
86
- @subtenant_id || catalog_item.subtenant_id
87
- end
88
-
89
- def validate_params!
90
- missing_params = []
91
- %i{catalog_id cpus memory requested_for subtenant_id }.each do |param|
92
- missing_params << param.to_s if send(param).nil?
93
- end
94
-
95
- raise ArgumentError, "Unable to submit request, required param(s) missing => #{missing_params.join(", ")}" unless missing_params.empty?
96
- end
97
-
98
- # @return [String] - the current catalog template payload merged with the settings applied from this request
99
- # @param [String] - A json payload that represents the catalog template you want to merge with this request
100
- def merge_payload(payload)
101
- hash_payload = JSON.parse(payload)
102
- blueprint_name = hash_payload["data"].select { |_k, v| v.is_a?(Hash) }.keys.first
103
- hash_payload["data"][blueprint_name]["data"]["cpu"] = @cpus
104
- hash_payload["data"][blueprint_name]["data"]["memory"] = @memory
105
- hash_payload["data"][blueprint_name]["data"]["size"] = @shirt_size
106
- hash_payload["requestedFor"] = @requested_for
107
- hash_payload["data"]["_leaseDays"] = @lease_days
108
- hash_payload["description"] = @notes
109
- hash_payload["data"] = hash_payload["data"].deep_merge(parameters["data"]) unless parameters.empty?
110
- hash_payload.to_json
111
- end
112
-
113
- # @return [String] - the current catalog template payload merged with the settings applied from this request
114
- def merged_payload
115
- merge_payload(template_payload)
116
- end
117
-
118
- # @return [String] - the current catalog template payload from VRA or custom payload set in JSON format
119
- def template_payload
120
- @template_payload ||= Vra::CatalogItem.dump_template(client, @catalog_id)
121
- end
122
-
123
- # @return [Vra::Request] - submits and returns the request, validating before hand
124
- def submit
125
- validate_params!
126
- begin
127
- post_response = client.http_post("/catalog-service/api/consumer/entitledCatalogItems/#{@catalog_id}/requests", merged_payload)
128
- rescue Vra::Exception::HTTPError => e
129
- raise Vra::Exception::RequestError, "Unable to submit request: #{e.errors.join(", ")}"
130
- rescue
131
- raise
132
- end
133
- request_id = JSON.parse(post_response.body)["id"]
134
- Vra::Request.new(client, request_id)
135
- end
136
- end
137
- end
data/lib/vra/requests.rb DELETED
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- module Vra
21
- class Requests
22
- def initialize(client)
23
- @client = client
24
- end
25
-
26
- def all_requests
27
- requests = []
28
-
29
- items = @client.http_get_paginated_array!("/catalog-service/api/consumer/requests")
30
- items.each do |item|
31
- requests << Vra::Request.new(@client, item["id"])
32
- end
33
-
34
- requests
35
- end
36
-
37
- def by_id(id)
38
- Vra::Request.new(@client, id)
39
- end
40
- end
41
- end
@@ -1,268 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "spec_helper"
21
-
22
- describe Vra::CatalogRequest do
23
- before(:each) do
24
- catalog_item = double("catalog_item")
25
- allow(catalog_item).to receive(:blueprint_id).and_return("catalog_blueprint")
26
- allow(catalog_item).to receive(:tenant_id).and_return("catalog_tenant")
27
- allow(catalog_item).to receive(:subtenant_id).and_return("catalog_subtenant")
28
- allow(Vra::CatalogItem).to receive(:new).and_return(catalog_item)
29
- end
30
-
31
- let(:client) do
32
- Vra::Client.new(username: "user@corp.local",
33
- password: "password",
34
- tenant: "tenant",
35
- base_url: "https://vra.corp.local")
36
- end
37
-
38
- let(:catalog_item_payload) do
39
- {
40
- "@type" => "CatalogItem",
41
- "id" => "9e98042e-5443-4082-afd5-ab5a32939bbc",
42
- "version" => 2,
43
- "name" => "CentOS 6.6",
44
- "description" => "Blueprint for deploying a CentOS Linux development server",
45
- "status" => "PUBLISHED",
46
- "statusName" => "Published",
47
- "organization" => {
48
- "tenantRef" => "vsphere.local",
49
- "tenantLabel" => "vsphere.local",
50
- "subtenantRef" => "962ab3f9-858c-4483-a49f-fa97392c314b",
51
- "subtenantLabel" => "catalog_subtenant",
52
- },
53
- "providerBinding" => {
54
- "bindingId" => "33af5413-4f20-4b3b-8268-32edad434dfb",
55
- "providerRef" => {
56
- "id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
57
- "label" => "iaas-service",
58
- },
59
- },
60
- "requestedFor" => "me@me.com",
61
- "data" => {
62
- "_leaseDays" => "2",
63
- "my_blueprint" => {
64
- "componentTypeId" => "com.vmware.csp.component.cafe.composition",
65
- "componentId" => nil,
66
- "classId" => "Blueprint.Component.Declaration",
67
- "typeFilter" => "",
68
- "data" => {
69
- "cpu" => "2",
70
- "memory" => "4096",
71
-
72
- },
73
- },
74
- },
75
- }
76
- end
77
-
78
- let(:request_template_response) do
79
- double("response", code: 200, body: catalog_item_payload.to_json)
80
- end
81
-
82
- context "when no subtenant ID is provided" do
83
- let(:request) do
84
- client.catalog.request("catalog-12345",
85
- cpus: 2,
86
- memory: 1024,
87
- lease_days: 15,
88
- requested_for: "tester@corp.local",
89
- notes: "test notes")
90
- end
91
-
92
- it "uses the subtenant ID from the catalog item" do
93
- expect(request.subtenant_id).to eq "catalog_subtenant"
94
- end
95
- end
96
-
97
- context "when subtenant is provided, and all shared tests" do
98
- let(:request) do
99
- client.catalog.request("catalog-12345",
100
- cpus: 2,
101
- memory: 1024,
102
- lease_days: 15,
103
- requested_for: "tester@corp.local",
104
- notes: "test notes",
105
- subtenant_id: "user_subtenant")
106
- end
107
-
108
- describe "#initialize" do
109
- it "sets the appropriate instance vars" do
110
- expect(request.catalog_id).to eq "catalog-12345"
111
- expect(request.cpus).to eq 2
112
- expect(request.memory).to eq 1024
113
- expect(request.lease_days).to eq 15
114
- expect(request.requested_for).to eq "tester@corp.local"
115
- expect(request.notes).to eq "test notes"
116
- expect(request.subtenant_id).to eq "user_subtenant"
117
- end
118
- end
119
-
120
- describe "#validate_params!" do
121
- context "when all required params are provided" do
122
- it "does not raise an exception" do
123
- expect { request.validate_params! }.to_not raise_error
124
- end
125
- end
126
-
127
- context "when a required parameter is not provided" do
128
- it "raises an exception" do
129
- request.cpus = nil
130
- expect { request.validate_params! }.to raise_error(ArgumentError)
131
- end
132
- end
133
- end
134
-
135
- describe "#merge_payload" do
136
- it "properly handles additional parameters" do
137
- request.set_parameter("param1", "string", "my string")
138
- request.set_parameter("param2", "integer", "2468")
139
- request.set_parameter("param3", "boolean", "true")
140
-
141
- template = File.read("spec/fixtures/resource/catalog_request.json")
142
- payload = JSON.parse(request.merge_payload(template))
143
- param1 = payload["data"]["param1"]
144
- param2 = payload["data"]["param2"]
145
- param3 = payload["data"]["param3"]
146
- expect(param1).to be_a(String)
147
- expect(param2).to be_a(Integer)
148
- expect(param1).to eq "my string"
149
- expect(param2).to eq 2468
150
- expect(param3).to be_truthy
151
- end
152
-
153
- it "properly handles additional nested parameters" do
154
- request.set_parameter("BP1~param1", "string", "my string")
155
- request.set_parameter("BP1~BP2~param2", "integer", 2468)
156
-
157
- template = File.read("spec/fixtures/resource/catalog_request.json")
158
- payload = JSON.parse(request.merge_payload(template))
159
- param1 = payload["data"]["BP1"]["data"]["param1"]
160
- param2 = payload["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
161
- expect(param1).to be_a(String)
162
- expect(param2).to be_a(Integer)
163
- expect(param1).to eq "my string"
164
- expect(param2).to eq 2468
165
- end
166
-
167
- it "properly handles nested parameters" do
168
- parameters = {
169
- "BP1" => {
170
- "param1" => {
171
- type: "string",
172
- value: "my string",
173
- },
174
- "BP2" => {
175
- "param2" => {
176
- type: "integer",
177
- value: 2468,
178
- },
179
- },
180
- },
181
- }
182
-
183
- parameters.each do |k, v|
184
- request.set_parameters(k, v)
185
- end
186
-
187
- template = File.read("spec/fixtures/resource/catalog_request.json")
188
- payload = JSON.parse(request.merge_payload(template))
189
- param1 = payload["data"]["BP1"]["data"]["param1"]
190
- param2 = payload["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
191
-
192
- expect(param1).to be_a(String)
193
- expect(param2).to be_a(Integer)
194
- expect(param1).to eq "my string"
195
- expect(param2).to eq 2468
196
- end
197
- end
198
-
199
- describe "#submit" do
200
- let(:response) do
201
- double("response", code: 200, body: { id: "12345678910" }.to_json)
202
- end
203
-
204
- before do
205
- allow(request).to receive(:request_payload).and_return({})
206
- allow(client).to receive(:authorize!).and_return(true)
207
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}").and_return(response)
208
- allow(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests/template")
209
- .and_return(request_template_response)
210
- end
211
-
212
- it "calls http_get template" do
213
- expect(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests/template")
214
- .and_return(request_template_response)
215
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
216
- request.submit
217
- end
218
-
219
- it "calls http_post" do
220
- expect(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
221
- request.submit
222
- end
223
-
224
- it "returns Vra::Request" do
225
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
226
- expect(request.submit).to be_a(Vra::Request)
227
- end
228
- end
229
- end
230
-
231
- describe "merges payload" do
232
- let(:request) do
233
- client.catalog.request("catalog-12345",
234
- cpus: 2,
235
- memory: 1024,
236
- lease_days: 15,
237
- requested_for: "tester@corp.local",
238
- notes: "test notes")
239
- end
240
- before(:each) do
241
- allow(Vra::CatalogItem).to receive(:dump_template).and_return({ data2: { key2: "value2" } }.merge(catalog_item_payload).to_json)
242
- end
243
-
244
- it "without catalog template" do
245
- request.template_payload = { data2: { key1: "value1" } }.merge(catalog_item_payload).to_json
246
- template = JSON.parse(request.merged_payload)
247
- expect(template["data2"].keys).to_not include("key2")
248
- end
249
-
250
- it "with catalog template" do
251
- request.template_payload = nil
252
- template = JSON.parse(request.merged_payload)
253
- expect(template["data2"].keys).to include("key2")
254
- end
255
- end
256
-
257
- it "creates request" do
258
- payload_file = File.join(fixtures_dir, "catalog_request_template.json")
259
- expect(Vra::CatalogRequest.request_from_payload(client, payload_file)).to be_a(Vra::CatalogRequest)
260
- end
261
-
262
- it "creates request with correct payload" do
263
- payload_file = File.join(fixtures_dir, "catalog_request_template.json")
264
- cr = Vra::CatalogRequest.request_from_payload(client, payload_file)
265
- data = JSON.parse(cr.merged_payload)
266
- expect(data["data"]["superduper_key"]).to eq("superduper_value")
267
- end
268
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "spec_helper"
21
-
22
- describe Vra::Requests do
23
- let(:client) do
24
- Vra::Client.new(username: "user@corp.local",
25
- password: "password",
26
- tenant: "tenant",
27
- base_url: "https://vra.corp.local")
28
- end
29
-
30
- let(:requests) { Vra::Requests.new(client) }
31
-
32
- describe "#all_resources" do
33
- it "calls the requests API endpoint" do
34
- expect(client).to receive(:http_get_paginated_array!)
35
- .with("/catalog-service/api/consumer/requests")
36
- .and_return([])
37
-
38
- requests.all_requests
39
- end
40
-
41
- it "returns an array of request objects" do
42
- allow(client).to receive(:http_get_paginated_array!)
43
- .with("/catalog-service/api/consumer/requests")
44
- .and_return([ { "id" => "1" }, { "id" => "2" } ])
45
-
46
- items = requests.all_requests
47
-
48
- expect(items[0]).to be_an_instance_of(Vra::Request)
49
- expect(items[1]).to be_an_instance_of(Vra::Request)
50
- end
51
- end
52
-
53
- describe "#by_id" do
54
- it "returns a request object" do
55
- expect(Vra::Request).to receive(:new).with(client, "12345")
56
-
57
- requests.by_id("12345")
58
- end
59
- end
60
- end