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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c5dcc8f5abbb59b980895b3970c86f73e49fe379
4
- data.tar.gz: 78746f7b4706f0ae7adcce6cffcd8a2f5fd178c2
2
+ SHA256:
3
+ metadata.gz: d3671834fbc97510772f7d42d524f2775789c7ac0fe7f29c80dad8c64effe3b6
4
+ data.tar.gz: 394929c607677c9c2341e9a6060e9341810f2a8941111247e2fe1e1f71ce5afb
5
5
  SHA512:
6
- metadata.gz: 26479fc2672a80ddf7b83f9b5bafedbe803304b1f580ffcd7603512f08a8e936d7b14933c36be801a010728441c0502cc55d7822c9591eb5b5c9bc9b6cfa294a
7
- data.tar.gz: ccd9fdf91aa926facc9bb8d8819fa73a653217b349ea79da6bc490917df1958a9ab5346d8f48c0090a4c764ba84303297997a6a8b2ddc1e604503963a3fafbaa
6
+ metadata.gz: a04bbf0434372a58119367bb5f3d9f35c10fff450263e14f92fac6bc78082a74d0ca8fbca713b4ae7a1c0fdc1e1a40a953b321b21be32bfd0996db3cf107d776
7
+ data.tar.gz: 3f3646d1aa4fb7d15fd451fce246ab9ccb1e4828dfd4e13110abdb5ce552a3c4a158fb3ff8ab6a6139154af6fec3c57646566876ae4af2c6414bd6f5fb5284b7
data/.gitignore CHANGED
@@ -15,4 +15,6 @@
15
15
  mkmf.log
16
16
  .direnv/
17
17
  .envrc
18
- .ruby-version
18
+ .ruby-version
19
+ .idea
20
+
data/CHANGELOG.md CHANGED
@@ -1,6 +1,39 @@
1
1
  # Change Log
2
2
 
