kitchen-vcenter 2.11.8 → 2.11.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50205f05bf2e5fca3977374cccbd79fa2c703dea89fee58336aeb4d4286a9c1b
4
- data.tar.gz: 5ce2309de70acd22033ea4871903371c1948f4433d85650aebe15bc629a5897d
3
+ metadata.gz: 0531d4a30ba60e32b1f7a86df17e1dcf1caa611b5c9cd87372fb4364cb19fa48
4
+ data.tar.gz: a20d1df383cbfb37faf41fd2c85166f394bd37200a0f29bece61270037557a0a
5
5
  SHA512:
6
- metadata.gz: 4a5103e264c87f170405022b9b2fd0e9873365a7707ab023822276c6d312072ccd7ddb4d3de9ac3fef45f99c0c9c530a94e4627e367c8c5b7dfc2f92929ddcc0
7
- data.tar.gz: fcf0c459ebd8805fafe813d5d34e9bc085936c2df84e3679a3564ae27e464757564ae23579c01e18358aa394c2fd013330132ee934d59bc41d668a31cfab109b
6
+ metadata.gz: b41c0ebc3486ff91b56bfce5ef3e219554a53e5a491f74da60cae4d0df45dca22ef172b95ee2d712ea59d3d10cac39e075c4e192604a53b61dd9c02f7de7a4fe
7
+ data.tar.gz: e7dca5a3b4ff2f93e9a78cab79361b48015f43a652784dd4ccf705a446c5e314aa4af35a0bf80fb396804522289f457075b2eadffb3a7c2a5c91a0e9413f7c4d
@@ -20,5 +20,5 @@
20
20
  # The main kitchen-vcenter module
21
21
  module KitchenVcenter
22
22
  # The version of this version of test-kitchen we assume enterprises want.
23
- VERSION = "2.11.8"
23
+ VERSION = "2.11.9"
24
24
  end
@@ -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,41 +591,9 @@ 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
- unless network_device.nil? || options[:network_name].nil?
511
- networks = dc.network.select { |n| n.name == options[:network_name] }
512
- raise Support::CloneError.new(format("Could not find network named %s", options[:network_name])) if networks.empty?
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
@@ -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.8
4
+ version: 2.11.9
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-02-28 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ping