kitchen-vcenter 2.7.8 → 2.8.6

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: 9e4016eb3acf59b1720fa8db8a286182337c9bd38528a94b52796f29f7779497
4
- data.tar.gz: 7b73e59e8e6437d819fcede40a6bf34fcb691e44211a8b7ecc0d5b66db02dae9
3
+ metadata.gz: 1da356cf16429bae878bc2a5672f2c574c9cd82028914f4aca53d1311955eb4c
4
+ data.tar.gz: ddf119be74e493604cef87b3cf3d45e2c486492a26eeac5fd5bb6c21ef58a38a
5
5
  SHA512:
6
- metadata.gz: 9fecbd078bec90c376c8c502926790e4d9bf308ddd8fc30b3911e2e06998fd63d6f21c7f2ce38c31e7227dd5b723506ab5da21d693797b6195653d1867d1af49
7
- data.tar.gz: 5304bc077b139e731ab5530c9f76ea26292b0349b89109f924f873d3098f7ca6ac1d0d0b032a348fc26f00ce010402befac0db5a958f0ddab41ae0eac8dae04a
6
+ metadata.gz: '07824b2bb5850ba139bea24ea65082c602e6e56ea79903a3645ce90d64ff1614e35eeee52ce1dae68670d688be6c9aaec577eab283ac4efb5fcfc4d9da23af1b'
7
+ data.tar.gz: a3d4f536ad36b3bf666183a607f2ba06a8bbfe9806e2e1917db30b65ec900a808fd69977587df44622e71f9a9ebce3363581c9cc689992f0fa8aac815457f93d
@@ -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.7.8"
23
+ VERSION = "2.8.6"
24
24
  end
@@ -20,8 +20,8 @@ require "vsphere-automation-cis"
20
20
  require "vsphere-automation-vcenter"
21
21
  require_relative "../../kitchen-vcenter/version"
22
22
  require_relative "../../support/clone_vm"
23
- require "securerandom"
24
- require "uri"
23
+ require "securerandom" unless defined?(SecureRandom)
24
+ require "uri" unless defined?(URI)
25
25
 
26
26
  # The main kitchen module
27
27
  module Kitchen
@@ -137,7 +137,7 @@ module Kitchen
137
137
  unless config[:folder].nil?
138
138
  config[:folder] = {
139
139
  name: config[:folder],
140
- id: get_folder(config[:folder]),
140
+ id: get_folder(config[:folder], "VIRTUAL_MACHINE", datacenter),
141
141
  }
142
142
  end
143
143
 
@@ -335,13 +335,19 @@ module Kitchen
335
335
  #
336
336
  # @param [name] name is the name of the folder
337
337
  # @param [type] type is the type of the folder, one of VIRTUAL_MACHINE, DATACENTER, possibly other values
338
- def get_folder(name, type = "VIRTUAL_MACHINE")
338
+ # @param [datacenter] datacenter is the datacenter of the folder
339
+ def get_folder(name, type = "VIRTUAL_MACHINE", datacenter = nil)
339
340
  folder_api = VSphereAutomation::VCenter::FolderApi.new(api_client)
340
- folders = folder_api.list({ filter_names: name, filter_type: type }).value
341
+ parent_path, basename = File.split(name)
342
+ filter = { filter_names: basename, filter_type: type }
343
+ filter[:filter_datacenters] = datacenter if datacenter
344
+ filter[:filter_parent_folders] = get_folder(parent_path, type, datacenter) unless parent_path == "."
341
345
 
342
- raise format("Unable to find folder: %s", name) if folders.empty?
346
+ folders = folder_api.list(filter).value
343
347
 
344
- raise format("%s returned too many folders", name) if folders.length > 1
348
+ raise format("Unable to find folder: %s", basename) if folders.empty?
349
+
350
+ raise format("`%s` returned too many folders", basename) if folders.length > 1
345
351
 
346
352
  folders.first.folder
347
353
  end
@@ -377,7 +383,7 @@ module Kitchen
377
383
  #
378
384
  # @param [name] name is the name of the Cluster
379
385
  def get_cluster_id(name)
380
- return nil if name.nil?
386
+ return if name.nil?
381
387
 
382
388
  cluster_api = VSphereAutomation::VCenter::ClusterApi.new(api_client)
383
389
  clusters = cluster_api.list({ filter_names: name }).value
@@ -365,7 +365,7 @@ class Support
365
365
 
366
366
  disk_spec.device.controllerKey = controller.key
367
367
 
368
- highest_id = vm.disks.map(&:unitNumber).sort.last
368
+ highest_id = vm.disks.map(&:unitNumber).max
369
369
  next_id = highest_id + idx + 1
370
370
 
371
371
  # Avoid the SCSI controller ID
@@ -425,7 +425,10 @@ class Support
425
425
  def find_datacenter
426
426
  vim.serviceInstance.find_datacenter(datacenter)
427
427
  rescue RbVmomi::Fault
428
- root_folder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == datacenter }
428
+ dc = root_folder.findByInventoryPath(datacenter)
429
+ return dc if dc.is_a?(RbVmomi::VIM::Datacenter)
430
+
431
+ raise Support::CloneError.new("Unable to locate datacenter at '#{datacenter}'")
429
432
  end
430
433
 
431
434
  def ip?(string)
@@ -440,18 +443,36 @@ class Support
440
443
  return false
441
444
  end
442
445
 
