vmware-vra 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95e805c8c8d6fd5228962ffa907ce07409b60022e29166ba970194e0aa61cc42
4
- data.tar.gz: 49beb545bf435a61aefccf06daa25629ccd991363dc9ca7546e3a15996cca362
3
+ metadata.gz: 55b844fe4edf716d4c6668cfa5c13721caa0f36a4873aae4f2949509cf6bfc1c
4
+ data.tar.gz: 5a68b428aa38c0e30a8ba89790ccdb5fd9b5d233485497886cd4d290f4f528d0
5
5
  SHA512:
6
- metadata.gz: de450415be0060fb3aef5d796e407bf9fedfb79b0f83a003d702073ee7aaa06508a5758191916d4c522c42348d166c01c23f8671221c2b8cd66b5e4b839177e7
7
- data.tar.gz: ade68fa3e927d199c2c263bd1fcc918c21ea8c9aa52703ab74092461e9719c442294064c1410fc890c27d90908be089d21340141c11814db04cbccf3d1e4710a
6
+ metadata.gz: b41f6cf8aca5fde7912e59937a569af9b0fb550877a07eb1302edd94b02a3caac478ca41474786fbf2293c2a96fc3334440b0eb72784a7b48c41090a401a9f99
7
+ data.tar.gz: 3dfa51c5e343ca7994f9240afa7b6b2f81de243bd88de0b8a9f19f9d189d571a4d95d4fe00628950a50673e8e15f4f2b849cf78456edc8423ff20aa512a84eb8
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
  # Change Log
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
+
2
8
  ## [3.0.1](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.1) (2022-01-25)
3
9
  [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v3.0.0...v3.0.1)
4
10
 
data/README.md CHANGED
@@ -125,8 +125,10 @@ request = client.catalog.request(
125
125
  #<Vra::DeploymentRequest:0x00007fb7340b7438
126
126
  ...
127
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.
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
+
130
132
  Additionally, the name of the deployment should be specified and it should be unique.
131
133
  The image mapping specifies the OS image for a VM and the flavor mapping specifies the CPU count and RAM of a VM.
132
134
 
@@ -73,12 +73,24 @@ module Vra
73
73
  data['iconId']
74
74
  end
75
75
 
76
+ def versions
77
+ client
78
+ .http_get_paginated_array!("/catalog/api/items/#{id}/versions")
79
+ .map { |v| v['id'] }
80
+ end
81
+
76
82
  def entitle!(opts = {})
77
83
  super(opts.merge(type: 'CatalogItemIdentifier'))
78
84
  end
79
85
 
80
- def self.entitle!(client, id)
81
- new(client, id: id).entitle!
86
+ class << self
87
+ def entitle!(client, id)
88
+ new(client, id: id).entitle!
89
+ end
90
+
91
+ def fetch_latest_version(client, id)
92
+ new(client, data: { 'id' => id }).versions&.first
93
+ end
82
94
  end
83
95
  end
84
96
  end
@@ -85,13 +85,21 @@ module Vra
85
85
 
86
86
  def validate!
87
87
  missing_params = []
88
- %i[image_mapping flavor_mapping name project_id version].each do |arg|
88
+ %i[image_mapping flavor_mapping name project_id].each do |arg|
89
89
  missing_params << arg if send(arg).nil?
90
90
  end
91
91
 
92
- return if missing_params.empty?
92
+ unless missing_params.empty?
93
+ raise ArgumentError, "Unable to submit request, required param(s) missing => #{missing_params.join(', ')}"
94
+ end
95
+
96
+ # If the user doesn't supply the catalog version, fetch the latest version and use it
97
+ # and if the API was unable to find a valid version, alert the user.
98
+ return unless @version.nil?
99
+
93
100
 
94
- raise ArgumentError, "Unable to submit request, required param(s) missing => #{missing_params.join(', ')}"
101
+ @version = CatalogItem.fetch_latest_version(client, catalog_id)
102
+ raise ArgumentError, 'Unable to fetch a valid catalog version' if @version.nil?
95
103
  end
96
104
 
97
105
  def send_request!
data/lib/vra/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module Vra
21
- VERSION = "3.0.1"
21
+ VERSION = "3.1.0"
22
22
  end
@@ -122,4 +122,37 @@ describe Vra::CatalogItem do
122
122
  expect(catalog_item.type).to be_a(Vra::CatalogType)
123
123
  end
124
124
  end
125
+
126
+ describe '#versions' do
127
+ let(:versions_response) do
128
+ [{ id: '2', description: 'v2.0' }, { id: '1', description: 'v1.0' }]
129
+ end
130
+
131
+ before do
132
+ allow(client).to receive(:authorized?).and_return(true)
133
+ end
134
+
135
+ it 'should call the api to fetch the versions' do
136
+ expect(client)
137
+ .to receive(:http_get_paginated_array!)
138
+ .with('/catalog/api/items/catalog-12345/versions')
139
+ .and_return(versions_response)
140
+
141
+ described_class.fetch_latest_version(client, 'catalog-12345')
142
+ end
143
+
144
+ it 'should return the correct version' do
145
+ stub_request(:get, client.full_url('/catalog/api/items/catalog-12345/versions?$skip=0&$top=20'))
146
+ .to_return(
147
+ status: 200,
148
+ body: {
149
+ content: versions_response,
150
+ totalPages: 1
151
+ }.to_json,
152
+ headers: {}
153
+ )
154
+
155
+ expect(described_class.fetch_latest_version(client, 'catalog-12345')).to eq('2')
156
+ end
157
+ end
125
158
  end
@@ -70,6 +70,45 @@ describe Vra::DeploymentRequest do
70
70
 
71
71
  expect { request.send(:validate!) }.not_to raise_error(ArgumentError)
72
72
  end
73
+
74
+ context 'versions' do
75
+ let(:dep_request) do
76
+ described_class.new(
77
+ client,
78
+ catalog_id,
79
+ image_mapping: 'centos',
80
+ name: 'sample dep',
81
+ flavor_mapping: 'small',
82
+ project_id: 'pro-123'
83
+ )
84
+ end
85
+
86
+ before do
87
+ allow(client).to receive(:authorized?).and_return(true)
88
+ end
89
+
90
+ it 'should not call the api to fetch versions if provided in the params' do
91
+ expect(client).not_to receive(:http_get_paginated_array!)
92
+
93
+ dep_request.version = '1'
94
+ dep_request.send(:validate!)
95
+ end
96
+
97
+ it 'should fetch version from api if version is blank' do
98
+ expect(client).to receive(:http_get_paginated_array!).and_return([{ 'id' => '2', 'description' => 'v2.0' }])
99
+
100
+ dep_request.send(:validate!)
101
+ expect(dep_request.version).to eq('2')
102
+ end
103
+
104
+ it 'should raise an exception if no valid versions found' do
105
+ expect(client).to receive(:http_get_paginated_array!).and_return([])
106
+
107
+ expect { dep_request.send(:validate!) }
108
+ .to raise_error(ArgumentError)
109
+ .with_message('Unable to fetch a valid catalog version')
110
+ end
111
+ end
73
112
  end
74
113
 
75
114
  describe '#additional parameters' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmware-vra
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Leff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-01-25 00:00:00.000000000 Z
12
+ date: 2022-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl