kitchen-vcenter 2.11.4 → 2.11.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kitchen-vcenter/version.rb +1 -1
- data/lib/support/clone_vm.rb +90 -36
- 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: 2814ca94153dd996897c1d357d2f538f07e699f47798d6bf8ca34b04d501ed8f
|
4
|
+
data.tar.gz: d1174b70520da7fcb424089ffc06928ef5bb272535640cad62cea16bca8d79cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12002adacfb368da1769950918f716a78b2b0a5533889d6541d473104572882c77ff0d2b48cfb16539eaf6ea027069de552e3c7e10e2ddf8782780c5ca8aa602
|
7
|
+
data.tar.gz: 3ff08fe608203a098b0b944e278c99c693a902cca9fcdc50154d25603ee515a755931aaedd2c99969bd55eaeaa4cfdd59451bdf5ec2823880862344435da423d
|
data/lib/support/clone_vm.rb
CHANGED
@@ -173,6 +173,14 @@ class Support
|
|
173
173
|
options[:vm_os].downcase.to_sym == :linux
|
174
174
|
end
|
175
175
|
|
176
|
+
def update_network?(network_device)
|
177
|
+
options[:network_name] && network_device
|
178
|
+
end
|
179
|
+
|
180
|
+
def add_network?(network_device)
|
181
|
+
options[:network_name] && network_device.nil?
|
182
|
+
end
|
183
|
+
|
176
184
|
def network_device(vm)
|
177
185
|
all_network_devices = vm.config.hardware.device.select do |device|
|
178
186
|
device.is_a?(RbVmomi::VIM::VirtualEthernetCard)
|
@@ -463,6 +471,82 @@ class Support
|
|
463
471
|
))
|
464
472
|
end
|
465
473
|
|
474
|
+
# This method will fetch the network which is configured in the kitchen.yml file with
|
475
|
+
# network_name configuration.
|
476
|
+
# If there are multiple networks with the same name, first one will be used.
|
477
|
+
#
|
478
|
+
# @return Network object
|
479
|
+
#
|
480
|
+
def fetch_network(datacenter)
|
481
|
+
networks = datacenter.network.select { |n| n.name == options[:network_name] }
|
482
|
+
raise Support::CloneError, format("Could not find network named %s", options[:network_name]) if networks.empty?
|
483
|
+
|
484
|
+
if networks.count > 1
|
485
|
+
Kitchen.logger.warn(
|
486
|
+
format("Found %d networks named %s, picking first one", networks.count, options[:network_name])
|
487
|
+
)
|
488
|
+
end
|
489
|
+
networks.first
|
490
|
+
end
|
491
|
+
|
492
|
+
# This is a helper method that can be used to create the deviceChange spec which can be used
|
493
|
+
# to add a new network device or update the existing network device
|
494
|
+
#
|
495
|
+
# The network_obj will be used as a backing for the network_device.
|
496
|
+
def network_change_spec(network_device, network_obj, operation: :edit)
|
497
|
+
if network_obj.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
|
498
|
+
Kitchen.logger.info format("Assigning network %s...", network_obj.pretty_path)
|
499
|
+
|
500
|
+
vds_obj = network_obj.config.distributedVirtualSwitch
|
501
|
+
Kitchen.logger.info format("Using vDS '%s' for network connectivity...", vds_obj.name)
|
502
|
+
|
503
|
+
network_device.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
|
504
|
+
port: RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
505
|
+
portgroupKey: network_obj.key,
|
506
|
+
switchUuid: vds_obj.uuid
|
507
|
+
)
|
508
|
+
)
|
509
|
+
elsif network_obj.is_a? RbVmomi::VIM::Network
|
510
|
+
Kitchen.logger.info format("Assigning network %s...", options[:network_name])
|
511
|
+
|
512
|
+
network_device.backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
|
513
|
+
deviceName: options[:network_name]
|
514
|
+
)
|
515
|
+
else
|
516
|
+
raise Support::CloneError, format("Unknown network type %s for network name %s", network_obj.class.to_s, options[:network_name])
|
517
|
+
end
|
518
|
+
|
519
|
+
[
|
520
|
+
RbVmomi::VIM.VirtualDeviceConfigSpec(
|
521
|
+
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation(operation),
|
522
|
+
device: network_device
|
523
|
+
),
|
524
|
+
]
|
525
|
+
end
|
526
|
+
|
527
|
+
# This method can be used to add new network device to the target vm
|
528
|
+
# This fill find the network which defined in kitchen.yml in network_name configuration
|
529
|
+
# and attach that to the target vm.
|
530
|
+
def add_new_network_device(datacenter)
|
531
|
+
network_obj = fetch_network(datacenter)
|
532
|
+
network_device = RbVmomi::VIM.VirtualVmxnet3(
|
533
|
+
key: 0,
|
534
|
+
deviceInfo: {
|
535
|
+
label: options[:network_name],
|
536
|
+
summary: options[:network_name],
|
537
|
+
}
|
538
|
+
)
|
539
|
+
|
540
|
+
config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
|
541
|
+
{
|
542
|
+
deviceChange: network_change_spec(network_device, network_obj, operation: :add),
|
543
|
+
}
|
544
|
+
)
|
545
|
+
|
546
|
+
task = vm.ReconfigVM_Task(spec: config_spec)
|
547
|
+
task.wait_for_completion
|
548
|
+
end
|
549
|
+
|
466
550
|
def clone
|
467
551
|
benchmark_start if benchmark?
|
468
552
|
|
@@ -507,47 +591,15 @@ class Support
|
|
507
591
|
network_device = network_device(src_vm)
|
508
592
|
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
593
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
Kitchen.logger.warn format("Found %d networks named %s, picking first one", networks.count, options[:network_name]) if networks.count > 1
|
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]))
|
537
|
-
end
|
538
|
-
|
539
|
-
relocate_spec.deviceChange = [
|
540
|
-
RbVmomi::VIM.VirtualDeviceConfigSpec(
|
541
|
-
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit"),
|
542
|
-
device: network_device
|
543
|
-
),
|
544
|
-
]
|
594
|
+
if update_network?(network_device)
|
595
|
+
network_obj = fetch_network(dc)
|
596
|
+
relocate_spec.deviceChange = network_change_spec(network_device, network_obj)
|
545
597
|
end
|
546
598
|
|
547
599
|
# Set the folder to use
|
548
600
|
dest_folder = options[:folder].nil? ? dc.vmFolder : options[:folder][:id]
|
549
601
|
|
550
|
-
Kitchen.logger.info format("Cloning '%s' to create the VM...", options[:template])
|
602
|
+
Kitchen.logger.info format("Cloning '%s' to create the %s VM...", options[:template], vm_name)
|
551
603
|
if instant_clone?
|
552
604
|
vcenter_data = vim.serviceInstance.content.about
|
553
605
|
raise Support::CloneError.new("Instant clones only supported with vCenter 6.7 or higher") unless vcenter_data.version.to_f >= 6.7
|
@@ -626,6 +678,8 @@ class Support
|
|
626
678
|
|
627
679
|
vm_customization if options[:vm_customization]
|
628
680
|
|
681
|
+
add_new_network_device(dc) if add_network?(network_device)
|
682
|
+
|
629
683
|
# Start only if specified or customizations wanted; no need for instant clones as they start in running state
|
630
684
|
if options[:poweron] && !options[:vm_customization].nil? && !instant_clone?
|
631
685
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ping
|