chef-provisioning-vsphere 2.2.0 → 2.2.1
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/CHANGELOG.md +8 -1
- data/lib/chef/provisioning/vsphere_driver/driver.rb +7 -55
- data/lib/chef/provisioning/vsphere_driver/version.rb +1 -1
- data/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb +37 -6
- data/spec/unit_tests/clone_spec_builder_spec.rb +4 -4
- data/spec/unit_tests/vsphere_helpers_spec.rb +183 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92dd7232f0e413e7c361d52694f55afaa06ff284
|
4
|
+
data.tar.gz: e2fade153c0e0fc4afa2743fd3fa630cd5edc722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ec7e70b47e2297b91cba24d7c22e5d95ae67e873a472c269a988c95f3e04a92de2a29ba9dee10de014dd47d78f65e77ec5f2bc4983f4d6f4661a07442ee2288
|
7
|
+
data.tar.gz: 2f6e4e64d1dffeb4880463c6e8d3ee991924068d38aa8f9e159022c727bacda2a1d5c4ebee386f7aed9b03473392904b99529d9e003e282f5214b2ee0d523789
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v2.2.
|
3
|
+
## [v2.2.1](https://github.com/chef-partners/chef-provisioning-vsphere/tree/v2.2.1)
|
4
4
|
|
5
|
+
[Full Changelog](https://github.com/chef-partners/chef-provisioning-vsphere/compare/v2.2.0...v2.2.1)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Fixes bug where additional disks added twice [\#84](https://github.com/chef-partners/chef-provisioning-vsphere/pull/84) ([josh-barker](https://github.com/josh-barker))
|
10
|
+
|
11
|
+
## [v2.2.0](https://github.com/chef-partners/chef-provisioning-vsphere/tree/v2.2.0) (2018-06-01)
|
5
12
|
[Full Changelog](https://github.com/chef-partners/chef-provisioning-vsphere/compare/v2.1.0...v2.2.0)
|
6
13
|
|
7
14
|
**Merged pull requests:**
|
@@ -88,7 +88,7 @@ module ChefProvisioningVsphere
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
attr_reader :connect_options
|
91
|
+
attr_reader :connect_options
|
92
92
|
|
93
93
|
# Creates a new vm_helper if not already there
|
94
94
|
#
|
@@ -291,7 +291,7 @@ module ChefProvisioningVsphere
|
|
291
291
|
end
|
292
292
|
|
293
293
|
## Check if true available after added nic
|
294
|
-
|
294
|
+
vm_helper.open_port?(machine_spec.location['ipaddress'], vm_helper.port) unless machine_spec.location['ipaddress'].nil?
|
295
295
|
machine
|
296
296
|
end
|
297
297
|
|
@@ -312,7 +312,7 @@ module ChefProvisioningVsphere
|
|
312
312
|
bootstrap_options,
|
313
313
|
vm
|
314
314
|
)
|
315
|
-
if is_windows?(vm) && !new_nics.nil? &&
|
315
|
+
if is_windows?(vm) && !new_nics.nil? && vm_helper.open_port?(machine_spec.location['ipaddress'], vm_helper.port)
|
316
316
|
new_nics.each do |nic|
|
317
317
|
nic_label = nic.device.deviceInfo.label
|
318
318
|
machine.execute_always(
|
@@ -687,57 +687,9 @@ module ChefProvisioningVsphere
|
|
687
687
|
vm = vsphere_helper.find_vm(vm_folder, machine_name)
|
688
688
|
add_machine_spec_location(vm, machine_spec)
|
689
689
|
|
690
|
-
additional_disk_size_gb = Array(bootstrap_options[:additional_disk_size_gb])
|
691
|
-
|
692
|
-
|
693
690
|
vsphere_helper.update_main_disk_size_for(vm, bootstrap_options[:main_disk_size_gb])
|
694
691
|
vsphere_helper.set_additional_disks_for(vm, bootstrap_options[:datastore], bootstrap_options[:additional_disk_size_gb])
|
695
|
-
|
696
|
-
raise ':datastore must be specified when adding a disk to a cloned vm'
|
697
|
-
end
|
698
|
-
|
699
|
-
additional_disk_size_gb.each do |size|
|
700
|
-
size = size.to_i
|
701
|
-
next if size == 0
|
702
|
-
task = vm.ReconfigVM_Task(
|
703
|
-
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
704
|
-
deviceChange: [
|
705
|
-
vsphere_helper.virtual_disk_for(
|
706
|
-
vm,
|
707
|
-
bootstrap_options[:datastore],
|
708
|
-
size
|
709
|
-
)
|
710
|
-
]
|
711
|
-
)
|
712
|
-
)
|
713
|
-
task.wait_for_completion
|
714
|
-
end
|
715
|
-
|
716
|
-
|
717
|
-
if bootstrap_options[:initial_iso_image]
|
718
|
-
d_obj = vm.config.hardware.device.select {|hw| hw.class == RbVmomi::VIM::VirtualCdrom}.first
|
719
|
-
backing = RbVmomi::VIM::VirtualCdromIsoBackingInfo(fileName: bootstrap_options[:initial_iso_image])
|
720
|
-
task = vm.ReconfigVM_Task(
|
721
|
-
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
722
|
-
deviceChange: [
|
723
|
-
operation: :edit,
|
724
|
-
device: RbVmomi::VIM::VirtualCdrom(
|
725
|
-
backing: backing,
|
726
|
-
key: d_obj.key,
|
727
|
-
controllerKey: d_obj.controllerKey,
|
728
|
-
connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
|
729
|
-
startConnected: true,
|
730
|
-
connected: true,
|
731
|
-
|
732
|
-
allowGuestControl: true
|
733
|
-
)
|
734
|
-
|
735
|
-
)
|
736
|
-
]
|
737
|
-
)
|
738
|
-
)
|
739
|
-
task.wait_for_completion
|
740
|
-
end
|
692
|
+
vsphere_helper.set_initial_iso(vm, bootstrap_options[:initial_iso_file])
|
741
693
|
|
742
694
|
vm
|
743
695
|
end
|
@@ -818,7 +770,7 @@ module ChefProvisioningVsphere
|
|
818
770
|
# @param [Object] vm The VM object from Chef-Provisioning
|
819
771
|
# @param [Object] action_handler taken from Chef provisioning for TODO.
|
820
772
|
def wait_for_transport(action_handler, machine_spec, machine_options, vm)
|
821
|
-
|
773
|
+
vm_helper.find_port?(vm, machine_options[:bootstrap_options]) if vm_helper.port.nil?
|
822
774
|
transport = transport_for(
|
823
775
|
machine_spec,
|
824
776
|
machine_options[:bootstrap_options][:ssh]
|
@@ -865,7 +817,7 @@ module ChefProvisioningVsphere
|
|
865
817
|
else
|
866
818
|
options[:winrm_transport].nil? ? :negotiate : options[:winrm_transport].to_sym
|
867
819
|
end
|
868
|
-
port = options[:port] ||
|
820
|
+
port = options[:port] || vm_helper.port
|
869
821
|
winrm_options = {
|
870
822
|
user: (options[:user]).to_s,
|
871
823
|
pass: options[:password]
|
@@ -939,7 +891,7 @@ module ChefProvisioningVsphere
|
|
939
891
|
# Then check that it is reachable
|
940
892
|
until Time.now.utc - start_time > timeout
|
941
893
|
print '.'
|
942
|
-
return vm_ip.to_s if
|
894
|
+
return vm_ip.to_s if vm_helper.open_port?(vm_ip, vm_helper.port, 1)
|
943
895
|
sleep 1
|
944
896
|
end
|
945
897
|
raise "Timed out (#{timeout}s) waiting for ip #{vm_ip} to be connectable"
|
@@ -133,7 +133,7 @@ module ChefProvisioningVsphere
|
|
133
133
|
vim # ensure connection is valid
|
134
134
|
@datacenter ||= begin
|
135
135
|
rootFolder = vim.serviceInstance.content.rootFolder
|
136
|
-
dc = traverse_folders_for_dc(vim.rootFolder, datacenter_name) || abort(
|
136
|
+
dc = traverse_folders_for_dc(vim.rootFolder, datacenter_name) || abort("vSphere Datacenter not found [#{datacenter_name}]")
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -259,12 +259,12 @@ module ChefProvisioningVsphere
|
|
259
259
|
# @param [Subject] datastore the datastore the disk will be created on.
|
260
260
|
# @param [Subject] size_gb the size of the disk.
|
261
261
|
def set_additional_disks_for(vm, datastore, additional_disk_size_gb)
|
262
|
-
|
262
|
+
raise ':datastore must be specified when adding a disk to a cloned vm' if datastore.to_s.empty? && additional_disk_size_gb
|
263
|
+
|
264
|
+
Array(additional_disk_size_gb).each do |size|
|
263
265
|
size = size.to_i
|
264
|
-
next if size
|
265
|
-
|
266
|
-
raise ':datastore must be specified when adding a disk to a cloned vm'
|
267
|
-
end
|
266
|
+
next if size <= 0
|
267
|
+
|
268
268
|
task = vm.ReconfigVM_Task(
|
269
269
|
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
270
270
|
deviceChange: [
|
@@ -280,6 +280,37 @@ module ChefProvisioningVsphere
|
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
|
+
# Mounts the an iso on the first virtual CD ROm
|
284
|
+
#
|
285
|
+
# @param [Object] vm the VM object.
|
286
|
+
# @param [Subject] name of the iso file
|
287
|
+
def set_initial_iso(vm, initial_iso_image)
|
288
|
+
return unless initial_iso_image
|
289
|
+
|
290
|
+
d_obj = vm.config.hardware.device.select { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }.first
|
291
|
+
backing = RbVmomi::VIM::VirtualCdromIsoBackingInfo(fileName: initial_iso_image)
|
292
|
+
|
293
|
+
task = vm.ReconfigVM_Task(
|
294
|
+
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
295
|
+
deviceChange: [
|
296
|
+
operation: :edit,
|
297
|
+
device: RbVmomi::VIM::VirtualCdrom(
|
298
|
+
backing: backing,
|
299
|
+
key: d_obj.key,
|
300
|
+
controllerKey: d_obj.controllerKey,
|
301
|
+
connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
|
302
|
+
startConnected: true,
|
303
|
+
connected: true,
|
304
|
+
|
305
|
+
allowGuestControl: true
|
306
|
+
)
|
307
|
+
)
|
308
|
+
]
|
309
|
+
)
|
310
|
+
)
|
311
|
+
task.wait_for_completion
|
312
|
+
end
|
313
|
+
|
283
314
|
# Updates the main virtual disk for the VM
|
284
315
|
# This can only add capacity to the main disk, it is not possible to reduce the capacity.
|
285
316
|
#
|
@@ -98,7 +98,7 @@ describe ChefProvisioningVsphere::CloneSpecBuilder do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'raises an error' do
|
101
|
-
expect { subject }.to raise_error
|
101
|
+
expect { subject }.to raise_error(RuntimeError)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -139,7 +139,7 @@ describe ChefProvisioningVsphere::CloneSpecBuilder do
|
|
139
139
|
let(:hostname) { 'my_host' }
|
140
140
|
|
141
141
|
it 'raises an error' do
|
142
|
-
expect { subject }.to raise_error
|
142
|
+
expect { subject }.to raise_error(RuntimeError)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -147,7 +147,7 @@ describe ChefProvisioningVsphere::CloneSpecBuilder do
|
|
147
147
|
let(:hostname) { '-myhost' }
|
148
148
|
|
149
149
|
it 'raises an error' do
|
150
|
-
expect { subject }.to raise_error
|
150
|
+
expect { subject }.to raise_error(RuntimeError)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -155,7 +155,7 @@ describe ChefProvisioningVsphere::CloneSpecBuilder do
|
|
155
155
|
let(:hostname) { 'myhost-' }
|
156
156
|
|
157
157
|
it 'raises an error' do
|
158
|
-
expect { subject }.to raise_error
|
158
|
+
expect { subject }.to raise_error(RuntimeError)
|
159
159
|
end
|
160
160
|
end
|
161
161
|
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'chef/provisioning/vsphere_driver'
|
2
|
+
|
3
|
+
describe ChefProvisioningVsphere::VsphereHelper do
|
4
|
+
let(:subject) do
|
5
|
+
connection_opts = {
|
6
|
+
host: 'fake.host.com',
|
7
|
+
port: 443
|
8
|
+
}
|
9
|
+
ChefProvisioningVsphere::VsphereHelper.new(connection_opts, 'fake datacenter')
|
10
|
+
end
|
11
|
+
let(:vm) { vm = double('vm') }
|
12
|
+
let(:task) { double('task', wait_for_completion: true) }
|
13
|
+
|
14
|
+
describe '#set_additional_disks_for' do
|
15
|
+
before do
|
16
|
+
allow(vm).to receive(:disks).and_return(['root_disk'], ['root_disk', 'first_disk'])
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when datastore is missing' do
|
20
|
+
let(:datastore) { nil }
|
21
|
+
it 'and no extra disks, nothing is raised' do
|
22
|
+
additional_disk_size_gb = nil
|
23
|
+
expect { subject.set_additional_disks_for vm, datastore, additional_disk_size_gb }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'and has 1 disk, error is raised' do
|
27
|
+
additional_disk_size_gb = 1
|
28
|
+
expect { subject.set_additional_disks_for vm, datastore, additional_disk_size_gb }.to raise_error(RuntimeError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'and has multiple disks, error is raised' do
|
32
|
+
additional_disk_size_gb = [1, 2]
|
33
|
+
expect { subject.set_additional_disks_for vm, datastore, additional_disk_size_gb }.to raise_error(RuntimeError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when datastore is present' do
|
38
|
+
let(:datastore) { 'some datastore' }
|
39
|
+
let(:disk_1) do
|
40
|
+
{
|
41
|
+
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
42
|
+
deviceChange: [
|
43
|
+
RbVmomi::VIM::VirtualDeviceConfigSpec(
|
44
|
+
operation: :add,
|
45
|
+
fileOperation: :create,
|
46
|
+
device: RbVmomi::VIM.VirtualDisk(
|
47
|
+
key: 1,
|
48
|
+
backing: RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
|
49
|
+
fileName: "[#{datastore}]",
|
50
|
+
diskMode: 'persistent',
|
51
|
+
thinProvisioned: true
|
52
|
+
),
|
53
|
+
capacityInKB: 1 * 1024 * 1024,
|
54
|
+
controllerKey: 1000,
|
55
|
+
unitNumber: 1
|
56
|
+
)
|
57
|
+
)
|
58
|
+
]
|
59
|
+
)
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:disk_2) do
|
64
|
+
{
|
65
|
+
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
66
|
+
deviceChange: [
|
67
|
+
RbVmomi::VIM::VirtualDeviceConfigSpec(
|
68
|
+
operation: :add,
|
69
|
+
fileOperation: :create,
|
70
|
+
device: RbVmomi::VIM.VirtualDisk(
|
71
|
+
key: 2,
|
72
|
+
backing: RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
|
73
|
+
fileName: "[#{datastore}]",
|
74
|
+
diskMode: 'persistent',
|
75
|
+
thinProvisioned: true
|
76
|
+
),
|
77
|
+
capacityInKB: 2 * 1024 * 1024,
|
78
|
+
controllerKey: 1000,
|
79
|
+
unitNumber: 2
|
80
|
+
)
|
81
|
+
)
|
82
|
+
]
|
83
|
+
)
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'and no extra disks, nothing is created' do
|
88
|
+
additional_disk_size_gb = nil
|
89
|
+
expect(vm).not_to receive(:ReconfigVM_Task)
|
90
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'and disk is a string, nothing is created' do
|
94
|
+
additional_disk_size_gb = ['not a number']
|
95
|
+
expect(vm).not_to receive(:ReconfigVM_Task)
|
96
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'and has 0 GB, nothing is created' do
|
100
|
+
additional_disk_size_gb = [0]
|
101
|
+
expect(vm).not_to receive(:ReconfigVM_Task)
|
102
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'and has -1 GB, nothing is created' do
|
106
|
+
additional_disk_size_gb = [-1]
|
107
|
+
expect(vm).not_to receive(:ReconfigVM_Task)
|
108
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'and has 1 x 1 GB, create disk' do
|
112
|
+
additional_disk_size_gb = 1
|
113
|
+
expect(vm).to receive(:ReconfigVM_Task).with(disk_1).and_return(task)
|
114
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'and has 2 disks, create 2 disks' do
|
118
|
+
additional_disk_size_gb = [1, 2]
|
119
|
+
|
120
|
+
expect(vm).to receive(:ReconfigVM_Task).with(disk_1).and_return(task)
|
121
|
+
expect(vm).to receive(:ReconfigVM_Task).with(disk_2).and_return(task)
|
122
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'and has 3 disks, including 1 of 0 size, create 2 disks' do
|
126
|
+
additional_disk_size_gb = [0, 1, 2]
|
127
|
+
expect(vm).to receive(:ReconfigVM_Task).with(disk_1).and_return(task)
|
128
|
+
expect(vm).to receive(:ReconfigVM_Task).with(disk_2).and_return(task)
|
129
|
+
|
130
|
+
subject.set_additional_disks_for vm, datastore, additional_disk_size_gb
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#set_initial_iso' do
|
136
|
+
let(:cd_rom) do
|
137
|
+
double('cd_rom',
|
138
|
+
class: RbVmomi::VIM::VirtualCdrom,
|
139
|
+
key: 'some key',
|
140
|
+
controllerKey: 'some controller key'
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
let(:fake_backing) do
|
145
|
+
RbVmomi::VIM::VirtualCdromIsoBackingInfo(fileName: 'some_iso.iso')
|
146
|
+
end
|
147
|
+
|
148
|
+
let(:iso_spec) do
|
149
|
+
{
|
150
|
+
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
151
|
+
deviceChange: [
|
152
|
+
operation: :edit,
|
153
|
+
device: RbVmomi::VIM::VirtualCdrom(
|
154
|
+
backing: fake_backing,
|
155
|
+
key: 'some key',
|
156
|
+
controllerKey: 'some controller key',
|
157
|
+
connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
|
158
|
+
startConnected: true,
|
159
|
+
connected: true,
|
160
|
+
allowGuestControl: true
|
161
|
+
)
|
162
|
+
)
|
163
|
+
]
|
164
|
+
)
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
before do
|
169
|
+
allow(vm).to receive_message_chain(:config, :hardware, :device)
|
170
|
+
.and_return([cd_rom])
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'does nothing when no iso' do
|
174
|
+
expect(vm).not_to receive(:ReconfigVM_Task)
|
175
|
+
subject.set_initial_iso vm, nil
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'sets initial iso' do
|
179
|
+
expect(vm).to receive(:ReconfigVM_Task).with(iso_spec).and_return(task)
|
180
|
+
subject.set_initial_iso vm, 'some_iso.iso'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-provisioning-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CenturyLink Cloud
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-06-
|
12
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- spec/unit_tests/clone_spec_builder_spec.rb
|
251
251
|
- spec/unit_tests/support/fake_action_handler.rb
|
252
252
|
- spec/unit_tests/support/vsphere_helper_stub.rb
|
253
|
+
- spec/unit_tests/vsphere_helpers_spec.rb
|
253
254
|
homepage: https://github.com/chef-partners/chef-provisioning-vsphere
|
254
255
|
licenses:
|
255
256
|
- MIT
|
@@ -283,3 +284,4 @@ test_files:
|
|
283
284
|
- spec/unit_tests/clone_spec_builder_spec.rb
|
284
285
|
- spec/unit_tests/support/fake_action_handler.rb
|
285
286
|
- spec/unit_tests/support/vsphere_helper_stub.rb
|
287
|
+
- spec/unit_tests/vsphere_helpers_spec.rb
|