kitchen-vcenter 2.11.8 → 2.11.13
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/lib/kitchen/driver/vcenter.rb +15 -2
- data/lib/kitchen-vcenter/version.rb +1 -1
- data/lib/support/clone_vm.rb +124 -35
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0942877c46827be0844a6e167180e1f34f97112da87a8d5789d3adc16dc95f28'
|
|
4
|
+
data.tar.gz: f87d1169572ae5b43f70d9d1e324034a982158fd18a1f6910e2baf538927f461
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad70d62b377f2afe4938d11ab896b77bb281cdb02e10a602e0d3530d959f874fdc00297d44fd90b8159598515a2b768a346973284bbfb7b1c08e882710fbcfbf
|
|
7
|
+
data.tar.gz: 55d2274fcff17c6c677401b602ada26deafa6c16faffa388ea21cc1712706f591cd4ee79e66560756902666dd32fb049b896b24677d008c3aedc833e9730f5f1
|
|
@@ -56,6 +56,7 @@ module Kitchen
|
|
|
56
56
|
default_config :clone_type, :full
|
|
57
57
|
default_config :cluster, nil
|
|
58
58
|
default_config :network_name, nil
|
|
59
|
+
default_config :networks, []
|
|
59
60
|
default_config :tags, nil
|
|
60
61
|
default_config :vm_wait_timeout, 90
|
|
61
62
|
default_config :vm_wait_interval, 2.0
|
|
@@ -94,6 +95,11 @@ module Kitchen
|
|
|
94
95
|
The `customize` setting was renamed to `vm_customization` and will
|
|
95
96
|
be removed in future versions.
|
|
96
97
|
MSG
|
|
98
|
+
deprecate_config_for :network_name, Util.outdent!(<<-MSG)
|
|
99
|
+
The `network_name` setting is deprecated and will be removed in the
|
|
100
|
+
future version. Please use the new settings `networks` and refer
|
|
101
|
+
documentation for the usage.
|
|
102
|
+
MSG
|
|
97
103
|
|
|
98
104
|
# The main create method
|
|
99
105
|
#
|
|
@@ -145,7 +151,7 @@ module Kitchen
|
|
|
145
151
|
config[:targethost] = get_host(config[:targethost], datacenter, cluster_id)
|
|
146
152
|
|
|
147
153
|
# Check if network exists, if to be changed
|
|
148
|
-
|
|
154
|
+
config[:networks].each { |network| network_exists?(network[:name]) }
|
|
149
155
|
|
|
150
156
|
# Same thing needs to happen with the folder name if it has been set
|
|
151
157
|
unless config[:folder].nil?
|
|
@@ -172,7 +178,7 @@ module Kitchen
|
|
|
172
178
|
folder: config[:folder],
|
|
173
179
|
resource_pool: config[:resource_pool],
|
|
174
180
|
clone_type: config[:clone_type].to_sym,
|
|
175
|
-
|
|
181
|
+
networks: config[:networks],
|
|
176
182
|
interface: config[:interface],
|
|
177
183
|
wait_timeout: config[:vm_wait_timeout],
|
|
178
184
|
wait_interval: config[:vm_wait_interval],
|
|
@@ -286,6 +292,13 @@ module Kitchen
|
|
|
286
292
|
config[:vm_username] = config[:aggressive_username] unless config[:aggressive_username].nil?
|
|
287
293
|
config[:vm_password] = config[:aggressive_password] unless config[:aggressive_password].nil?
|
|
288
294
|
config[:vm_customization] = config[:customize] unless config[:customize].nil?
|
|
295
|
+
validate_network_parameters
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def validate_network_parameters
|
|
299
|
+
return if config[:network_name].nil?
|
|
300
|
+
|
|
301
|
+
config[:networks] = [{ name: config[:network_name], operation: "edit" }]
|
|
289
302
|
end
|
|
290
303
|
|
|
291
304
|
# A helper method to validate the state
|
data/lib/support/clone_vm.rb
CHANGED
|
@@ -173,6 +173,39 @@ class Support
|
|
|
173
173
|
options[:vm_os].downcase.to_sym == :linux
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
+
# Network configured to update the existing one in the template
|
|
177
|
+
#
|
|
178
|
+
def networks_to_update
|
|
179
|
+
options[:networks].select { |n| n[:operation] == "edit" }
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# New networks that needs to be attached to newly created vm
|
|
183
|
+
#
|
|
184
|
+
def networks_to_add
|
|
185
|
+
options[:networks].select { |n| [nil, "add"].include?(n[:operation]) }
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# A network should update if there is a network_device available in the template
|
|
189
|
+
# and the user configured a new network with edit operation.
|
|
190
|
+
#
|
|
191
|
+
def update_network?(network_device)
|
|
192
|
+
networks_to_update.any? && network_device
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Checks whether any networks configured for addition
|
|
196
|
+
def add_network?
|
|
197
|
+
networks_to_add.any?
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# TODO: Remove this method and its invocations after the deprecation of `network_name` config
|
|
201
|
+
# For backward compatibility
|
|
202
|
+
# If the template doesn't have any NIC and the user use the old
|
|
203
|
+
# configuration(network_name), then that network should be attached to the vm.
|
|
204
|
+
#
|
|
205
|
+
def attach_new_network?(network_device)
|
|
206
|
+
network_device.nil? && networks_to_update.any?
|
|
207
|
+
end
|
|
208
|
+
|
|
176
209
|
def network_device(vm)
|
|
177
210
|
all_network_devices = vm.config.hardware.device.select do |device|
|
|
178
211
|
device.is_a?(RbVmomi::VIM::VirtualEthernetCard)
|
|
@@ -463,6 +496,85 @@ class Support
|
|
|
463
496
|
))
|
|
464
497
|
end
|
|
465
498
|
|
|
499
|
+
# This method will fetch the network which is configured in the kitchen.yml file with
|
|
500
|
+
# network_name configuration.
|
|
501
|
+
# If there are multiple networks with the same name, first one will be used.
|
|
502
|
+
#
|
|
503
|
+
# @return Network object
|
|
504
|
+
#
|
|
505
|
+
def fetch_network(datacenter, network_name)
|
|
506
|
+
networks = datacenter.network.select { |n| n.name == network_name }
|
|
507
|
+
raise Support::CloneError, format("Could not find network named %s", network_name) if networks.empty?
|
|
508
|
+
|
|
509
|
+
if networks.count > 1
|
|
510
|
+
Kitchen.logger.warn(
|
|
511
|
+
format("Found %d networks named %s, picking first one", networks.count, network_name)
|
|
512
|
+
)
|
|
513
|
+
end
|
|
514
|
+
networks.first
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
# This is a helper method that can be used to create the deviceChange spec which can be used
|
|
518
|
+
# to add a new network device or update the existing network device
|
|
519
|
+
#
|
|
520
|
+
# The network_obj will be used as a backing for the network_device.
|
|
521
|
+
def network_change_spec(network_device, network_obj, network_name, operation: :edit)
|
|
522
|
+
if network_obj.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
|
|
523
|
+
Kitchen.logger.info format("Assigning network %s...", network_obj.pretty_path)
|
|
524
|
+
|
|
525
|
+
vds_obj = network_obj.config.distributedVirtualSwitch
|
|
526
|
+
Kitchen.logger.info format("Using vDS '%s' for network connectivity...", vds_obj.name)
|
|
527
|
+
|
|
528
|
+
network_device.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
|
|
529
|
+
port: RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
|
530
|
+
portgroupKey: network_obj.key,
|
|
531
|
+
switchUuid: vds_obj.uuid
|
|
532
|
+
)
|
|
533
|
+
)
|
|
534
|
+
elsif network_obj.is_a? RbVmomi::VIM::Network
|
|
535
|
+
Kitchen.logger.info format("Assigning network %s...", network_name)
|
|
536
|
+
|
|
537
|
+
network_device.backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
|
|
538
|
+
deviceName: network_name
|
|
539
|
+
)
|
|
540
|
+
else
|
|
541
|
+
raise Support::CloneError, format("Unknown network type %s for network name %s", network_obj.class.to_s, network_name)
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
RbVmomi::VIM.VirtualDeviceConfigSpec(
|
|
545
|
+
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation(operation),
|
|
546
|
+
device: network_device
|
|
547
|
+
)
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
# This method can be used to add new network device to the target vm
|
|
551
|
+
# This fill find the network which defined in kitchen.yml in network_name configuration
|
|
552
|
+
# and attach that to the target vm.
|
|
553
|
+
def add_new_network_device(datacenter, networks)
|
|
554
|
+
device_change = []
|
|
555
|
+
networks.each do |network|
|
|
556
|
+
network_obj = fetch_network(datacenter, network[:name])
|
|
557
|
+
network_device = RbVmomi::VIM.VirtualVmxnet3(
|
|
558
|
+
key: 0,
|
|
559
|
+
deviceInfo: {
|
|
560
|
+
label: network[:name],
|
|
561
|
+
summary: network[:name],
|
|
562
|
+
}
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
device_change << network_change_spec(network_device, network_obj, network[:name], operation: :add)
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
|
|
569
|
+
{
|
|
570
|
+
deviceChange: device_change,
|
|
571
|
+
}
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
task = vm.ReconfigVM_Task(spec: config_spec)
|
|
575
|
+
task.wait_for_completion
|
|
576
|
+
end
|
|
577
|
+
|
|
466
578
|
def clone
|
|
467
579
|
benchmark_start if benchmark?
|
|
468
580
|
|
|
@@ -507,47 +619,19 @@ class Support
|
|
|
507
619
|
network_device = network_device(src_vm)
|
|
508
620
|
Kitchen.logger.warn format("Source VM/template does not have any network device (use VMware IPPools and vsphere-gom transport or govc to access)") unless network_device
|
|
509
621
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
network_obj = networks.first
|
|
516
|
-
|
|
517
|
-
if network_obj.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
|
|
518
|
-
Kitchen.logger.info format("Assigning network %s...", network_obj.pretty_path)
|
|
519
|
-
|
|
520
|
-
vds_obj = network_obj.config.distributedVirtualSwitch
|
|
521
|
-
Kitchen.logger.info format("Using vDS '%s' for network connectivity...", vds_obj.name)
|
|
522
|
-
|
|
523
|
-
network_device.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
|
|
524
|
-
port: RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
|
525
|
-
portgroupKey: network_obj.key,
|
|
526
|
-
switchUuid: vds_obj.uuid
|
|
527
|
-
)
|
|
528
|
-
)
|
|
529
|
-
elsif network_obj.is_a? RbVmomi::VIM::Network
|
|
530
|
-
Kitchen.logger.info format("Assigning network %s...", options[:network_name])
|
|
531
|
-
|
|
532
|
-
network_device.backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
|
|
533
|
-
deviceName: options[:network_name]
|
|
534
|
-
)
|
|
535
|
-
else
|
|
536
|
-
raise Support::CloneError.new(format("Unknown network type %s for network name %s", network_obj.class.to_s, options[:network_name]))
|
|
622
|
+
if update_network?(network_device)
|
|
623
|
+
network_spec = []
|
|
624
|
+
networks_to_update.each do |network|
|
|
625
|
+
network_obj = fetch_network(dc, network[:name])
|
|
626
|
+
network_spec << network_change_spec(network_device, network_obj, network[:name])
|
|
537
627
|
end
|
|
538
|
-
|
|
539
|
-
relocate_spec.deviceChange = [
|
|
540
|
-
RbVmomi::VIM.VirtualDeviceConfigSpec(
|
|
541
|
-
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit"),
|
|
542
|
-
device: network_device
|
|
543
|
-
),
|
|
544
|
-
]
|
|
628
|
+
relocate_spec.deviceChange = network_spec
|
|
545
629
|
end
|
|
546
630
|
|
|
547
631
|
# Set the folder to use
|
|
548
632
|
dest_folder = options[:folder].nil? ? dc.vmFolder : options[:folder][:id]
|
|
549
633
|
|
|
550
|
-
Kitchen.logger.info format("Cloning '%s' to create the VM...", options[:template])
|
|
634
|
+
Kitchen.logger.info format("Cloning '%s' to create the %s VM...", options[:template], vm_name)
|
|
551
635
|
if instant_clone?
|
|
552
636
|
vcenter_data = vim.serviceInstance.content.about
|
|
553
637
|
raise Support::CloneError.new("Instant clones only supported with vCenter 6.7 or higher") unless vcenter_data.version.to_f >= 6.7
|
|
@@ -626,6 +710,11 @@ class Support
|
|
|
626
710
|
|
|
627
711
|
vm_customization if options[:vm_customization]
|
|
628
712
|
|
|
713
|
+
# TODO: Remove this line after the deprecation of `network_name` config
|
|
714
|
+
add_new_network_device(dc, networks_to_update) if attach_new_network?(network_device)
|
|
715
|
+
|
|
716
|
+
add_new_network_device(dc, networks_to_add) if add_network?
|
|
717
|
+
|
|
629
718
|
# Start only if specified or customizations wanted; no need for instant clones as they start in running state
|
|
630
719
|
if options[:poweron] && !options[:vm_customization].nil? && !instant_clone?
|
|
631
720
|
task = vm.PowerOnVM_Task
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kitchen-vcenter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.11.
|
|
4
|
+
version: 2.11.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chef Software
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: net-ping
|