vmware-vra 2.6.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -1
  3. data/CHANGELOG.md +35 -2
  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 +62 -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 +14 -13
  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 +272 -227
  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 +3 -5
  44. metadata +44 -36
  45. data/.travis.yml +0 -14
  46. data/Jenkinsfile +0 -31
  47. data/lib/vra/catalog_request.rb +0 -126
  48. data/lib/vra/requests.rb +0 -41
  49. data/spec/catalog_request_spec.rb +0 -267
  50. data/spec/requests_spec.rb +0 -60
  51. 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.6.1
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: 2018-07-31 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
@@ -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
@@ -129,14 +115,14 @@ dependencies:
129
115
  requirements:
130
116
  - - "~>"
131
117
  - !ruby/object:Gem::Version
132
- version: '1.21'
118
+ version: '3.5'
133
119
  type: :development
134
120
  prerelease: false
135
121
  version_requirements: !ruby/object:Gem::Requirement
136
122
  requirements:
137
123
  - - "~>"
138
124
  - !ruby/object:Gem::Version
139
- version: '1.21'
125
+ version: '3.5'
140
126
  description: Client gem for interacting with VMware vRealize Automation.
141
127
  email:
142
128
  - jj@chef.io
@@ -148,30 +134,35 @@ 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
- - Jenkinsfile
155
139
  - LICENSE.txt
156
140
  - README.md
157
141
  - Rakefile
158
142
  - lib/vra.rb
159
143
  - lib/vra/catalog.rb
144
+ - lib/vra/catalog_base.rb
160
145
  - lib/vra/catalog_item.rb
161
- - lib/vra/catalog_request.rb
146
+ - lib/vra/catalog_source.rb
147
+ - lib/vra/catalog_type.rb
162
148
  - lib/vra/client.rb
149
+ - lib/vra/deployment.rb
150
+ - lib/vra/deployment_request.rb
151
+ - lib/vra/deployments.rb
163
152
  - lib/vra/exceptions.rb
164
153
  - lib/vra/http.rb
165
154
  - lib/vra/request.rb
166
155
  - lib/vra/request_parameters.rb
167
- - lib/vra/requests.rb
168
156
  - lib/vra/resource.rb
169
- - lib/vra/resources.rb
170
157
  - lib/vra/version.rb
171
158
  - spec/catalog_item_spec.rb
172
- - spec/catalog_request_spec.rb
159
+ - spec/catalog_source_spec.rb
173
160
  - spec/catalog_spec.rb
161
+ - spec/catalog_type_spec.rb
174
162
  - spec/client_spec.rb
163
+ - spec/deployment_request_spec.rb
164
+ - spec/deployment_spec.rb
165
+ - spec/deployments_spec.rb
175
166
  - spec/fixtures/catalog_request_template.json
176
167
  - spec/fixtures/resource/catalog_request.json
177
168
  - spec/fixtures/resource/ip_address.txt
@@ -179,21 +170,28 @@ files:
179
170
  - spec/fixtures/resource/no_ip_address.txt
180
171
  - spec/fixtures/resource/non_vm_resource.json
181
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
182
182
  - spec/fixtures/resource/vm_properties.json
183
183
  - spec/fixtures/resource/vm_resource.json
184
184
  - spec/fixtures/resource/vm_resource_no_operations.json
185
185
  - spec/http_spec.rb
186
186
  - spec/request_spec.rb
187
- - spec/requests_spec.rb
188
187
  - spec/resource_spec.rb
189
- - spec/resources_spec.rb
190
188
  - spec/spec_helper.rb
191
189
  - vmware-vra.gemspec
192
190
  homepage: https://github.com/chef-partners/vmware-vra-gem
193
191
  licenses:
194
192
  - Apache 2.0
195
193
  metadata: {}
196
- post_install_message:
194
+ post_install_message:
197
195
  rdoc_options: []
198
196
  require_paths:
199
197
  - lib
@@ -208,16 +206,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
206
  - !ruby/object:Gem::Version
209
207
  version: '0'
210
208
  requirements: []