3
- ## [2.6.1](https://github.com/chef-partners/vmware-vra-gem/tree/2.6.1) (2018-07-31)
3
+ ## [3.0.0](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.0) (2022-01-18)
4
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.2...v3.0.0)
5
+
6
+ - Rewritten to support vRA 8. If you require support for 7 make sure to pin on the previous 2.7.2 release.
7
+
8
+ ## [2.7.2](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.2) (2020-09-09)
9
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.1...v2.7.2)
10
+
11
+ - Added an extra option to handle shirt size parameter
12
+ - Masking user credentials(password) in debug mode
13
+
14
+ ## [2.7.1](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.1) (2019-05-28)
15
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.0...v2.7.1)
16
+
17
+ **Closed issues:**
18
+
19
+ - Some Extra Parameters are not passing through to VRA [\#75](https://github.com/chef-partners/vmware-vra-gem/issues/75)
20
+
21
+ **Merged pull requests:**
22
+
23
+ - Add support for boolean vRA parameters, fix deep merge, add tracing [\#76](https://github.com/chef-partners/vmware-vra-gem/pull/76) ([stuartpreston](https://github.com/stuartpreston))
24
+
25
+ ## [2.7.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.0) (2019-05-10)
26
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.6.1...v2.7.0)
27
+
28
+ **Closed issues:**
29
+
30
+ - Extra Parameters Not Being Sent to vRA [\#73](https://github.com/chef-partners/vmware-vra-gem/issues/73)
31
+
32
+ **Merged pull requests:**
33
+
34
+ - vRA7 multiple fixes for nested, non-nested and merged parameters for a Blueprint [\#74](https://github.com/chef-partners/vmware-vra-gem/pull/74) ([stuartpreston](https://github.com/stuartpreston))
35
+
36
+ ## [2.6.1](https://github.com/chef-partners/vmware-vra-gem/tree/v2.6.1) (2018-07-31)
4
37
  [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.6.0...2.6.1)
5
38
 
6
39
  **Closed issues:**
@@ -276,4 +309,4 @@
276
309
 
277
310
 
278
311
 
279
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
312
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # VMware vRA Gem
2
2
  [![Gem Version](https://badge.fury.io/rb/vmware-vra.svg)](http://badge.fury.io/rb/vmware-vra)
3
- [![Build Status](https://travis-ci.org/chef-partners/vmware-vra-gem.svg?branch=master)](https://travis-ci.org/chef-partners/vmware-vra-gem)
4
3
 
5
4
  Client gem for interacting with VMware's vRealize Automation application.
6
5
 
@@ -16,6 +15,8 @@ to create Chef plugins for knife, test-kitchen, and provisioning.
16
15
 
17
16
  `2.0.0` version and forward will support vRA 7+.
18
17
 
18
+ `3.0.0` version and forward will support vRA 8+.
19
+
19
20
  ## Installation
20
21
 
21
22
  Add this line to your application's Gemfile:
@@ -44,165 +45,134 @@ require 'vra'
44
45
  Then, set up your client object. You will need to know your tenant ID from your vRA administrator.
45
46
 
46
47
  ```
47
- vra = Vra::Client.new(username: 'devmgr@corp.local', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true)
48
+ client = Vra::Client.new(username: 'devmgr@corp.local', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true)
48
49
  => #<Vra::Client:0x000000034c0df8 ... >
49
50
  ```
51
+ ### Catalog Types:
50
52
 
51
- To list all items in the catalog:
53
+ To list all the catalog types:
52
54
 
53
55
  ```
54
- vra.catalog.all_items
55
- => [{"@type"=>"CatalogItem", "id"=>"a9cd6148-6e0b-4a80-ac47-f5255c52b43d", "version"=>2, "name"=>"CentOS 6.6", "description"=>"Blueprint for deploying a CentOS Linux development server", ... }]
56
+ client.catalog.all_types
57
+ => [#<Vra::CatalogType:0x00007fcde6855370 @id="com.vmw.vro.workflow", @data={"id"=>"com.vmw.vro.workflow", ... ]
56
58
  ```
57
59
 
58
- To only list the items in the catalog for which you are entitled to request:
60
+ ### Catalog Sources:
61
+
62
+ To list all the catalog sources:
59
63
 
60
64
  ```
61
- vra.catalog.entitled_items
62
- => [{"@type"=>"ConsumerEntitledCatalogItem", "catalogItem"=>{"id"=>"d29efd6b-3cd6-4f8d-b1d8-da4ddd4e52b1", "version"=>2, "name"=>"WindowsServer2012", "description"=>"Windows Server 2012", ... }]
65
+ client.catalog.all_sources
66
+ [#<Vra::CatalogSource:0x00007fcde3948c30 @id="2f5b2d5c-6dc2-4ea7-b304-cd8fea5ede0f", @data= ...]
63
67
  ```
64
68
 
65
- When you are ready to request an item from the catalog, create a new catalog request object:
69
+ And to list the sources that are entitled only:
66
70
 
67
71
  ```
68
- catalog_request = vra.catalog.request('a9cd6148-6e0b-4a80-ac47-f5255c52b43d', cpus: 1, memory: 512, requested_for: 'devmgr@corp.local', lease_days: 30)
69
- => #<Vra::CatalogRequest:0x00000003477c20 ... >
72
+ client.catalog.entitled_sources(project_id)
73
+ => [#<Vra::CatalogSource:0x00007fcde2a28c00 @id="18102dc2-9e48-487a-93a8-aafab2ecc05 ...]
70
74
  ```
71
75
 
72
- To retrive catalog id from catalog name:
76
+ Creating a new source can be done as follows:
73
77
 
74
78
  ```
75
- vra.catalog.fetch_catalog_items('my_catalog_name')
76
- => #<Vra::CatalogRequest:0x00000004477c20 ... >
79
+ source = Vra::CatalogSource.create(client, name: 'New source', catalog_type_id: 'com.vmw.vro.workflow', project_id: project_id)
80
+ => #<Vra::CatalogSource:0x00007fad651f63b8 ... >
77
81
  ```
78
82
 
79
- vRA requires your sub-tenant (a.k.a. "business group") to be specified when requesting an item from the catalog. If the catalog item you are requesting is specifically created for a given business group, the gem will use that ID automatically without you needing to specify it.
83
+ ### Catalog Items
80
84
 
81
- An easier option has been provided to end user to provide a friendly sub-tenant name instead of sub-tenant id, and the driver would take care of retrieving the sub-tenant id for the corresponding sub-tenant name. Tenant name is also required along with sub-tenant name to retrieve sub-tenant id.
82
-
83
- To retrieve sub-tenant id from sub-tenant name:
85
+ To list all items in the catalog:
84
86
 
85
87
  ```
86
- vra.fetch_subtenant_items('my_tenant', 'my_subtenant_name')
88
+ client.catalog.all_items
89
+ => [#<Vra::CatalogItem:0x00007fe583863b28>, #<Vra::CatalogItem:0x00007fe583863ad8 ... ]
87
90
  ```
88
91
 
89
- However, if there is no sub-tenant ID or sub-tenant name available for us to use, you will receive an error when you submit:
92
+ To only list the items in the catalog for which you are entitled to request:
90
93
 
91
94
  ```
92
- request = catalog_request.submit
93
- ArgumentError: Unable to submit request, required param(s) missing => subtenant_id
94
- from /home/aleff/vmware-vra/lib/vra/catalog_request.rb:42:in `validate_params!'
95
- from /home/aleff/vmware-vra/lib/vra/catalog_request.rb:99:in `submit'
96
- from (irb):4
97
- from /opt/chefdk/embedded/bin/irb:11:in `<main>'
98
-
95
+ client.catalog.entitled_items(project_id)
96
+ => [#<Vra::CatalogItem:0x00007fe583863b28>, #<Vra::CatalogItem:0x00007fe583863ad8 ... ]
99
97
  ```
100
98
 
101
- In this case, you will need to supply the sub-tenant ID manually:
99
+ To retrive catalog id from catalog name:
102
100
 
103
101
  ```
104
- catalog_request.subtenant_id = '5327ddd3-1a4e-4663-9e9d-63db86ffc8af'
105
- => "5327ddd3-1a4e-4663-9e9d-63db86ffc8af"
102
+ client.catalog.fetch_catalog_items('centos')
103
+ =>
104
+ [#<Vra::CatalogItem:0x00007fb734110f60
105
+ @id="f2e8c6ee-dd00-32c4-94c7-0a50046cb2f3",
106
+ @data={
107
+ "name"=>"oe-centos-1633598756_bp",
108
+ ...>
109
+ ]
106
110
  ```
107
111
 
108
- If your catalog blueprint item requires additional parameters to successfully submit your request, you may add them:
112
+ ### Requesting Deployments
113
+ When you are ready to request a deployment using a catalog, create a new deployment object:
109
114
 
110
115
  ```
111
- catalog_request.set_parameter('my_parameter', 'string', 'my value')
116
+ request = client.catalog.request(
117
+ catalog_id,
118
+ image_mapping: 'VRA-nc-lnx-ce8.4-Docker',
119
+ flavor_mapping: 'Small',
120
+ name: 'CentOS VRA8 Test',
121
+ project_id: project_id,
122
+ version: '1'
123
+ )
124
+ =>
125
+ #<Vra::DeploymentRequest:0x00007fb7340b7438
126
+ ...
112
127
  ```
128
+ To request a deployment from a catalog item, you can use the above method with a project ID that has a cloud template version released to the project.
129
+ The ID of the catalog item from which you are requesting the deployment should be also included, and the version of the released cloud template.
130
+ Additionally, the name of the deployment should be specified and it should be unique.
131
+ The image mapping specifies the OS image for a VM and the flavor mapping specifies the CPU count and RAM of a VM.
113
132
 
114
- If you need to set a parameter on a child object in the blueprint, you can add them by using a ~:
133
+ If your catalog blueprint item requires additional parameters to successfully submit your request, you may add them:
115
134
 
116
135
  ```
117
- catalog_request.set_parameter('object~my_parameter', 'string', 'my value')
136
+ request.set_parameter('my_parameter', 'string', 'my value')
118
137
  ```
119
138
 
120
- ### Creating a request from a yaml or json payload
121
- Should you want to create a request ahead of time you can create the parameters up front by
122
- reading from a file or a hard coded payload you use every time. This is not required by any means but allows
123
- for some extra flexibility when using this request object directly. The only difference is that you can pass
124
- in the request parameters instead of having to set them after you create the object.
125
-
126
- Given a sample request object like the following you will want to read the yaml into an ruby object:
139
+ ### Managing the deployment
127
140
 
128
- ```yaml
129
- requestData:
130
- entries:
131
- key: provider-provisioningGroupId
132
- value:
133
- type: string
134
- value: 93992-3929392-32323828-832882394
135
- key: provider-datacenter
136
- type: string
137
- value: datacenter1
138
- key: provider-domain
139
- type: string
140
- value: chef.com
141
+ Now, submit your request! The client will return a new "Deployment" object you can use to query for status.
141
142
 
142
143
  ```
144
+ deployment = catalog_request.submit
145
+ => #<Vra::Deployment:0x000000027caea0 ... >
143
146
 
144
- And now use that data to create the Vra::RequestParameters to feed into the catalog request.
145
-
146
- ```ruby
147
- # read in the request data
148
- yaml_data = YAML,load(data)
149
- # create a parameters array, although this only works with VRA6, since VRA7 can have complex data
150
- parameters = yaml_data['requestData']['entries'].map {|item| [item['key'], item['value'].values].flatten }
151
- # We put the values in a array so we can easily explode the parameters using the splat operator later
152
- request_params = Vra::RequestParameters.new
153
- # loop through each parameter and setting each parameter
154
- parameters.each {|p| request_params.set(*p) # splat
155
- request_options = {
156
- cpus: 1,
157
- memory: 1024,
158
- requested_for: 'me@me.com',
159
- lease_days: 2,
160
- additional_params: request_params
161
- }
162
- # create the request
163
- catalog_request = vra.catalog.request(blueprint, request_options)
164
- ```
165
-
166
- Now, submit your request! The client will return a new "Request" object you can use to query for status.
167
-
168
- ```
169
- request = catalog_request.submit
170
- => #<Vra::Request:0x000000027caea0 ... >
171
-
172
- request.status
147
+ deployment.status
173
148
  => "IN_PROGRESS"
174
149
  ```
175
150
 
176
- You can easily refresh your request object to get the latest status:
151
+ You can refresh your deployment object to get the latest status:
177
152
 
178
153
  ```
179
- request.refresh && request.status
154
+ deployment.refresh && deployment.status
180
155
  => "SUCCESSFUL"
181
-
182
- request.completion_state
183
- => "SUCCESSFUL"
184
-
185
- request.completion_details
186
- => "Request succeeded. Created hol-dev-32."
187
156
  ```
188
157
 
189
- You can also save the request ID for later, and create a new request object at your leisure to follow-up on your request:
158
+ You can also save the deployment ID for later, and create a new deployment object at your leisure to follow-up on your deployment request:
190
159
 
191
160
  ```
192
- request.id
161
+ deployment.id
193
162
  => "aed22465-02db-481d-b55a-cefe216096a2"
194
163
 
195
- new_request = vra.requests.by_id('aed22465-02db-481d-b55a-cefe216096a2')
196
- => #<Vra::Request:0x0000000564ac30 ... >
164
+ new_deployment = client.deployments.by_id('aed22465-02db-481d-b55a-cefe216096a2')
165
+ => #<Vra::Deployment:0x0000000564ac30 ... >
197
166
 
198
- new_request.status
199
- => "SUCCESSFUL"
167
+ new_deployment.status
168
+ => "CREATE_SUCCESSFUL"
200
169
  ```
201
170
 
202
- When the request is successful, you can query the resources created as the result of your request. Assuming that the catalog item blueprint we requested only creates a single VM, we can get that resource and learn more information about it:
171
+ ### Deployment Resources
172
+ When the deployment request is successful, you can query the resources created as the result of your request. Assuming that the catalog item blueprint we requested only creates a single VM, we can get that resource and learn more information about it:
203
173
 
204
174
  ```
205
- resource = request.resources.first
175
+ resource = deployment.resources.first
206
176
  => #<Vra::Resource:0x00000006772e68 ... >
207
177
 
208
178
  resource.network_interfaces
@@ -215,23 +185,26 @@ resource.name
215
185
  => "hol-dev-32"
216
186
  ```
217
187
 
218
- And just like requests, you can save the resource ID and query it again later:
188
+ If you have the resource_id and the deployment object, you can fetch the resources details as follows
219
189
 
220
190
  ```
221
191
  resource.id
222
192
  => "331fd10b-f2a2-40ae-86bc-1255c1ee9a6d"
223
193
 
224
- new_resource = vra.resources.by_id('331fd10b-f2a2-40ae-86bc-1255c1ee9a6d')
194
+ new_resource = deployment.resource_by_id('331fd10b-f2a2-40ae-86bc-1255c1ee9a6d')
225
195
  => #<Vra::Resource:0x000000067c13b0 ... >
226
196
 
227
197
  new_resource.name
228
198
  => "hol-dev-32"
229
199
  ```
230
200
 
231
- When you no longer need the VM, you can destroy it, which returns another request object you can query for status:
201
+ ### Deleting a deployment from vRA
202
+
203
+ When you no longer need the VM, you can destroy the deployment which will delete all the associated resources as well.
204
+ The method will return a request object you can query for status:
232
205
 
233
206
  ```
234
- destroy_req = resource.destroy
207
+ destroy_req = deployment.destroy
235
208
  => #<Vra::Request:0x00000006ea90d8 ... >
236
209
 
237
210
  destroy_req.status
@@ -241,66 +214,43 @@ destroy_req.status
241
214
  You can also list all resources and requests you have permission to see with these methods:
242
215
 
243
216
  ```
244
- vra.resources.all_resources
245
- vra.requests.all_requests
217
+ deployment.resources
218
+ deployment.requests
246
219
  ```
247
220
 
248
- ### Download VRA catalog templates
249
- It can be quite useful to download the catalog templates from your VRA server for future playback or inspection. This
250
- can now be easily done with some helpful class methods.
251
-
252
- To get a json string representation of the catalog template you can use `Vra::CatalogItem.dump_template(client, catalog_id)`
253
-
254
- To dump the catalog template to a file instead of a string `Vra::CatalogItem.write_template(client, catalog_id)`. This will create a file like `windows2012.json`.
255
-
256
- If you just want to dump all the templates you can use `Vra::CatalogItem.dump_templates(client)`. This will create a directory named vra_templates
257
- with all the entitled templates for the current user.
258
-
259
- There are additional options you can provide to these methods in order to customize output file names and directories, so please see the source code in lib/vra/catalog_item.rb
260
-
261
- ### Supply custom VRA catalog template and create request
262
- If you previously had some custom templates already in JSON format you can now use those to create requests instead of setting
263
- a bunch of parameters. This can be especially useful when your request has complex parameters or you have a bunch of templates
264
- that you want to create unique requests for.
221
+ ### Pagination
265
222
 
266
- To use you can do something like:
223
+ vRA paginates API requests where lists of items are returned. By default, this gem will ask vRA to provide items in groups of 20. However, as reported in [Issue 10](https://github.com/chef-partners/vmware-vra-gem/issues/10), it appears vRA may have a pagination bug. You can change the default page size from 20 to a value of your choice by passing in a `page_size` option when setting up the client:
267
224
 
268
225
  ```ruby
269
- payload_file = '/tmp/windows_2012.json' # must be in json format
270
- cr = Vra::CatalogRequest.request_from_payload(client, payload_file)
271
- cr.submit
272
-
226
+ vra = Vra::Client.new(username: 'devmgr@corp.local', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true, page_size: 100)
273
227
  ```
274
228
 
275
- If you already have a catalog request object you can still supply a custom payload by simply setting the template_payload property.
276
- Note this custom payload will be merged with the properties originally set when creating the catalog request object.
229
+ ... or setting `page_size` on the client object after you've created it:
277
230
 
278
231
  ```ruby
279
- cr = Vra::CatalogRequest.new(id, opts)
280
- cr.template_payload = File.read('/tmp/windows_2012.json')
281
- cr.submit
282
-
232
+ client.page_size = 100
283
233
  ```
284
234
 
285
- ### Pagination
235
+ ### Debugging
286
236
 
287
- vRA paginates API requests where lists of items are returned. By default, this gem will ask vRA to provide items in groups of 20. However, as reported in [Issue 10](https://github.com/chef-partners/vmware-vra-gem/issues/10), it appears vRA may have a pagination bug. You can change the default page size from 20 to a value of your choice by passing in a `page_size` option when setting up the client:
237
+ To aid diagnosis of deep API issues, set the following environment variable to enable logging of all API requests. Note that this will include requests to retrieve the bearer token.
288
238
 
239
+ MacOS/Linux:
289
240
  ```ruby
290
- vra = Vra::Client.new(username: 'devmgr@corp.local', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true, page_size: 100)
241
+ export VRA_HTTP_TRACE=1
291
242
  ```
292
243
 
293
- ... or setting `page_size` on the client object after you've created it:
294
-
295
- ```ruby
296
- client.page_size = 100
244
+ Windows:
245
+ ```powershell
246
+ $env:VRA_HTTP_TRACE=1
297
247
  ```
298
248
 
299
249
  ## License and Authors
300
250
 
301
251
  Author:: Chef Partner Engineering (<partnereng@chef.io>)
302
252
 
303
- Copyright:: Copyright (c) 2015-2016 Chef Software, Inc.
253
+ Copyright:: Copyright (c) 2022 Chef Software, Inc.
304
254
 
305
255
  License:: Apache License, Version 2.0
306
256
 
data/Rakefile CHANGED
@@ -9,15 +9,4 @@ RuboCop::RakeTask.new do |task|
9
9
  task.options << "--display-cop-names"
10
10
  end
11
11
 
12
- begin
13
- require "github_changelog_generator/task"
14
-
15
- GitHubChangelogGenerator::RakeTask.new :changelog do |config|
16
- config.future_release = Vra::VERSION
17
- config.issues = true
18
- end
19
- rescue LoadError
20
- puts "github_changelog_generator is not available. gem install github_changelog_generator to generate changelogs"
21
- end
22
-
23
- task default: [ :spec, :rubocop ]
12
+ task default: %i{spec rubocop}
data/lib/vra/catalog.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2022 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,22 +25,53 @@ module Vra
25
25
  @client = client
26
26
  end
27
27
 
28
+ def all_types
29
+ fetch_resources Vra::CatalogType
30
+ end
31
+
32
+ def all_sources
33
+ fetch_resources Vra::CatalogSource
34
+ end
35
+
28
36
  def all_items
29
- client.http_get_paginated_array!("/catalog-service/api/consumer/catalogItems")
30
- .map! { |x| Vra::CatalogItem.new(client, data: x) }
37
+ fetch_resources Vra::CatalogItem
38
+ end
39
+
40
+ def entitled_sources(project_id)
41
+ fetch_entitlements(project_id, 'CatalogSourceIdentifier')
31
42
  end
32
43
 
33
- def entitled_items
34
- client.http_get_paginated_array!("/catalog-service/api/consumer/entitledCatalogItems")
35
- .map! { |x| Vra::CatalogItem.new(client, data: x["catalogItem"]) }
44
+ def entitled_items(project_id)
45
+ fetch_entitlements(project_id, 'CatalogItemIdentifier')
36
46
  end
37
47
 
38
48
  def request(*args)
39
- Vra::CatalogRequest.new(@client, *args)
49
+ Vra::DeploymentRequest.new(@client, *args)
40
50
  end
41
51
 
42
52
  def fetch_catalog_items(catalog_name)
43
- client.http_get("/catalog-service/api/consumer/entitledCatalogItemViews?%24filter=name+eq+'#{catalog_name}'")
53
+ fetch_resources(
54
+ Vra::CatalogItem,
55
+ '/catalog/api/admin/items',
56
+ "search=#{catalog_name}"
57
+ )
58
+ end
59
+
60
+ private
61
+
62
+ def fetch_resources(klass, url = nil, filter = nil)
63
+ client
64
+ .http_get_paginated_array!(url || klass::INDEX_URL, filter)
65
+ .map! { |x| klass.new(client, data: x) }
66
+ end
67
+
68
+ def fetch_entitlements(project_id, type)
69
+ klass = type == 'CatalogSourceIdentifier' ? Vra::CatalogSource : Vra::CatalogItem
70
+
71
+ client
72
+ .get_parsed("/catalog/api/admin/entitlements?projectId=#{project_id}")
73
+ .select { |x| x['definition']['type'] == type }
74
+ .map! { |x| klass.new(client, data: x['definition']) }
44
75
  end
45
76
  end
46
77
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Ashique Saidalavi (<ashique.saidalavi@progress.com>)
4
+ # Copyright:: Copyright (c) 2022 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
+ module Vra
20
+ # Base class with common methods
21
+ class CatalogBase
22
+ attr_reader :id
23
+
24
+ # @param client [Vra::Client] - a vra client object
25
+ # @param opts [Hash] - Contains the either id of the catalog or the data hash
26
+ # Either one of id or data hash is required, must not supply both
27
+ def initialize(client, opts)
28
+ @client = client
29
+ @id = opts[:id]
30
+ @data = opts[:data]
31
+ end
32
+
33
+ def entitle!(opts = {})
34
+ response = client.http_post(
35
+ "/catalog/api/admin/entitlements?project_id=#{project_id}",
36
+ FFI_Yajl::Encoder.encode(entitle_params(opts[:type])),
37
+ opts[:skip_auth] || false
38
+ )
39
+
40
+ FFI_Yajl::Parser.parse(response.body)
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :client, :data
46
+
47
+ def validate!
48
+ raise ArgumentError, 'must supply id or data hash' if @id.nil? && @data.nil?
49
+ raise ArgumentError, 'must supply id or data hash, not both' if !@id.nil? && !@data.nil?
50
+ end
51
+
52
+ def entitle_params(type)
53
+ {
54
+ 'projectId': project_id,
55
+ 'definition': {
56
+ 'type': type,
57
+ 'id': id
58
+ }
59
+ }
60
+ end
61
+ end
62
+ end