vra-restapi 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ {
2
+ "@type": "CatalogResource",
3
+ "id": "31a7badc-6562-458d-84f3-ec58d74a6953",
4
+ "resourceTypeRef": {
5
+ "id": "Infrastructure.Service",
6
+ "label": "Not a Virtual Machine"
7
+ },
8
+ "name": "hol-dev-12",
9
+ "status": "ACTIVE",
10
+ "organization": {
11
+ "tenantRef": "vsphere.local",
12
+ "tenantLabel": "vsphere.local",
13
+ "subtenantRef": "5327ddd3-1a4e-4663-9e9d-63db86ffc8af",
14
+ "subtenantLabel": "Rainpole Developers"
15
+ },
16
+ "resourceData": {
17
+ }
18
+ }
@@ -0,0 +1,251 @@
1
+ {
2
+ "@type": "CatalogResource",
3
+ "id": "31a7badc-6562-458d-84f3-ec58d74a6953",
4
+ "resourceTypeRef": {
5
+ "id": "Infrastructure.Virtual",
6
+ "label": "Virtual Machine"
7
+ },
8
+ "name": "hol-dev-11",
9
+ "description": "test-description",
10
+ "status": "ACTIVE",
11
+ "organization": {
12
+ "tenantRef": "vsphere.local",
13
+ "tenantLabel": "vsphere.local",
14
+ "subtenantRef": "5327ddd3-1a4e-4663-9e9d-63db86ffc8af",
15
+ "subtenantLabel": "Rainpole Developers"
16
+ },
17
+ "owners": [
18
+ {"tenantName": "vsphere.local", "ref": "user1@corp.local", "type": "USER", "value": "Joe User"},
19
+ {"tenantName": "vsphere.local", "ref": "user2@corp.local", "type": "USER", "value": "Jane User"}
20
+ ],
21
+ "operations": [
22
+ {
23
+ "name": "Change Lease",
24
+ "description": "Change the lease for a machine. Leave empty for indefinite.",
25
+ "iconId": "machineChangeLease.png",
26
+ "type": "ACTION",
27
+ "id": "50a50fde-2c8e-4122-acad-77cca348ae23",
28
+ "extensionId": null,
29
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
30
+ "bindingId": "Infrastructure.Machine.Action.ChangeLease",
31
+ "hasForm": true,
32
+ "formScale": "SMALL"
33
+ },
34
+ {
35
+ "name": "Connect to Remote Console",
36
+ "description": "Infrastructure connect using remote console",
37
+ "iconId": "cafe_default_icon_genericResourceOperation",
38
+ "type": "EXTENSION",
39
+ "id": "24c98f8e-6e9b-4f4e-b4df-460a29c80e1a",
40
+ "extensionId": "csp.places.iaas.item.window.ConnectViaVmrc",
41
+ "providerTypeId": null,
42
+ "bindingId": null,
43
+ "hasForm": false,
44
+ "formScale": null
45
+ },
46
+ {
47
+ "name": "Destroy",
48
+ "description": "Destroy a virtual machine.",
49
+ "iconId": "virtualDestroy.png",
50
+ "type": "ACTION",
51
+ "id": "ace8ba42-e724-48d8-9614-9b3a62b5a464",
52
+ "extensionId": null,
53
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
54
+ "bindingId": "Infrastructure.Virtual.Action.Destroy",
55
+ "hasForm": false,
56
+ "formScale": null
57
+ },
58
+ {
59
+ "name": "Expire",
60
+ "description": "Expire a machine.",
61
+ "iconId": "machineExpire.png",
62
+ "type": "ACTION",
63
+ "id": "34f354b5-4f09-495d-a553-646bbdc2d4b4",
64
+ "extensionId": null,
65
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
66
+ "bindingId": "Infrastructure.Machine.Action.Expire",
67
+ "hasForm": false,
68
+ "formScale": null
69
+ },
70
+ {
71
+ "name": "Install Tools",
72
+ "description": "Install tools on a machine.",
73
+ "iconId": "machineInstallTools.png",
74
+ "type": "ACTION",
75
+ "id": "2798f564-ba80-4e3a-b2c9-70aa686ed6a7",
76
+ "extensionId": null,
77
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
78
+ "bindingId": "Infrastructure.Machine.Action.InstallTools",
79
+ "hasForm": false,
80
+ "formScale": null
81
+ },
82
+ {
83
+ "name": "Power Cycle",
84
+ "description": "Reset a machine.",
85
+ "iconId": "machineReset.png",
86
+ "type": "ACTION",
87
+ "id": "9c1c2d9a-9ccc-46fc-bb5d-36632bdb3167",
88
+ "extensionId": null,
89
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
90
+ "bindingId": "Infrastructure.Machine.Action.Reset",
91
+ "hasForm": false,
92
+ "formScale": null
93
+ },
94
+ {
95
+ "name": "Power Off",
96
+ "description": "Power off a machine.",
97
+ "iconId": "machinePowerOff.png",
98
+ "type": "ACTION",
99
+ "id": "a391186c-7a3c-44fc-8d3d-3f5dcc269c85",
100
+ "extensionId": null,
101
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
102
+ "bindingId": "Infrastructure.Machine.Action.PowerOff",
103
+ "hasForm": false,
104
+ "formScale": null
105
+ },
106
+ {
107
+ "name": "Reboot",
108
+ "description": "Reboot a machine.",
109
+ "iconId": "machineReboot.png",
110
+ "type": "ACTION",
111
+ "id": "e71a9cae-7e8b-46a4-83fa-cfa4731669e4",
112
+ "extensionId": null,
113
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
114
+ "bindingId": "Infrastructure.Machine.Action.Reboot",
115
+ "hasForm": false,
116
+ "formScale": null
117
+ },
118
+ {
119
+ "name": "Reconfigure",
120
+ "description": "Reconfigure a machine.",
121
+ "iconId": "machineReconfigure.png",
122
+ "type": "ACTION",
123
+ "id": "1db5df1b-cb05-495d-a577-874b97af951e",
124
+ "extensionId": null,
125
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
126
+ "bindingId": "Infrastructure.Machine.Action.Reconfigure",
127
+ "hasForm": true,
128
+ "formScale": "BIG"
129
+ },
130
+ {
131
+ "name": "Reprovision",
132
+ "description": "Reprovision a machine.",
133
+ "iconId": "machineReprovision.png",
134
+ "type": "ACTION",
135
+ "id": "3ba6fdd8-d36b-48aa-8314-5437441fdea4",
136
+ "extensionId": null,
137
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
138
+ "bindingId": "Infrastructure.Machine.Action.Reprovision",
139
+ "hasForm": true,
140
+ "formScale": "BIG"
141
+ },
142
+ {
143
+ "name": "Shutdown",
144
+ "description": "Shutdown a machine.",
145
+ "iconId": "machineShutdown.png",
146
+ "type": "ACTION",
147
+ "id": "38231238-b979-43de-8697-1d61193e09c5",
148
+ "extensionId": null,
149
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
150
+ "bindingId": "Infrastructure.Machine.Action.Shutdown",
151
+ "hasForm": false,
152
+ "formScale": null
153
+ },
154
+ {
155
+ "name": "Suspend",
156
+ "description": "Suspend a machine.",
157
+ "iconId": "machineSuspend.png",
158
+ "type": "ACTION",
159
+ "id": "48e64dc6-f147-4977-94f7-4acfd4599b96",
160
+ "extensionId": null,
161
+ "providerTypeId": "com.vmware.csp.iaas.blueprint.service",
162
+ "bindingId": "Infrastructure.Machine.Action.Suspend",
163
+ "hasForm": false,
164
+ "formScale": null
165
+ }
166
+ ],
167
+ "resourceData": {
168
+ "entries": [
169
+ {
170
+ "key": "Expire",
171
+ "value": {
172
+ "type": "boolean",
173
+ "value": true
174
+ }
175
+ },
176
+ {
177
+ "key": "NETWORK_LIST",
178
+ "value": {
179
+ "type": "multiple",
180
+ "elementTypeId": "COMPLEX",
181
+ "items": [
182
+ {
183
+ "type": "complex",
184
+ "componentTypeId": "com.vmware.csp.component.iaas.proxy.provider",
185
+ "componentId": null,
186
+ "classId": "dynamicops.api.model.NetworkViewModel",
187
+ "typeFilter": null,
188
+ "values": {
189
+ "entries": [
190
+ {
191
+ "key": "NETWORK_ADDRESS",
192
+ "value": {
193
+ "type": "string",
194
+ "value": "192.168.110.200"
195
+ }
196
+ },
197
+ {
198
+ "key": "NETWORK_MAC_ADDRESS",
199
+ "value": {
200
+ "type": "string",
201
+ "value": "00:50:56:ae:95:3c"
202
+ }
203
+ },
204
+ {
205
+ "key": "NETWORK_NAME",
206
+ "value": {
207
+ "type": "string",
208
+ "value": "VM Network"
209
+ }
210
+ }
211
+ ]
212
+ }
213
+ },
214
+ {
215
+ "type": "complex",
216
+ "componentTypeId": "com.vmware.csp.component.iaas.proxy.provider",
217
+ "componentId": null,
218
+ "classId": "dynamicops.api.model.NetworkViewModel",
219
+ "typeFilter": null,
220
+ "values": {
221
+ "entries": [
222
+ {
223
+ "key": "NETWORK_ADDRESS",
224
+ "value": {
225
+ "type": "string",
226
+ "value": "192.168.220.200"
227
+ }
228
+ },
229
+ {
230
+ "key": "NETWORK_MAC_ADDRESS",
231
+ "value": {
232
+ "type": "string",
233
+ "value": "00:50:56:ae:95:3d"
234
+ }
235
+ },
236
+ {
237
+ "key": "NETWORK_NAME",
238
+ "value": {
239
+ "type": "string",
240
+ "value": "Management Network"
241
+ }
242
+ }
243
+ ]
244
+ }
245
+ }
246
+ ]
247
+ }
248
+ }
249
+ ]
250
+ }
251
+ }
@@ -0,0 +1,101 @@
1
+ {
2
+ "@type": "CatalogResource",
3
+ "id": "31a7badc-6562-458d-84f3-ec58d74a6953",
4
+ "resourceTypeRef": {
5
+ "id": "Infrastructure.Virtual",
6
+ "label": "Virtual Machine"
7
+ },
8
+ "name": "hol-dev-11",
9
+ "status": "ACTIVE",
10
+ "organization": {
11
+ "tenantRef": "vsphere.local",
12
+ "tenantLabel": "vsphere.local",
13
+ "subtenantRef": "5327ddd3-1a4e-4663-9e9d-63db86ffc8af",
14
+ "subtenantLabel": "Rainpole Developers"
15
+ },
16
+ "operations": null,
17
+ "resourceData": {
18
+ "entries": [
19
+ {
20
+ "key": "Expire",
21
+ "value": {
22
+ "type": "boolean",
23
+ "value": true
24
+ }
25
+ },
26
+ {
27
+ "key": "NETWORK_LIST",
28
+ "value": {
29
+ "type": "multiple",
30
+ "elementTypeId": "COMPLEX",
31
+ "items": [
32
+ {
33
+ "type": "complex",
34
+ "componentTypeId": "com.vmware.csp.component.iaas.proxy.provider",
35
+ "componentId": null,
36
+ "classId": "dynamicops.api.model.NetworkViewModel",
37
+ "typeFilter": null,
38
+ "values": {
39
+ "entries": [
40
+ {
41
+ "key": "NETWORK_ADDRESS",
42
+ "value": {
43
+ "type": "string",
44
+ "value": "192.168.110.200"
45
+ }
46
+ },
47
+ {
48
+ "key": "NETWORK_MAC_ADDRESS",
49
+ "value": {
50
+ "type": "string",
51
+ "value": "00:50:56:ae:95:3c"
52
+ }
53
+ },
54
+ {
55
+ "key": "NETWORK_NAME",
56
+ "value": {
57
+ "type": "string",
58
+ "value": "VM Network"
59
+ }
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ {
65
+ "type": "complex",
66
+ "componentTypeId": "com.vmware.csp.component.iaas.proxy.provider",
67
+ "componentId": null,
68
+ "classId": "dynamicops.api.model.NetworkViewModel",
69
+ "typeFilter": null,
70
+ "values": {
71
+ "entries": [
72
+ {
73
+ "key": "NETWORK_ADDRESS",
74
+ "value": {
75
+ "type": "string",
76
+ "value": "192.168.220.200"
77
+ }
78
+ },
79
+ {
80
+ "key": "NETWORK_MAC_ADDRESS",
81
+ "value": {
82
+ "type": "string",
83
+ "value": "00:50:56:ae:95:3d"
84
+ }
85
+ },
86
+ {
87
+ "key": "NETWORK_NAME",
88
+ "value": {
89
+ "type": "string",
90
+ "value": "Management Network"
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ }
96
+ ]
97
+ }
98
+ }
99
+ ]
100
+ }
101
+ }
@@ -0,0 +1,145 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ shared_examples 'refresh_trigger_method' do |method|
22
+ it 'calls #refresh_if_needed' do
23
+ expect(request).to receive(:refresh_if_empty)
24
+ request.send(method)
25
+ end
26
+
27
+ it 'returns nil if request data is empty' do
28
+ allow(request).to receive(:refresh_if_empty)
29
+ allow(request).to receive(:request_empty?).and_return true
30
+ expect(request.send(method)).to eq nil
31
+ end
32
+ end
33
+
34
+ describe Vra::Request do
35
+ let(:client) do
36
+ Vra::Client.new(username: 'user@corp.local',
37
+ password: 'password',
38
+ tenant: 'tenant',
39
+ base_url: 'https://vra.corp.local')
40
+ end
41
+
42
+ let(:request_id) { '2c3df007-b1c4-4687-b332-310089c4851d' }
43
+
44
+ let(:in_progress_payload) do
45
+ {
46
+ 'phase' => 'IN_PROGRESS',
47
+ 'requestCompletion' => {
48
+ 'requestCompletionState' => nil,
49
+ 'completionDetails' => nil
50
+ }
51
+ }
52
+ end
53
+
54
+ let(:completed_payload) do
55
+ {
56
+ 'phase' => 'SUCCESSFUL',
57
+ 'requestCompletion' => {
58
+ 'requestCompletionState' => 'SUCCESSFUL',
59
+ 'completionDetails' => 'Request succeeded. Created test-machine.'
60
+ }
61
+ }
62
+ end
63
+
64
+ let(:request) { Vra::Request.new(client, request_id) }
65
+
66
+ describe '#initialize' do
67
+ it 'sets the id' do
68
+ expect(request.id).to eq request_id
69
+ end
70
+ end
71
+
72
+ describe '#refresh' do
73
+ it 'calls the request API endpoint' do
74
+ expect(client).to receive(:http_get!)
75
+ .with("/catalog-service/api/consumer/requests/#{request_id}")
76
+ .and_return(in_progress_payload.to_json)
77
+
78
+ request.refresh
79
+ end
80
+ end
81
+
82
+ describe '#refresh_if_empty' do
83
+ context 'request data is empty' do
84
+ it 'calls #refresh' do
85
+ expect(request).to receive(:refresh)
86
+ request.refresh_if_empty
87
+ end
88
+ end
89
+
90
+ context 'request data is not empty' do
91
+ it 'does not call #refresh' do
92
+ allow(request).to receive(:request_empty?).and_return(false)
93
+ expect(request).to_not receive(:refresh)
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '#status' do
99
+ it_behaves_like 'refresh_trigger_method', :status
100
+ end
101
+
102
+ describe '#completed?' do
103
+ context 'when the request is neither successful or failed yet' do
104
+ it 'returns false' do
105
+ allow(request).to receive(:successful?).and_return(false)
106
+ allow(request).to receive(:failed?).and_return(false)
107
+ expect(request.completed?).to eq false
108
+ end
109
+ end
110
+
111
+ context 'when the request is successful' do
112
+ it 'returns true' do
113
+ allow(request).to receive(:successful?).and_return(true)
114
+ allow(request).to receive(:failed?).and_return(false)
115
+ expect(request.completed?).to eq true
116
+ end
117
+ end
118
+
119
+ context 'when the request failed' do
120
+ it 'returns true' do
121
+ allow(request).to receive(:successful?).and_return(false)
122
+ allow(request).to receive(:failed?).and_return(true)
123
+ expect(request.completed?).to eq true
124
+ end
125
+ end
126
+ end
127
+
128
+ describe '#completion_state' do
129
+ it_behaves_like 'refresh_trigger_method', :completion_state
130
+ end
131
+
132
+ describe '#completion_details' do
133
+ it_behaves_like 'refresh_trigger_method', :completion_details
134
+ end
135
+
136
+ describe '#resources' do
137
+ it 'calls the requests resources API endpoint' do
138
+ expect(client).to receive(:http_get_paginated_array!)
139
+ .with("/catalog-service/api/consumer/requests/#{request_id}/resources")
140
+ .and_return([])
141
+
142
+ request.resources
143
+ end
144
+ end
145
+ end