211
- rubyforge_project:
212
- rubygems_version: 2.5.1
213
- signing_key:
209
+ rubygems_version: 3.2.32
210
+ signing_key:
214
211
  specification_version: 4
215
212
  summary: Client gem for interacting with VMware vRealize Automation.
216
213
  test_files:
217
214
  - spec/catalog_item_spec.rb
218
- - spec/catalog_request_spec.rb
215
+ - spec/catalog_source_spec.rb
219
216
  - spec/catalog_spec.rb
217
+ - spec/catalog_type_spec.rb
220
218
  - spec/client_spec.rb
219
+ - spec/deployment_request_spec.rb
220
+ - spec/deployment_spec.rb
221
+ - spec/deployments_spec.rb
221
222
  - spec/fixtures/catalog_request_template.json
222
223
  - spec/fixtures/resource/catalog_request.json
223
224
  - spec/fixtures/resource/ip_address.txt
@@ -225,12 +226,19 @@ test_files:
225
226
  - spec/fixtures/resource/no_ip_address.txt
226
227
  - spec/fixtures/resource/non_vm_resource.json
227
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
228
238
  - spec/fixtures/resource/vm_properties.json
229
239
  - spec/fixtures/resource/vm_resource.json
230
240
  - spec/fixtures/resource/vm_resource_no_operations.json
231
241
  - spec/http_spec.rb
232
242
  - spec/request_spec.rb
233
- - spec/requests_spec.rb
234
243
  - spec/resource_spec.rb
