vmware-vra 2.7.1 → 3.1.0
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 +22 -1
- data/README.md +81 -143
- 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 +37 -71
- 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 +125 -0
- data/lib/vra/{resources.rb → deployments.rb} +26 -17
- data/lib/vra/exceptions.rb +2 -2
- data/lib/vra/http.rb +16 -8
- data/lib/vra/request.rb +28 -36
- data/lib/vra/request_parameters.rb +12 -12
- 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 +91 -216
- 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 +231 -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 -134
- data/lib/vra/requests.rb +0 -41
- data/spec/catalog_request_spec.rb +0 -268
- 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: 55b844fe4edf716d4c6668cfa5c13721caa0f36a4873aae4f2949509cf6bfc1c
|
|
4
|
+
data.tar.gz: 5a68b428aa38c0e30a8ba89790ccdb5fd9b5d233485497886cd4d290f4f528d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b41f6cf8aca5fde7912e59937a569af9b0fb550877a07eb1302edd94b02a3caac478ca41474786fbf2293c2a96fc3334440b0eb72784a7b48c41090a401a9f99
|
|
7
|
+
data.tar.gz: 3dfa51c5e343ca7994f9240afa7b6b2f81de243bd88de0b8a9f19f9d189d571a4d95d4fe00628950a50673e8e15f4f2b849cf78456edc8423ff20aa512a84eb8
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [3.1.0](https://github.com/chef-partners/vmware-vra-gem/tree/v3.1.0) (2022-01-30)
|
|
4
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v3.0.1...v3.1.0)
|
|
5
|
+
|
|
6
|
+
- Make the version param optional in deployment request api
|
|
7
|
+
|
|
8
|
+
## [3.0.1](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.1) (2022-01-25)
|
|
9
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v3.0.0...v3.0.1)
|
|
10
|
+
|
|
11
|
+
- Fix access token workflow to work with VRA8
|
|
12
|
+
|
|
13
|
+
## [3.0.0](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.0) (2022-01-18)
|
|
14
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.2...v3.0.0)
|
|
15
|
+
|
|
16
|
+
- Rewritten to support vRA 8. If you require support for 7 make sure to pin on the previous 2.7.2 release.
|
|
17
|
+
|
|
18
|
+
## [2.7.2](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.2) (2020-09-09)
|
|
19
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.1...v2.7.2)
|
|
20
|
+
|
|
21
|
+
- Added an extra option to handle shirt size parameter
|
|
22
|
+
- Masking user credentials(password) in debug mode
|
|
23
|
+
|
|
3
24
|
## [2.7.1](https://github.com/chef-partners/vmware-vra-gem/tree/v2.7.1) (2019-05-28)
|
|
4
25
|
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.0...v2.7.1)
|
|
5
26
|
|
|
@@ -298,4 +319,4 @@
|
|
|
298
319
|
|
|
299
320
|
|
|
300
321
|
|
|
301
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
|
322
|
+
\* *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,136 @@ 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
|
+
|
|
130
|
+
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. If the user doesn't specify a version explicitly, the latest version will be fetched automatically and will be used for the request.
|
|
131
|
+
|
|
132
|
+
Additionally, the name of the deployment should be specified and it should be unique.
|
|
133
|
+
The image mapping specifies the OS image for a VM and the flavor mapping specifies the CPU count and RAM of a VM.
|
|
113
134
|
|
|
114
|
-
If
|
|
135
|
+
If your catalog blueprint item requires additional parameters to successfully submit your request, you may add them:
|
|
115
136
|
|
|
116
137
|
```
|
|
117
|
-
|
|
138
|
+
request.set_parameter('my_parameter', 'string', 'my value')
|
|
118
139
|
```
|
|
119
140
|
|
|
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.
|
|
141
|
+
### Managing the deployment
|
|
125
142
|
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
143
|
+
Now, submit your request! The client will return a new "Deployment" object you can use to query for status.
|
|
141
144
|
|
|
142
145
|
```
|
|
146
|
+
deployment = catalog_request.submit
|
|
147
|
+
=> #<Vra::Deployment:0x000000027caea0 ... >
|
|
143
148
|
|
|
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
|
|
149
|
+
deployment.status
|
|
173
150
|
=> "IN_PROGRESS"
|
|
174
151
|
```
|
|
175
152
|
|
|
176
|
-
You can
|
|
153
|
+
You can refresh your deployment object to get the latest status:
|
|
177
154
|
|
|
178
155
|
```
|
|
179
|
-
|
|
180
|
-
=> "SUCCESSFUL"
|
|
181
|
-
|
|
182
|
-
request.completion_state
|
|
156
|
+
deployment.refresh && deployment.status
|
|
183
157
|
=> "SUCCESSFUL"
|
|
184
|
-
|
|
185
|
-
request.completion_details
|
|
186
|
-
=> "Request succeeded. Created hol-dev-32."
|
|
187
158
|
```
|
|
188
159
|
|
|
189
|
-
You can also save the
|
|
160
|
+
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
161
|
|
|
191
162
|
```
|
|
192
|
-
|
|
163
|
+
deployment.id
|
|
193
164
|
=> "aed22465-02db-481d-b55a-cefe216096a2"
|
|
194
165
|
|
|
195
|
-
|
|
196
|
-
=> #<Vra::
|
|
166
|
+
new_deployment = client.deployments.by_id('aed22465-02db-481d-b55a-cefe216096a2')
|
|
167
|
+
=> #<Vra::Deployment:0x0000000564ac30 ... >
|
|
197
168
|
|
|
198
|
-
|
|
199
|
-
=> "
|
|
169
|
+
new_deployment.status
|
|
170
|
+
=> "CREATE_SUCCESSFUL"
|
|
200
171
|
```
|
|
201
172
|
|
|
202
|
-
|
|
173
|
+
### Deployment Resources
|
|
174
|
+
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
175
|
|
|
204
176
|
```
|
|
205
|
-
resource =
|
|
177
|
+
resource = deployment.resources.first
|
|
206
178
|
=> #<Vra::Resource:0x00000006772e68 ... >
|
|
207
179
|
|
|
208
180
|
resource.network_interfaces
|
|
@@ -215,23 +187,26 @@ resource.name
|
|
|
215
187
|
=> "hol-dev-32"
|
|
216
188
|
```
|
|
217
189
|
|
|
218
|
-
|
|
190
|
+
If you have the resource_id and the deployment object, you can fetch the resources details as follows
|
|
219
191
|
|
|
220
192
|
```
|
|
221
193
|
resource.id
|
|
222
194
|
=> "331fd10b-f2a2-40ae-86bc-1255c1ee9a6d"
|
|
223
195
|
|
|
224
|
-
new_resource =
|
|
196
|
+
new_resource = deployment.resource_by_id('331fd10b-f2a2-40ae-86bc-1255c1ee9a6d')
|
|
225
197
|
=> #<Vra::Resource:0x000000067c13b0 ... >
|
|
226
198
|
|
|
227
199
|
new_resource.name
|
|
228
200
|
=> "hol-dev-32"
|
|
229
201
|
```
|
|
230
202
|
|
|
231
|
-
|
|
203
|
+
### Deleting a deployment from vRA
|
|
204
|
+
|
|
205
|
+
When you no longer need the VM, you can destroy the deployment which will delete all the associated resources as well.
|
|
206
|
+
The method will return a request object you can query for status:
|
|
232
207
|
|
|
233
208
|
```
|
|
234
|
-
destroy_req =
|
|
209
|
+
destroy_req = deployment.destroy
|
|
235
210
|
=> #<Vra::Request:0x00000006ea90d8 ... >
|
|
236
211
|
|
|
237
212
|
destroy_req.status
|
|
@@ -241,45 +216,8 @@ destroy_req.status
|
|
|
241
216
|
You can also list all resources and requests you have permission to see with these methods:
|
|
242
217
|
|
|
243
218
|
```
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
```
|
|
247
|
-
|
|
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.
|
|
265
|
-
|
|
266
|
-
To use you can do something like:
|
|
267
|
-
|
|
268
|
-
```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
|
-
|
|
273
|
-
```
|
|
274
|
-
|
|
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.
|
|
277
|
-
|
|
278
|
-
```ruby
|
|
279
|
-
cr = Vra::CatalogRequest.new(id, opts)
|
|
280
|
-
cr.template_payload = File.read('/tmp/windows_2012.json')
|
|
281
|
-
cr.submit
|
|
282
|
-
|
|
219
|
+
deployment.resources
|
|
220
|
+
deployment.requests
|
|
283
221
|
```
|
|
284
222
|
|
|
285
223
|
### Pagination
|
|
@@ -314,7 +252,7 @@ $env:VRA_HTTP_TRACE=1
|
|
|
314
252
|
|
|
315
253
|
Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
|
316
254
|
|
|
317
|
-
Copyright:: Copyright (c)
|
|
255
|
+
Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
|
318
256
|
|
|
319
257
|
License:: Apache License, Version 2.0
|
|
320
258
|
|
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
|