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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +27 -1
- data/README.md +91 -141
- data/Rakefile +1 -12
- data/lib/vra/catalog.rb +39 -8
- data/lib/vra/catalog_base.rb +62 -0
- data/lib/vra/catalog_item.rb +29 -75
- data/lib/vra/catalog_source.rb +116 -0
- data/lib/vra/catalog_type.rb +56 -0
- data/lib/vra/client.rb +72 -53
- data/lib/vra/deployment.rb +155 -0
- data/lib/vra/deployment_request.rb +117 -0
- data/lib/vra/{resources.rb → deployments.rb} +26 -17
- data/lib/vra/exceptions.rb +2 -2
- data/lib/vra/http.rb +20 -7
- data/lib/vra/request.rb +28 -36
- data/lib/vra/request_parameters.rb +12 -10
- data/lib/vra/resource.rb +33 -203
- data/lib/vra/version.rb +2 -2
- data/lib/vra.rb +15 -12
- data/spec/catalog_item_spec.rb +64 -222
- data/spec/catalog_source_spec.rb +178 -0
- data/spec/catalog_spec.rb +112 -72
- data/spec/catalog_type_spec.rb +114 -0
- data/spec/client_spec.rb +287 -228
- data/spec/deployment_request_spec.rb +192 -0
- data/spec/deployment_spec.rb +227 -0
- data/spec/deployments_spec.rb +80 -0
- data/spec/fixtures/resource/sample_catalog_item.json +18 -0
- data/spec/fixtures/resource/sample_catalog_item_2.json +18 -0
- data/spec/fixtures/resource/sample_catalog_source.json +20 -0
- data/spec/fixtures/resource/sample_catalog_type.json +49 -0
- data/spec/fixtures/resource/sample_dep_actions.json +58 -0
- data/spec/fixtures/resource/sample_dep_request.json +19 -0
- data/spec/fixtures/resource/sample_dep_resource.json +112 -0
- data/spec/fixtures/resource/sample_deployment.json +26 -0
- data/spec/fixtures/resource/sample_entitlements.json +25 -0
- data/spec/http_spec.rb +63 -61
- data/spec/request_spec.rb +62 -68
- data/spec/resource_spec.rb +71 -390
- data/spec/spec_helper.rb +10 -4
- data/vmware-vra.gemspec +2 -4
- metadata +42 -32
- data/.travis.yml +0 -14
- data/lib/vra/catalog_request.rb +0 -127
- data/lib/vra/requests.rb +0 -41
- data/spec/catalog_request_spec.rb +0 -265
- data/spec/requests_spec.rb +0 -60
- data/spec/resources_spec.rb +0 -71
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e805c8c8d6fd5228962ffa907ce07409b60022e29166ba970194e0aa61cc42
|
4
|
+
data.tar.gz: 49beb545bf435a61aefccf06daa25629ccd991363dc9ca7546e3a15996cca362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de450415be0060fb3aef5d796e407bf9fedfb79b0f83a003d702073ee7aaa06508a5758191916d4c522c42348d166c01c23f8671221c2b8cd66b5e4b839177e7
|
7
|
+
data.tar.gz: ade68fa3e927d199c2c263bd1fcc918c21ea8c9aa52703ab74092461e9719c442294064c1410fc890c27d90908be089d21340141c11814db04cbccf3d1e4710a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,30 @@
|
|
1
1
|
# Change Log
|
2
|
+
## [3.0.1](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.1) (2022-01-25)
|
3
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v3.0.0...v3.0.1)
|
4
|
+
|
5
|
+
- Fix access token workflow to work with VRA8
|
6
|
+
|
7
|
+
## [3.0.0](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.0) (2022-01-18)
|
8
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.2...v3.0.0)
|
9
|
+
|
10
|
+
- Rewritten to support vRA 8. If you require support for 7 make sure to pin on the previous 2.7.2 release.
|
11
|
+
|
12
|
+
## [2.7.2](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.2) (2020-09-09)
|
13
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.1...v2.7.2)
|
14
|
+
|
15
|
+
- Added an extra option to handle shirt size parameter
|
16
|
+
- Masking user credentials(password) in debug mode
|
17
|
+
|
18
|
+
## [2.7.1](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.1) (2019-05-28)
|
19
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.0...v2.7.1)
|
20
|
+
|
21
|
+
**Closed issues:**
|
22
|
+
|
23
|
+
- Some Extra Parameters are not passing through to VRA [\#75](https://github.com/chef-partners/vmware-vra-gem/issues/75)
|
24
|
+
|
25
|
+
**Merged pull requests:**
|
26
|
+
|
27
|
+
- 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))
|
2
28
|
|
3
29
|
## [2.7.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.0) (2019-05-10)
|
4
30
|
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.6.1...v2.7.0)
|
@@ -287,4 +313,4 @@
|
|
287
313
|
|
288
314
|
|
289
315
|
|
290
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
316
|
+
\* *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
|
[](http://badge.fury.io/rb/vmware-vra)
|
3
|
-
[](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
|
-
|
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
|
53
|
+
To list all the catalog types:
|
52
54
|
|
53
55
|
```
|
54
|
-
|
55
|
-
=> [
|
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
|
-
|
60
|
+
### Catalog Sources:
|
61
|
+
|
62
|
+
To list all the catalog sources:
|
59
63
|
|
60
64
|
```
|
61
|
-
|
62
|
-
|
65
|
+
client.catalog.all_sources
|
66
|
+
[#<Vra::CatalogSource:0x00007fcde3948c30 @id="2f5b2d5c-6dc2-4ea7-b304-cd8fea5ede0f", @data= ...]
|
63
67
|
```
|
64
68
|
|
65
|
-
|
69
|
+
And to list the sources that are entitled only:
|
66
70
|
|
67
71
|
```
|
68
|
-
|
69
|
-
=> #<Vra::
|
72
|
+
client.catalog.entitled_sources(project_id)
|
73
|
+
=> [#<Vra::CatalogSource:0x00007fcde2a28c00 @id="18102dc2-9e48-487a-93a8-aafab2ecc05 ...]
|
70
74
|
```
|
71
75
|
|
72
|
-
|
76
|
+
Creating a new source can be done as follows:
|
73
77
|
|
74
78
|
```
|
75
|
-
|
76
|
-
=> #<Vra::
|
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
|
-
|
83
|
+
### Catalog Items
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
To retrieve sub-tenant id from sub-tenant name:
|
85
|
+
To list all items in the catalog:
|
84
86
|
|
85
87
|
```
|
86
|
-
|
88
|
+
client.catalog.all_items
|
89
|
+
=> [#<Vra::CatalogItem:0x00007fe583863b28>, #<Vra::CatalogItem:0x00007fe583863ad8 ... ]
|
87
90
|
```
|
88
91
|
|
89
|
-
|
92
|
+
To only list the items in the catalog for which you are entitled to request:
|
90
93
|
|
91
94
|
```
|
92
|
-
|
93
|
-
|
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
|
-
|
99
|
+
To retrive catalog id from catalog name:
|
102
100
|
|
103
101
|
```
|
104
|
-
|
105
|
-
=>
|
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
|
-
|
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
|
-
|
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
|
133
|
+
If your catalog blueprint item requires additional parameters to successfully submit your request, you may add them:
|
115
134
|
|
116
135
|
```
|
117
|
-
|
136
|
+
request.set_parameter('my_parameter', 'string', 'my value')
|
118
137
|
```
|
119
138
|
|
120
|
-
###
|
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
|
-
|
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
|
-
|
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
|
151
|
+
You can refresh your deployment object to get the latest status:
|
177
152
|
|
178
153
|
```
|
179
|
-
|
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
|
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
|
-
|
161
|
+
deployment.id
|
193
162
|
=> "aed22465-02db-481d-b55a-cefe216096a2"
|
194
163
|
|
195
|
-
|
196
|
-
=> #<Vra::
|
164
|
+
new_deployment = client.deployments.by_id('aed22465-02db-481d-b55a-cefe216096a2')
|
165
|
+
=> #<Vra::Deployment:0x0000000564ac30 ... >
|
197
166
|
|
198
|
-
|
199
|
-
=> "
|
167
|
+
new_deployment.status
|
168
|
+
=> "CREATE_SUCCESSFUL"
|
200
169
|
```
|
201
170
|
|
202
|
-
|
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 =
|
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
|
-
|
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 =
|
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
|
-
|
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 =
|
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
|
-
|
245
|
-
|
217
|
+
deployment.resources
|
218
|
+
deployment.requests
|
246
219
|
```
|
247
220
|
|
248
|
-
###
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
280
|
-
cr.template_payload = File.read('/tmp/windows_2012.json')
|
281
|
-
cr.submit
|
282
|
-
|
232
|
+
client.page_size = 100
|
283
233
|
```
|
284
234
|
|
285
|
-
###
|
235
|
+
### Debugging
|
286
236
|
|
287
|
-
|
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
|
-
|
241
|
+
export VRA_HTTP_TRACE=1
|
291
242
|
```
|
292
243
|
|
293
|
-
|
294
|
-
|
295
|
-
|
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)
|
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
|
-
|
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)
|
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
|
-
|
30
|
-
|
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
|
-
|
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::
|
49
|
+
Vra::DeploymentRequest.new(@client, *args)
|
40
50
|
end
|
41
51
|
|
42
52
|
def fetch_catalog_items(catalog_name)
|
43
|
-
|
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
|