vmware-vra 2.7.0 → 3.0.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/CHANGELOG.md +27 -1
  4. data/README.md +91 -141
  5. data/Rakefile +1 -12
  6. data/lib/vra/catalog.rb +39 -8
  7. data/lib/vra/catalog_base.rb +62 -0
  8. data/lib/vra/catalog_item.rb +29 -75
  9. data/lib/vra/catalog_source.rb +116 -0
  10. data/lib/vra/catalog_type.rb +56 -0
  11. data/lib/vra/client.rb +72 -53
  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 +2 -2
  16. data/lib/vra/http.rb +20 -7
  17. data/lib/vra/request.rb +28 -36
  18. data/lib/vra/request_parameters.rb +12 -10
  19. data/lib/vra/resource.rb +33 -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 +287 -228
  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 +2 -4
  44. metadata +42 -32
  45. data/.travis.yml +0 -14
  46. data/lib/vra/catalog_request.rb +0 -127
  47. data/lib/vra/requests.rb +0 -41
  48. data/spec/catalog_request_spec.rb +0 -265
  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.0
4
+ version: 3.0.1
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: 2019-05-10 00:00:00.000000000 Z
12
+ date: 2022-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl
@@ -43,14 +43,14 @@ dependencies:
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1.7'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.7'
56
56
  - !ruby/object:Gem::Dependency