443
- unless ip?(options[:guest_customization][:ip_address])
444
- raise Support::CloneError.new("Guest customization error: ip_address is required to be formatted as an IPv4 address")
445
- end
446
+ if options[:guest_customization][:ip_address]
447
+ unless ip?(options[:guest_customization][:ip_address])
448
+ raise Support::CloneError.new("Guest customization error: ip_address is required to be formatted as an IPv4 address")
449
+ end
446
450
 
447
- unless ip?(options[:guest_customization][:subnet_mask])
448
- raise Support::CloneError.new("Guest customization error: subnet_mask is required to be formatted as an IPv4 address")
451
+ unless options[:guest_customization][:subnet_mask]
452
+ raise Support::CloneError.new("Guest customization error: subnet_mask is required if assigning a fixed IPv4 address")
453
+ end
454
+
455
+ unless ip?(options[:guest_customization][:subnet_mask])
456
+ raise Support::CloneError.new("Guest customization error: subnet_mask is required to be formatted as an IPv4 address")
457
+ end
449
458
  end
450
459
 
451
- options[:guest_customization][:gateway].each do |v|
452
- unless ip?(v)
453
- raise Support::CloneError.new("Guest customization error: gateway is required to be formatted as an IPv4 address")
460
+ if options[:guest_customization][:gateway]
461
+ unless options[:guest_customization][:gateway].is_a?(Array)
462
+ raise Support::CloneError.new("Guest customization error: gateway must be an array")
454
463
  end
464
+
465
+ options[:guest_customization][:gateway].each do |v|
466
+ unless ip?(v)
467
+ raise Support::CloneError.new("Guest customization error: gateway is required to be formatted as an IPv4 address")
468
+ end
469
+ end
470
+ end
471
+
472
+ required = %i{dns_domain timezone dns_server_list dns_suffix_list}
473
+ missing = required - options[:guest_customization].keys
474
+ unless missing.empty?
475
+ raise Support::CloneError.new("Guest customization error: #{missing.join(", ")} are required to support guest customization")
455
476
  end
456
477
 
457
478
  options[:guest_customization][:dns_server_list].each do |v|
@@ -460,19 +481,27 @@ class Support
460
481
  end
461
482
  end
462
483
 
463
- unless %i{dns_domain timezone dns_server_list dns_suffix_list ip_address gateway subnet_mask}.all? { |k| options[:guest_customization].key? k }
464
- raise Support::CloneError.new("Guest customization error: currently all options are required to support guest customization")
465
- end
466
-
467
484
  if !options[:guest_customization][:dns_server_list].is_a?(Array)
468
485
  raise Support::CloneError.new("Guest customization error: dns_server_list must be an array")
469
486
  elsif !options[:guest_customization][:dns_suffix_list].is_a?(Array)
470
487
  raise Support::CloneError.new("Guest customization error: dns_suffix_list must be an array")
471
- elsif !options[:guest_customization][:gateway].is_a?(Array)
472
- raise Support::CloneError.new("Guest customization error: gateway must be an array")
473
488
  end
474
489
 
475
- spec = RbVmomi::VIM::CustomizationSpec.new(
490
+ if options[:guest_customization][:ip_address]
491
+ customized_ip = RbVmomi::VIM::CustomizationIPSettings.new(
492
+ ip: RbVmomi::VIM::CustomizationFixedIp(ipAddress: options[:guest_customization][:ip_address]),
493
+ gateway: options[:guest_customization][:gateway],
494
+ subnetMask: options[:guest_customization][:subnet_mask],
495
+ dnsDomain: options[:guest_customization][:dns_domain]
496
+ )
497
+ else
498
+ customized_ip = RbVmomi::VIM::CustomizationIPSettings.new(
499
+ ip: RbVmomi::VIM::CustomizationDhcpIpGenerator.new,
500
+ dnsDomain: options[:guest_customization][:dns_domain]
501
+ )
502
+ end
503
+
504
+ RbVmomi::VIM::CustomizationSpec.new(
476
505
  identity: RbVmomi::VIM::CustomizationLinuxPrep.new(
477
506
  domain: options[:guest_customization][:dns_domain],
478
507
  hostName: RbVmomi::VIM::CustomizationFixedName.new(
@@ -486,18 +515,9 @@ class Support
486
515
  dnsSuffixList: options[:guest_customization][:dns_suffix_list]
487
516
  ),
488
517
  nicSettingMap: [RbVmomi::VIM::CustomizationAdapterMapping.new(
489
- adapter: RbVmomi::VIM::CustomizationIPSettings.new(
490
- ip: RbVmomi::VIM::CustomizationFixedIp(
491
- ipAddress: options[:guest_customization][:ip_address]
492
- ),
493
- gateway: options[:guest_customization][:gateway],
494
- subnetMask: options[:guest_customization][:subnet_mask],
495
- dnsDomain: options[:guest_customization][:dns_domain]
496
- )
518
+ adapter: customized_ip
497
519
  )]
498
520
  )
499
-
500
- spec
501
521
  end
502
522
 
503
523
  def clone
@@ -1,5 +1,5 @@
1
1
  require "rbvmomi"
2
- require "net/http"
2
+ require "net/http" unless defined?(Net::HTTP)
3
3
 
4
4
  class Support
5
5
  # Encapsulate VMware Tools GOM interaction, inspired by github:dnuffer/raidopt
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.7.8
4
+ version: 2.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-31 00:00:00.000000000 Z
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbvmomi