vmware-vra 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/vra/resource.rb +67 -14
- data/lib/vra/version.rb +1 -1
- data/spec/fixtures/resource/vm_resource.json +1 -0
- data/spec/resource_spec.rb +131 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 563dc4afc43f55acb9a8730e85c36eb056bf8659
|
4
|
+
data.tar.gz: 7cd1b95d64942372852164ae4a9d46d7b29eb102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfd135e158d35ff715734115ba2185762d680b397e4488bb7d3afa4ff19a7c8cb64b58f244512d9c4d12d60f8822c349bc02e8dcc308cff5c9b3bac59e1006e3
|
7
|
+
data.tar.gz: f32e242fe52fdb7596de59cf6d792f7097fd3b9a514e80204b608219b6f7799c15cd4f6f73db7b71d8c0c24797cfced5ceae64232ad5f68366c9db91ccab7b27
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## v1.3.0
|
2
|
+
* [pr#13](https://github.com/chef-partners/vmware-vra-gem/pull/13) Additional methods to support a vRA driver for Chef Provisioning
|
3
|
+
|
1
4
|
## v1.2.0
|
2
5
|
* [pr#11](https://github.com/chef-partners/vmware-vra-gem/pull/11) Ability to set paginated results page size, which is a workaround for issue reported in #10 regarding duplicate items returned in paginated results.
|
3
6
|
|
data/lib/vra/resource.rb
CHANGED
@@ -49,55 +49,87 @@ module Vra
|
|
49
49
|
rescue Vra::Exception::HTTPNotFound
|
50
50
|
raise Vra::Exception::NotFound, "resource ID #{@id} does not exist"
|
51
51
|
end
|
52
|
+
alias_method :refresh, :fetch_resource_data
|
52
53
|
|
53
54
|
def name
|
54
|
-
|
55
|
+
resource_data['name']
|
56
|
+
end
|
57
|
+
|
58
|
+
def description
|
59
|
+
resource_data['description']
|
55
60
|
end
|
56
61
|
|
57
62
|
def status
|
58
|
-
|
63
|
+
resource_data['status']
|
59
64
|
end
|
60
65
|
|
61
66
|
def vm?
|
62
|
-
|
67
|
+
resource_data['resourceTypeRef']['id'] == 'Infrastructure.Virtual'
|
63
68
|
end
|
64
69
|
|
65
70
|
def tenant_id
|
66
|
-
|
71
|
+
resource_data['organization']['tenantRef']
|
67
72
|
end
|
68
73
|
|
69
74
|
def tenant_name
|
70
|
-
|
75
|
+
resource_data['organization']['tenantLabel']
|
71
76
|
end
|
72
77
|
|
73
78
|
def subtenant_id
|
74
|
-
|
79
|
+
resource_data['organization']['subtenantRef']
|
75
80
|
end
|
76
81
|
|
77
82
|
def subtenant_name
|
78
|
-
|
83
|
+
resource_data['organization']['subtenantLabel']
|
79
84
|
end
|
80
85
|
|
81
86
|
def catalog_id
|
82
|
-
|
87
|
+
resource_data['catalogItem']['id']
|
83
88
|
end
|
84
89
|
|
85
90
|
def catalog_name
|
86
|
-
|
91
|
+
resource_data['catalogItem']['label']
|
87
92
|
end
|
88
93
|
|
89
94
|
def owner_ids
|
90
|
-
|
95
|
+
resource_data['owners'].map { |x| x['ref'] }
|
91
96
|
end
|
92
97
|
|
93
98
|
def owner_names
|
94
|
-
|
99
|
+
resource_data['owners'].map { |x| x['value'] }
|
100
|
+
end
|
101
|
+
|
102
|
+
def machine_status
|
103
|
+
status = resource_data['resourceData']['entries'].find { |x| x['key'] == 'MachineStatus' }
|
104
|
+
raise 'No MachineStatus entry available for resource' if status.nil?
|
105
|
+
|
106
|
+
status['value']['value']
|
107
|
+
end
|
108
|
+
|
109
|
+
def machine_on?
|
110
|
+
machine_status == 'On'
|
111
|
+
end
|
112
|
+
|
113
|
+
def machine_off?
|
114
|
+
machine_status == 'Off'
|
115
|
+
end
|
116
|
+
|
117
|
+
def machine_turning_on?
|
118
|
+
machine_status == 'TurningOn'
|
119
|
+
end
|
120
|
+
|
121
|
+
def machine_turning_off?
|
122
|
+
%w(TurningOff ShuttingDown).include?(machine_status)
|
123
|
+
end
|
124
|
+
|
125
|
+
def machine_in_provisioned_state?
|
126
|
+
machine_status == 'MachineProvisioned'
|
95
127
|
end
|
96
128
|
|
97
129
|
def network_interfaces
|
98
130
|
return unless vm?
|
99
131
|
|
100
|
-
network_list =
|
132
|
+
network_list = resource_data['resourceData']['entries'].find { |x| x['key'] == 'NETWORK_LIST' }
|
101
133
|
return if network_list.nil?
|
102
134
|
|
103
135
|
network_list['value']['items'].each_with_object([]) do |item, nics|
|
@@ -127,9 +159,9 @@ module Vra
|
|
127
159
|
def actions
|
128
160
|
# if this Resource instance was created with data from a "all_resources" fetch,
|
129
161
|
# it is likely missing operations data because the vRA API is not pleasant sometimes.
|
130
|
-
fetch_resource_data if
|
162
|
+
fetch_resource_data if resource_data['operations'].nil?
|
131
163
|
|
132
|
-
|
164
|
+
resource_data['operations']
|
133
165
|
end
|
134
166
|
|
135
167
|
def action_id_by_name(name)
|
@@ -148,6 +180,27 @@ module Vra
|
|
148
180
|
submit_action_request(action_id)
|
149
181
|
end
|
150
182
|
|
183
|
+
def shutdown
|
184
|
+
action_id = action_id_by_name('Shutdown')
|
185
|
+
raise Vra::Exception::NotFound, "No shutdown action found for resource #{@id}" if action_id.nil?
|
186
|
+
|
187
|
+
submit_action_request(action_id)
|
188
|
+
end
|
189
|
+
|
190
|
+
def poweroff
|
191
|
+
action_id = action_id_by_name('Power Off')
|
192
|
+
raise Vra::Exception::NotFound, "No power-off action found for resource #{@id}" if action_id.nil?
|
193
|
+
|
194
|
+
submit_action_request(action_id)
|
195
|
+
end
|
196
|
+
|
197
|
+
def poweron
|
198
|
+
action_id = action_id_by_name('Power On')
|
199
|
+
raise Vra::Exception::NotFound, "No power-on action found for resource #{@id}" if action_id.nil?
|
200
|
+
|
201
|
+
submit_action_request(action_id)
|
202
|
+
end
|
203
|
+
|
151
204
|
def action_request_payload(action_id)
|
152
205
|
{
|
153
206
|
'@type' => 'ResourceActionRequest',
|
data/lib/vra/version.rb
CHANGED
data/spec/resource_spec.rb
CHANGED
@@ -19,6 +19,23 @@
|
|
19
19
|
require 'spec_helper'
|
20
20
|
require 'ffi_yajl'
|
21
21
|
|
22
|
+
shared_examples_for 'a resource action' do |action_method, action_name|
|
23
|
+
context 'when the action is available' do
|
24
|
+
it 'calls gets the action ID and submits the request' do
|
25
|
+
expect(resource).to receive(:action_id_by_name).with(action_name).and_return('action-123')
|
26
|
+
expect(resource).to receive(:submit_action_request).with('action-123')
|
27
|
+
resource.send(action_method)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the action is not available' do
|
32
|
+
it 'raises an exception' do
|
33
|
+
expect(resource).to receive(:action_id_by_name).with(action_name).and_return nil
|
34
|
+
expect { resource.send(action_method) }.to raise_error(Vra::Exception::NotFound)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
22
39
|
describe Vra::Resource do
|
23
40
|
let(:client) do
|
24
41
|
Vra::Client.new(username: 'user@corp.local',
|
@@ -93,6 +110,12 @@ describe Vra::Resource do
|
|
93
110
|
end
|
94
111
|
end
|
95
112
|
|
113
|
+
describe '#description' do
|
114
|
+
it 'returns the correct description' do
|
115
|
+
expect(resource.description).to eq 'test-description'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
96
119
|
describe '#status' do
|
97
120
|
it 'returns the correct status' do
|
98
121
|
expect(resource.status).to eq 'ACTIVE'
|
@@ -141,6 +164,102 @@ describe Vra::Resource do
|
|
141
164
|
end
|
142
165
|
end
|
143
166
|
|
167
|
+
describe '#machine_status' do
|
168
|
+
context 'when no MachineStatus exists' do
|
169
|
+
let(:resource_data) { { 'resourceData' => { 'entries' => [] } } }
|
170
|
+
|
171
|
+
it 'raises an exception' do
|
172
|
+
allow(resource).to receive(:resource_data).and_return(resource_data)
|
173
|
+
expect { resource.machine_status }.to raise_error(RuntimeError)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when MachineStatus Exists' do
|
178
|
+
let(:resource_data) do
|
179
|
+
{
|
180
|
+
'resourceData' => {
|
181
|
+
'entries' => [
|
182
|
+
{
|
183
|
+
'key' => 'MachineStatus',
|
184
|
+
'value' => { 'type' => 'string', 'value' => 'Off' }
|
185
|
+
}
|
186
|
+
]
|
187
|
+
}
|
188
|
+
}
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'returns the correct status value' do
|
192
|
+
allow(resource).to receive(:resource_data).and_return(resource_data)
|
193
|
+
expect(resource.machine_status).to eq('Off')
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe '#machine_on?' do
|
199
|
+
it 'returns true if the machine_status is On' do
|
200
|
+
allow(resource).to receive(:machine_status).and_return('On')
|
201
|
+
expect(resource.machine_on?).to eq(true)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'returns false if the machine_status is not On' do
|
205
|
+
allow(resource).to receive(:machine_status).and_return('Off')
|
206
|
+
expect(resource.machine_on?).to eq(false)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe '#machine_off?' do
|
211
|
+
it 'returns true if the machine_status is Off' do
|
212
|
+
allow(resource).to receive(:machine_status).and_return('Off')
|
213
|
+
expect(resource.machine_off?).to eq(true)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'returns false if the machine_status is not Off' do
|
217
|
+
allow(resource).to receive(:machine_status).and_return('On')
|
218
|
+
expect(resource.machine_off?).to eq(false)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe '#machine_turning_on?' do
|
223
|
+
it 'returns true if the machine_status is TurningOn' do
|
224
|
+
allow(resource).to receive(:machine_status).and_return('TurningOn')
|
225
|
+
expect(resource.machine_turning_on?).to eq(true)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'returns false if the machine_status is not TurningOn' do
|
229
|
+
allow(resource).to receive(:machine_status).and_return('On')
|
230
|
+
expect(resource.machine_turning_on?).to eq(false)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe '#machine_turning_off?' do
|
235
|
+
it 'returns true if the machine_status is TurningOff' do
|
236
|
+
allow(resource).to receive(:machine_status).and_return('TurningOff')
|
237
|
+
expect(resource.machine_turning_off?).to eq(true)
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'returns true if the machine_status is ShuttingDown' do
|
241
|
+
allow(resource).to receive(:machine_status).and_return('ShuttingDown')
|
242
|
+
expect(resource.machine_turning_off?).to eq(true)
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'returns false if the machine_status is not TurningOff or ShuttingDown' do
|
246
|
+
allow(resource).to receive(:machine_status).and_return('Off')
|
247
|
+
expect(resource.machine_turning_off?).to eq(false)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe '#machine_in_provisioned_state?' do
|
252
|
+
it 'returns true if the machine_status is MachineProvisioned' do
|
253
|
+
allow(resource).to receive(:machine_status).and_return('MachineProvisioned')
|
254
|
+
expect(resource.machine_in_provisioned_state?).to eq(true)
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'returns false if the machine_status is not MachineProvisioned' do
|
258
|
+
allow(resource).to receive(:machine_status).and_return('On')
|
259
|
+
expect(resource.machine_in_provisioned_state?).to eq(false)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
144
263
|
describe '#network_interfaces' do
|
145
264
|
it 'returns an array of 2 elements' do
|
146
265
|
expect(resource.network_interfaces.size).to be 2
|
@@ -194,20 +313,19 @@ describe Vra::Resource do
|
|
194
313
|
end
|
195
314
|
|
196
315
|
describe '#destroy' do
|
197
|
-
|
198
|
-
|
199
|
-
expect(resource).to receive(:action_id_by_name).with('Destroy').and_return('action-123')
|
200
|
-
expect(resource).to receive(:submit_action_request).with('action-123')
|
201
|
-
resource.destroy
|
202
|
-
end
|
203
|
-
end
|
316
|
+
it_behaves_like 'a resource action', :destroy, 'Destroy'
|
317
|
+
end
|
204
318
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
319
|
+
describe '#shutdown' do
|
320
|
+
it_behaves_like 'a resource action', :shutdown, 'Shutdown'
|
321
|
+
end
|
322
|
+
|
323
|
+
describe '#poweroff' do
|
324
|
+
it_behaves_like 'a resource action', :poweroff, 'Power Off'
|
325
|
+
end
|
326
|
+
|
327
|
+
describe '#poweron' do
|
328
|
+
it_behaves_like 'a resource action', :poweron, 'Power On'
|
211
329
|
end
|
212
330
|
|
213
331
|
describe '#submit_action_request' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmware-vra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Leff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.4.
|
183
|
+
rubygems_version: 2.4.8
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: Client gem for interacting with VMware vRealize Automation.
|