235
- - spec/resources_spec.rb
236
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.3.1
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=
data/Jenkinsfile DELETED
@@ -1,31 +0,0 @@
1
- pipeline {
2
- agent {
3
- docker {
4
- args '-u root'
5
- image 'localhost:5000/jjkeysv3'
6
- }
7
-
8
- }
9
- triggers {
10
- pollSCM('H * * * *')
11
- }
12
- stages {
13
- stage('Pull down the ChefDK') {
14
- steps {
15
- sh '''apt-get update
16
- apt-get install -y curl sudo git build-essential
17
- curl -L https://chef.io/chef/install.sh | sudo bash -s -- -P chefdk -c current'''
18
- }
19
- }
20
- stage('Bundle') {
21
- steps {
22
- sh 'chef exec bundle install'
23
- }
24
- }
25
- stage('Rake') {
26
- steps {
27
- sh 'chef exec bundle exec rake '
28
- }
29
- }
30
- }
31
- }
@@ -1,126 +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
25
- attr_accessor :cpus, :memory, :requested_for, :lease_days, :notes, :template_payload
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
- end
100
-
101
- # @return [String] - the current catalog template payload merged with the settings applied from this request
102
- def merged_payload
103
- merge_payload(template_payload)
104
- end
105
-
106
- # @return [String] - the current catalog template payload from VRA or custom payload set in JSON format
107
- def template_payload
108
- @template_payload ||= Vra::CatalogItem.dump_template(client, @catalog_id)
109
- end
110
-
111
- # @return [Vra::Request] - submits and returns the request, validating before hand
112
- def submit
113
- validate_params!
114
-
115
- begin
116
- post_response = client.http_post("/catalog-service/api/consumer/entitledCatalogItems/#{@catalog_id}/requests", template_payload)
117
- rescue Vra::Exception::HTTPError => e
118
- raise Vra::Exception::RequestError, "Unable to submit request: #{e.errors.join(', ')}"
119
- rescue
120
- raise
121
- end
122
- request_id = JSON.parse(post_response.body)["id"]
123
- Vra::Request.new(client, request_id)
124
- end
125
- end
126
- 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,267 +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"]["param1"]
143
- param2 = payload["data"]["param2"]
144
-
145
- expect(param1).to be_a(String)
146
- expect(param2).to be_a(Integer)
147
- expect(param1).to eq "my string"
148
- expect(param2).to eq 2468
149
- end
150
-
151
- it "properly handles additional nested parameters" do
152
- request.set_parameter("BP1~param1", "string", "my string")
153
- request.set_parameter("BP1~BP2~param2", "integer", 2468)
154
-
155
- template = File.read("spec/fixtures/resource/catalog_request.json")
156
- payload = JSON.parse(request.merge_payload(template))
157
- param1 = payload["data"]["BP1"]["data"]["param1"]
158
- param2 = payload["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
159
-
160
- expect(param1).to be_a(String)
161
- expect(param2).to be_a(Integer)
162
- expect(param1).to eq "my string"
163
- expect(param2).to eq 2468
164
- end
165
-
166
- it "properly handles nested parameters" do
167
- parameters = {
168
- "BP1" => {
169
- "param1" => {
170
- type: "string",
171
- value: "my string",
172
- },
173
- "BP2" => {
174
- "param2" => {
175
- type: "integer",
176
- value: 2468,
177
- },
178
- },
179
- },
180
- }
181
-
182
- parameters.each do |k, v|
183
- request.set_parameters(k, v)
184
- end
185
-
186
- template = File.read("spec/fixtures/resource/catalog_request.json")
187
- payload = JSON.parse(request.merge_payload(template))
188
- param1 = payload["data"]["BP1"]["data"]["param1"]
189
- param2 = payload["data"]["BP1"]["data"]["BP2"]["data"]["param2"]
190
-
191
- expect(param1).to be_a(String)
192
- expect(param2).to be_a(Integer)
193
- expect(param1).to eq "my string"
194
- expect(param2).to eq 2468
195
- end
196
- end
197
-
198
- describe "#submit" do
199
- let(:response) do
200
- double("response", code: 200, body: { id: "12345678910" }.to_json)
201
- end
202
-
203
- before do
204
- allow(request).to receive(:request_payload).and_return({})
205
- allow(client).to receive(:authorize!).and_return(true)
206
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}").and_return(response)
207
- allow(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests/template")
208
- .and_return(request_template_response)
209
- end
210
-
211
- it "calls http_get template" do
212
- expect(client).to receive(:http_get).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests/template")
213
- .and_return(request_template_response)
214
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
215
- request.submit
216
- end
217
-
218
- it "calls http_post" do
219
- expect(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
220
- request.submit
221
- end
222
-
223
- it "returns Vra::Request" do
224
- allow(client).to receive(:http_post).with("/catalog-service/api/consumer/entitledCatalogItems/catalog-12345/requests", request.merged_payload).and_return(response)
225
- expect(request.submit).to be_a(Vra::Request)
226
- end
227
- end
228
- end
229
-
230
- describe "merges payload" do
231
- let(:request) do
232
- client.catalog.request("catalog-12345",
233
- cpus: 2,
234
- memory: 1024,
235
- lease_days: 15,
236
- requested_for: "tester@corp.local",
237
- notes: "test notes")
238
- end
239
- before(:each) do
240
- allow(Vra::CatalogItem).to receive(:dump_template).and_return({ data2: { key2: "value2" } }.merge(catalog_item_payload).to_json)
241
- end
242
-
243
- it "without catalog template" do
244
- request.template_payload = { data2: { key1: "value1" } }.merge(catalog_item_payload).to_json
245
- template = JSON.parse(request.merged_payload)
246
- expect(template["data2"].keys).to_not include("key2")
247
- end
248
-
249
- it "with catalog template" do
250
- request.template_payload = nil
251
- template = JSON.parse(request.merged_payload)
252
- expect(template["data2"].keys).to include("key2")
253
- end
254
- end
255
-
256
- it "creates request" do
257
- payload_file = File.join(fixtures_dir, "catalog_request_template.json")
258
- expect(Vra::CatalogRequest.request_from_payload(client, payload_file)).to be_a(Vra::CatalogRequest)
259
- end
260
-
261
- it "creates request with correct payload" do
262
- payload_file = File.join(fixtures_dir, "catalog_request_template.json")
263
- cr = Vra::CatalogRequest.request_from_payload(client, payload_file)
264
- data = JSON.parse(cr.merged_payload)
265
- expect(data["data"]["superduper_key"]).to eq("superduper_value")
266
- end
267
- end