@@ -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.0.3
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,127 +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
- module Vra
22
- class CatalogRequest
23
- attr_reader :catalog_id, :catalog_item, :client, :custom_fields
24
- attr_writer :subtenant_id, :template_payload
25
- attr_accessor :cpus, :memory, :requested_for, :lease_days, :notes
26
-
27
- def initialize(client, catalog_id, opts = {})
28
- @client = client
29
- @catalog_id = catalog_id
30
- @cpus = opts[:cpus]
31
- @memory = opts[:memory]
32
- @requested_for = opts[:requested_for]
33
- @lease_days = opts[:lease_days]
34
- @notes = opts[:notes]
35
- @subtenant_id = opts[:subtenant_id]
36
- @additional_params = opts[:additional_params] || Vra::RequestParameters.new
37
- @catalog_item = Vra::CatalogItem.new(client, id: catalog_id)
38
- end
39
-
40
- # @param payload_file [String] - A json payload that represents the catalog template you want to merge with this request
41
- # @param client [Vra::Client] - a vra client object
42
- # @return [Vra::CatalogRequest] - a request with the given payload merged
43
- def self.request_from_payload(client, payload_file)
44
- hash_payload = JSON.parse(File.read(payload_file))
45
- catalog_id = hash_payload["catalogItemId"]
46
- blueprint_name = hash_payload["data"].select { |_k, v| v.is_a?(Hash) }.keys.first
47
- blueprint_data = hash_payload["data"][blueprint_name]
48
- opts = {}
49
- opts[:cpus] = blueprint_data["data"]["cpu"]
50
- opts[:memory] = blueprint_data["data"]["memory"]
51
- opts[:requested_for] = hash_payload["requestedFor"]
52
- opts[:lease_days] = blueprint_data.fetch("leaseDays", nil) || hash_payload["data"].fetch("_lease_days", 1)
53
- opts[:description] = hash_payload["description"]
54
- opts[:subtenant_id] = hash_payload["businessGroupId"]
55
- cr = Vra::CatalogRequest.new(client, catalog_id, opts)
56
- cr.template_payload = File.read(payload_file)
57
- cr
58
- end
59
-
60
- def set_parameter(key, type, value)
61
- @additional_params.set(key, type, value)
62
- end
63
-
64
- def set_parameters(key, value_data)
65
- @additional_params.set_parameters(key, value_data)
66
- end
67
-
68
- def delete_parameter(key)
69
- @additional_params.delete(key)
70
- end
71
-
72
- def parameters
73
- @additional_params.to_vra
74
- end
75
-
76
- def subtenant_id
77
- @subtenant_id || catalog_item.subtenant_id
78
- end
79
-
80
- def validate_params!
81
- missing_params = []
82
- [ :catalog_id, :cpus, :memory, :requested_for, :subtenant_id ].each do |param|
83
- missing_params << param.to_s if send(param).nil?
84
- end
85
-
86
- raise ArgumentError, "Unable to submit request, required param(s) missing => #{missing_params.join(', ')}" unless missing_params.empty?
87
- end
88
-
89
- # @return [String] - the current catalog template payload merged with the settings applied from this request
90
- # @param [String] - A json payload that represents the catalog template you want to merge with this request
91
- def merge_payload(payload)
92
- hash_payload = JSON.parse(payload)
93
- blueprint_name = hash_payload["data"].select { |_k, v| v.is_a?(Hash) }.keys.first
94
- hash_payload["data"][blueprint_name]["data"]["cpu"] = @cpus
95
- hash_payload["data"][blueprint_name]["data"]["memory"] = @memory
96
- hash_payload["requestedFor"] = @requested_for
97
- hash_payload["data"]["_leaseDays"] = @lease_days
98
- hash_payload["description"] = @notes
99
- hash_payload["data"][blueprint_name]["data"].merge!(parameters["data"]) unless parameters.empty?
100
- hash_payload.to_json
101
- end
102
-
103
- # @return [String] - the current catalog template payload merged with the settings applied from this request
104
- def merged_payload
105
- merge_payload(template_payload)
106
- end
107
-
108
- # @return [String] - the current catalog template payload from VRA or custom payload set in JSON format
109
- def template_payload
110
- @template_payload ||= Vra::CatalogItem.dump_template(client, @catalog_id)
111
- end
112
-
113
- # @return [Vra::Request] - submits and returns the request, validating before hand
114
- def submit
115
- validate_params!
116
- begin
117
- post_response = client.http_post("/catalog-service/api/consumer/entitledCatalogItems/#{@catalog_id}/requests", merged_payload)
118
- rescue Vra::Exception::HTTPError => e
119
- raise Vra::Exception::RequestError, "Unable to submit request: #{e.errors.join(', ')}"
120
- rescue
121
- raise
122
- end
123
- request_id = JSON.parse(post_response.body)["id"]
124
- Vra::Request.new(client, request_id)
125
- end
126
- end
127
- 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,265 +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
-
140
- template = File.read("spec/fixtures/resource/catalog_request.json")
141
- payload = JSON.parse(request.merge_payload(template))
142
- param1 = payload["data"]["my_blueprint"]["data"]["param1"]
143
- param2 = payload["data"]["my_blueprint"]["data"]["param2"]
144
- expect(param1).to be_a(String)
145
- expect(param2).to be_a(Integer)
146
- expect(param1).to eq "my string"
147
- expect(param2).to eq 2468
148
- end
149
-
150
- it "properly handles additional nested parameters" do
151
- request.set_parameter("BP1~param1", "string", "my string")
152
- request.set_parameter("BP1~BP2~param2", "integer", 2468)
153
-
154
- template = File.read("spec/fixtures/resource/catalog_request.json")
155
- payload = JSON.parse(request.merge_payload(template))
156
- param1 = payload["data"]["my_blueprint"]["data"]["BP1"]["data"]["param1"]
157
- param2 = payload["data"]["my_blueprint"]["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
158
- expect(param1).to be_a(String)
159
- expect(param2).to be_a(Integer)
160
- expect(param1).to eq "my string"
161
- expect(param2).to eq 2468
162
- end
163
-
164
- it "properly handles nested parameters" do
165
- parameters = {
166
- "BP1" => {
167
- "param1" => {
168
- type: "string",
169
- value: "my string",
170
- },
171
- "BP2" => {
172
- "param2" => {
173
- type: "integer",
174
- value: 2468,
175
- },
176
- },
177
- },
178
- }
179
-
180
- parameters.each do |k, v|
181
- request.set_parameters(k, v)
182
- end
183
-
184
- template = File.read("spec/fixtures/resource/catalog_request.json")
185
- payload = JSON.parse(request.merge_payload(template))
186
- param1 = payload["data"]["my_blueprint"]["data"]["BP1"]["data"]["param1"]
187
- param2 = payload["data"]["my_blueprint"]["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
188
-
189
- expect(param1).to be_a(String)
190
- expect(param2).to be_a(Integer)
191
- expect(param1).to eq "my string"
192
- expect(param2).to eq 2468
193
- end
194
- end
195
-
196
- describe "#submit" do
197
- let(:response) do
198
- double("response", code: 200, body: { id: "12345678910" }.to_json)
199
- end
200
-
201
- before do
202
- allow(request).to receive(:request_payload).and_return({})
203
- allow(client).to receive(:authorize!).and_return(true)
204
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}").and_return(response)
205
- allow(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests/template")
206
- .and_return(request_template_response)
207
- end
208
-
209
- it "calls http_get template" do
210
- expect(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests/template")
211
- .and_return(request_template_response)
212
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
213
- request.submit
214
- end
215
-
216
- it "calls http_post" do
217
- expect(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
218
- request.submit
219
- end
220
-
221
- it "returns Vra::Request" do
222
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
223
- expect(request.submit).to be_a(Vra::Request)
224
- end
225
- end
226
- end
227
-
228
- describe "merges payload" do
229
- let(:request) do
230
- client.catalog.request("catalog-12345",
231
- cpus: 2,
232
- memory: 1024,
233
- lease_days: 15,
234
- requested_for: "tester@corp.local",
235
- notes: "test notes")
236
- end
237
- before(:each) do
238
- allow(Vra::CatalogItem).to receive(:dump_template).and_return({ data2: { key2: "value2" } }.merge(catalog_item_payload).to_json)
239
- end
240
-
241
- it "without catalog template" do
242
- request.template_payload = { data2: { key1: "value1" } }.merge(catalog_item_payload).to_json
243
- template = JSON.parse(request.merged_payload)
244
- expect(template["data2"].keys).to_not include("key2")
245
- end
246
-
247
- it "with catalog template" do
248
- request.template_payload = nil
249
- template = JSON.parse(request.merged_payload)
250
- expect(template["data2"].keys).to include("key2")
251
- end
252
- end
253
-
254
- it "creates request" do
255
- payload_file = File.join(fixtures_dir, "catalog_request_template.json")
256
- expect(Vra::CatalogRequest.request_from_payload(client, payload_file)).to be_a(Vra::CatalogRequest)
257
- end
258
-
259
- it "creates request with correct payload" do
260
- payload_file = File.join(fixtures_dir, "catalog_request_template.json")
261
- cr = Vra::CatalogRequest.request_from_payload(client, payload_file)
262
- data = JSON.parse(cr.merged_payload)
263
- expect(data["data"]["superduper_key"]).to eq("superduper_value")
264
- end
265
- 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