vmware-vra 2.7.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +5 -0
- data/README.md +79 -144
- data/Rakefile +0 -11
- data/lib/vra/catalog.rb +39 -8
- data/lib/vra/catalog_base.rb +62 -0
- data/lib/vra/catalog_item.rb +28 -74
- data/lib/vra/catalog_source.rb +116 -0
- data/lib/vra/catalog_type.rb +56 -0
- data/lib/vra/client.rb +62 -54
- 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 +1 -1
- data/lib/vra/http.rb +11 -6
- data/lib/vra/request.rb +28 -36
- data/lib/vra/request_parameters.rb +12 -12
- data/lib/vra/resource.rb +32 -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 +271 -226
- 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 +0 -1
- metadata +40 -30
- data/.travis.yml +0 -14
- data/lib/vra/catalog_request.rb +0 -137
- 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
data/spec/catalog_spec.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");
|
@@ -17,79 +17,43 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
22
|
describe Vra::Catalog do
|
23
23
|
let(:client) do
|
24
|
-
Vra::Client.new(
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
Vra::Client.new(
|
25
|
+
username: 'user@corp.local',
|
26
|
+
password: 'password',
|
27
|
+
tenant: 'tenant',
|
28
|
+
base_url: 'https://vra.corp.local'
|
29
|
+
)
|
28
30
|
end
|
29
31
|
|
30
32
|
let(:catalog_item) do
|
31
|
-
|
32
|
-
"@type" => "CatalogItem",
|
33
|
-
"id" => "a9cd6148-6e0b-4a80-ac47-f5255c52b43d",
|
34
|
-
"version" => 2,
|
35
|
-
"name" => "CentOS 6.6",
|
36
|
-
"description" => "Blueprint for deploying a CentOS Linux development server",
|
37
|
-
"status" => "PUBLISHED",
|
38
|
-
"statusName" => "Published",
|
39
|
-
"organization" => {
|
40
|
-
"tenantRef" => "vsphere.local",
|
41
|
-
"tenantLabel" => "vsphere.local",
|
42
|
-
"subtenantRef" => nil,
|
43
|
-
"subtenantLabel" => nil,
|
44
|
-
},
|
45
|
-
"providerBinding" => {
|
46
|
-
"bindingId" => "33af5413-4f20-4b3b-8268-32edad434dfb",
|
47
|
-
"providerRef" => {
|
48
|
-
"id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
|
49
|
-
"label" => "iaas-service",
|
50
|
-
},
|
51
|
-
},
|
52
|
-
}
|
33
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_catalog_item.json'))
|
53
34
|
end
|
54
35
|
|
55
36
|
let(:entitled_catalog_item) do
|
56
|
-
|
57
|
-
"@type" => "ConsumerEntitledCatalogItem",
|
58
|
-
"catalogItem" => {
|
59
|
-
"id" => "d29efd6b-3cd6-4f8d-b1d8-da4ddd4e52b1",
|
60
|
-
"version" => 2,
|
61
|
-
"name" => "WindowsServer2012",
|
62
|
-
"description" => "Windows Server 2012 with the latest updates and patches.",
|
63
|
-
"status" => "PUBLISHED",
|
64
|
-
"statusName" => "Published",
|
65
|
-
"organization" => {
|
66
|
-
"tenantRef" => "vsphere.local",
|
67
|
-
"tenantLabel" => "vsphere.local",
|
68
|
-
"subtenantRef" => nil,
|
69
|
-
"subtenantLabel" => nil,
|
70
|
-
},
|
71
|
-
"providerBinding" => {
|
72
|
-
"bindingId" => "59fd02a1-acca-4918-9d3d-2298d310caef",
|
73
|
-
"providerRef" => {
|
74
|
-
"id" => "c3b2bc30-47b0-454f-b57d-df02a7356fe6",
|
75
|
-
"label" => "iaas-service",
|
76
|
-
},
|
77
|
-
},
|
78
|
-
},
|
79
|
-
}
|
37
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_catalog_item_2.json'))
|
80
38
|
end
|
81
39
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
40
|
+
before(:each) do
|
41
|
+
allow(client).to receive(:authorized?).and_return(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#all_items' do
|
45
|
+
it 'calls the catalogItems endpoint' do
|
46
|
+
expect(client).to receive(:http_get_paginated_array!)
|
47
|
+
.with('/catalog/api/admin/items', nil)
|
48
|
+
.and_return([catalog_item])
|
86
49
|
|
87
50
|
client.catalog.all_items
|
88
51
|
end
|
89
52
|
|
90
|
-
it
|
91
|
-
allow(client).to receive(:http_get_paginated_array!)
|
92
|
-
.
|
53
|
+
it 'returns a Vra::CatalogItem object' do
|
54
|
+
allow(client).to receive(:http_get_paginated_array!)
|
55
|
+
.with('/catalog/api/admin/items', nil)
|
56
|
+
.and_return([catalog_item])
|
93
57
|
|
94
58
|
items = client.catalog.all_items
|
95
59
|
|
@@ -97,29 +61,105 @@ describe Vra::Catalog do
|
|
97
61
|
end
|
98
62
|
end
|
99
63
|
|
100
|
-
describe
|
101
|
-
it
|
102
|
-
expect(client).to receive(:
|
103
|
-
.
|
64
|
+
describe '#entitled_items' do
|
65
|
+
it 'calls the entitledCatalogItems endpoint' do
|
66
|
+
expect(client).to receive(:get_parsed)
|
67
|
+
.with('/catalog/api/admin/entitlements?projectId=pro-123456')
|
68
|
+
.and_return(JSON.parse(File.read('spec/fixtures/resource/sample_entitlements.json')))
|
104
69
|
|
105
|
-
client.catalog.entitled_items
|
70
|
+
client.catalog.entitled_items('pro-123456')
|
106
71
|
end
|
107
72
|
|
108
|
-
it
|
109
|
-
allow(client).to receive(:
|
110
|
-
.
|
73
|
+
it 'returns a Vra::CatalogItem object' do
|
74
|
+
allow(client).to receive(:get_parsed)
|
75
|
+
.with('/catalog/api/admin/entitlements?projectId=pro-123456')
|
76
|
+
.and_return(JSON.parse(File.read('spec/fixtures/resource/sample_entitlements.json')))
|
111
77
|
|
112
|
-
items = client.catalog.entitled_items
|
78
|
+
items = client.catalog.entitled_items('pro-123456')
|
113
79
|
|
114
80
|
expect(items.first).to be_an_instance_of(Vra::CatalogItem)
|
115
81
|
end
|
82
|
+
|
83
|
+
it 'return a Vra::CatalogSource object on source entitlements' do
|
84
|
+
allow(client).to receive(:get_parsed)
|
85
|
+
.with('/catalog/api/admin/entitlements?projectId=pro-123456')
|
86
|
+
.and_return(JSON.parse(File.read('spec/fixtures/resource/sample_entitlements.json')))
|
87
|
+
|
88
|
+
items = client.catalog.entitled_sources('pro-123456')
|
89
|
+
|
90
|
+
expect(items.first).to be_an_instance_of(Vra::CatalogSource)
|
91
|
+
end
|
116
92
|
end
|
117
93
|
|
118
|
-
describe
|
119
|
-
it
|
94
|
+
describe '#request' do
|
95
|
+
it 'returns a new Vra::CatalogRequest object' do
|
120
96
|
allow(Vra::CatalogItem).to receive(:new)
|
121
|
-
request = client.catalog.request(
|
122
|
-
expect(request).to be_an_instance_of(Vra::
|
97
|
+
request = client.catalog.request('blueprint-1', cpus: 2)
|
98
|
+
expect(request).to be_an_instance_of(Vra::DeploymentRequest)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#sources' do
|
103
|
+
let(:source_data) do
|
104
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_catalog_source.json'))
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should call the api to fetch the sources' do
|
108
|
+
expect(client).to receive(:http_get_paginated_array!)
|
109
|
+
.with('/catalog/api/admin/sources', nil)
|
110
|
+
.and_return([source_data])
|
111
|
+
|
112
|
+
client.catalog.all_sources
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return the Vra::CatalogSource object' do
|
116
|
+
expect(client).to receive(:http_get_paginated_array!)
|
117
|
+
.with('/catalog/api/admin/sources', nil)
|
118
|
+
.and_return([source_data])
|
119
|
+
|
120
|
+
source = client.catalog.all_sources.first
|
121
|
+
|
122
|
+
expect(source).to be_a(Vra::CatalogSource)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#types' do
|
127
|
+
let(:type_data) do
|
128
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_catalog_type.json'))
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should call the api to fetch the types' do
|
132
|
+
expect(client).to receive(:http_get_paginated_array!)
|
133
|
+
.with('/catalog/api/types', nil)
|
134
|
+
.and_return([type_data])
|
135
|
+
|
136
|
+
client.catalog.all_types
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should return the Vra::CatalogType object' do
|
140
|
+
expect(client).to receive(:http_get_paginated_array!)
|
141
|
+
.with('/catalog/api/types', nil)
|
142
|
+
.and_return([type_data])
|
143
|
+
|
144
|
+
source = client.catalog.all_types.first
|
145
|
+
|
146
|
+
expect(source).to be_a(Vra::CatalogType)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#fetch_catalog_by_name' do
|
151
|
+
let(:catalog_item) do
|
152
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_catalog_item.json'))
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'returns the catalogs by name' do
|
156
|
+
expect(client).to receive(:http_get_paginated_array!)
|
157
|
+
.with('/catalog/api/admin/items', 'search=centos')
|
158
|
+
.and_return([catalog_item])
|
159
|
+
|
160
|
+
cat = client.catalog.fetch_catalog_items('centos').first
|
161
|
+
|
162
|
+
expect(cat).to be_an_instance_of(Vra::CatalogItem)
|
123
163
|
end
|
124
164
|
end
|
125
165
|
end
|
@@ -0,0 +1,114 @@
|
|
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
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Vra::CatalogType do
|
22
|
+
let(:client) do
|
23
|
+
Vra::Client.new(
|
24
|
+
username: 'user@corp.local',
|
25
|
+
password: 'password',
|
26
|
+
tenant: 'tenant',
|
27
|
+
base_url: 'https://vra.corp.local'
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:sample_data) do
|
32
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_catalog_type.json'))
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#initialize' do
|
36
|
+
let(:cat_type) do
|
37
|
+
described_class.allocate
|
38
|
+
end
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
allow(client).to receive(:get_parsed).and_return(sample_data)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should validate and fetch data' do
|
45
|
+
expect(cat_type).to receive(:validate!)
|
46
|
+
expect(cat_type).to receive(:fetch_data)
|
47
|
+
|
48
|
+
cat_type.send(:initialize, client, id: 'com.vmw.vro.workflow')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should fetch data when id is passed' do
|
52
|
+
cat_type.send(:initialize, client, id: 'com.vmw.vro.workflow')
|
53
|
+
|
54
|
+
expect(cat_type.send(:data)).not_to be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should set id when data is passed' do
|
58
|
+
cat_type.send(:initialize, client, data: sample_data)
|
59
|
+
|
60
|
+
expect(cat_type.id).to eq('com.vmw.vro.workflow')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#validate' do
|
65
|
+
let(:cat_type) do
|
66
|
+
described_class.allocate
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should raise exception when neither id nor data passed' do
|
70
|
+
expect { cat_type.send(:initialize, client) }.to raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should raise exception when both id and data is passed' do
|
74
|
+
params = [client, { id: 'com.vmw.vra.workflow', data: sample_data }]
|
75
|
+
expect { cat_type.send(:initialize, *params) }.to raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#fetch_data' do
|
80
|
+
let(:cat_type) do
|
81
|
+
described_class.allocate
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should fetch the data correctly' do
|
85
|
+
allow(client).to receive(:get_parsed).and_return(sample_data)
|
86
|
+
cat_type.send(:initialize, client, id: 'com.vmw.vro.workflow')
|
87
|
+
|
88
|
+
data = cat_type.send(:data)
|
89
|
+
expect(data).not_to be_nil
|
90
|
+
expect(cat_type.id).to eq(data['id'])
|
91
|
+
expect(data['name']).to eq('vRealize Orchestrator Workflow')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should raise when catalog with type not found' do
|
95
|
+
allow(client).to receive(:get_parsed).and_raise(Vra::Exception::HTTPNotFound)
|
96
|
+
|
97
|
+
expect { cat_type.send(:initialize, client, id: sample_data['id']) }
|
98
|
+
.to raise_error(Vra::Exception::NotFound)
|
99
|
+
.with_message("catalog type ID #{sample_data['id']} does not exist")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'attributes' do
|
104
|
+
it 'should have the correct attributes' do
|
105
|
+
allow(client).to receive(:get_parsed).and_return(sample_data)
|
106
|
+
|
107
|
+
cat_type = described_class.new(client, id: sample_data['id'])
|
108
|
+
expect(cat_type.name).to eq('vRealize Orchestrator Workflow')
|
109
|
+
expect(cat_type.base_url).to eq('https://vra.corp.local:8080/vro')
|
110
|
+
expect(cat_type.config_schema).to eq(sample_data['configSchema'])
|
111
|
+
expect(cat_type.icon_id).to eq('0616ff81-c13b-32fe-b3b9-de3c2edd85dd')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|