kitchen-vcenter 2.7.0 → 2.7.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da86b6422044114b6f2b89cc85b8dc527fa5b743f2ff733e604c4730773e6fae
4
- data.tar.gz: dab5b088008e3344b2d52fca17d97a4fffaf25a4dbf486b4ac7139d82bedbf00
3
+ metadata.gz: 336491e73efecaf915ea3d66abee8ec788a918b5f4f9a6b89a9a186622f1fbc4
4
+ data.tar.gz: 1c90b4a62e44c40837955a48afde23509c0afccbae563430fc6bfdc3ff7caae0
5
5
  SHA512:
6
- metadata.gz: 7fe27912e489acea7d4d126ca4ff6db750d24dbb56024ff387816db7b2948522da203a1d01cb728a7f16b10b0e44fb0bd27bfefa54a93849328fde67fe939d07
7
- data.tar.gz: daadea97931ae326c43ab040ccd3cd5ebea0d724f76a8c9e3cc86b5e16c2f47b519fb7e66859f3db106b5366f05fd20d6ee5e373ef29d5098756d58845a9d1ee
6
+ metadata.gz: bff63dd4a20821ce5ec1f8a2032ceae2962b4d26345810c23ebf44dc5548afc85b642342f617f54d8be79b8075b815f65c20df48070b718897216102cdeab2fc
7
+ data.tar.gz: 8384025e3a26ea8a33122f770aecb961a608f96deab7e349d4501676b1ce8628fc4035b65f0428be363fb31d845c677644729f95382de9d017be03d2e15650f6
@@ -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.0"
23
+ VERSION = "2.7.6"
24
24
  end
@@ -51,6 +51,7 @@ module Kitchen
51
51
  default_config :vm_wait_interval, 2.0
52
52
  default_config :vm_rollback, false
53
53
  default_config :customize, nil
54
+ default_config :guest_customization, nil
54
55
  default_config :interface, nil
55
56
  default_config :active_discovery, false
56
57
  default_config :active_discovery_command, nil
@@ -116,10 +117,13 @@ module Kitchen
116
117
  end
117
118
 
118
119
  # Check that the datacenter exists
119
- datacenter_exists?(config[:datacenter])
120
+ dc_folder = File.dirname(config[:datacenter])
121
+ dc_folder = nil if dc_folder == "."
122
+ dc_name = File.basename(config[:datacenter])
123
+ datacenter_exists?(dc_folder, dc_name)
120
124
 
121
125
  # Get datacenter and cluster information
122
- datacenter = get_datacenter(config[:datacenter])
126
+ datacenter = get_datacenter(dc_folder, dc_name)
123
127
  cluster_id = get_cluster_id(config[:cluster])
124
128
 
125
129
  # Using the clone class, create a machine for TK
@@ -156,6 +160,7 @@ module Kitchen
156
160
  wait_timeout: config[:vm_wait_timeout],
157
161
  wait_interval: config[:vm_wait_interval],
158
162
  customize: config[:customize],
163
+ guest_customization: config[:guest_customization],
159
164
  active_discovery: config[:active_discovery],
160
165
  active_discovery_command: config[:active_discovery_command],
161
166
  vm_os: config[:vm_os],
@@ -288,10 +293,13 @@ module Kitchen
288
293
 
289
294
  # Sees in the datacenter exists or not
290
295
  #
296
+ # @param [folder] folder is the name of the folder in which the Datacenter is stored in inventory, possibly nil
291
297
  # @param [name] name is the name of the datacenter
292
- def datacenter_exists?(name)
298
+ def datacenter_exists?(folder, name)
293
299
  dc_api = VSphereAutomation::VCenter::DatacenterApi.new(api_client)
294
- dcs = dc_api.list({ filter_names: name }).value
300
+ opts = { filter_names: name }
301
+ opts[:filter_folders] = get_folder(folder, "DATACENTER") if folder
302
+ dcs = dc_api.list(opts).value
295
303
 
296
304
  raise format("Unable to find data center: %s", name) if dcs.empty?
297
305
  end
@@ -326,9 +334,10 @@ module Kitchen
326
334
  # Gets the folder you want to create the VM
327
335
  #
328
336
  # @param [name] name is the name of the folder
329
- def get_folder(name)
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")
330
339
  folder_api = VSphereAutomation::VCenter::FolderApi.new(api_client)
331
- folders = folder_api.list({ filter_names: name, filter_type: "VIRTUAL_MACHINE" }).value
340
+ folders = folder_api.list({ filter_names: name, filter_type: type }).value
332
341
 
333
342
  raise format("Unable to find folder: %s", name) if folders.empty?
334
343
 
@@ -349,10 +358,13 @@ module Kitchen
349
358
 
350
359
  # Gets the info of the datacenter
351
360
  #
361
+ # @param [folder] folder is the name of the folder in which the Datacenter is stored in inventory, possibly nil
352
362
  # @param [name] name is the name of the Datacenter
353
- def get_datacenter(name)
363
+ def get_datacenter(folder, name)
354
364
  dc_api = VSphereAutomation::VCenter::DatacenterApi.new(api_client)
355
- dcs = dc_api.list({ filter_names: name }).value
365
+ opts = { filter_names: name }
366
+ opts[:filter_folders] = get_folder(folder, "DATACENTER") if folder
367
+ dcs = dc_api.list(opts).value
356
368
 
357
369
  raise format("Unable to find data center: %s", name) if dcs.empty?
358
370
 
@@ -221,13 +221,13 @@ class Support
221
221
  case options[:vm_os].downcase.to_sym
222
222
  when :linux
223
223
  # @todo: allow override if no dhclient
224
- return [
224
+ [
225
225
  "/sbin/modprobe -r vmxnet3",
226
226
  "/sbin/modprobe vmxnet3",
227
227
  "/sbin/dhclient",
228
228
  ]
229
229
  when :windows
230
- return [
230
+ [
231
231
  "netsh interface set Interface #{options[:vm_win_network]} disable",
232
232
  "netsh interface set Interface #{options[:vm_win_network]} enable",
233
233
  "ipconfig /renew",
@@ -428,12 +428,87 @@ class Support
428
428
  root_folder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == datacenter }
429
429
  end
430
430
 
431
+ def ip?(string)
432
+ IPAddr.new(string)
433
+ true
434
+ rescue IPAddr::InvalidAddressError
435
+ false
436
+ end
437
+
438
+ def customization_spec
439
+ unless options[:guest_customization]
440
+ return false
441
+ end
442
+
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
+
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")
449
+ end
450
+
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")
454
+ end
455
+ end
456
+
457
+ options[:guest_customization][:dns_server_list].each do |v|
458
+ unless ip?(v)
459
+ raise Support::CloneError.new("Guest customization error: dns_server_list is required to be formatted as an IPv4 address")
460
+ end
461
+ end
462
+
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
+ if !options[:guest_customization][:dns_server_list].is_a?(Array)
468
+ raise Support::CloneError.new("Guest customization error: dns_server_list must be an array")
469
+ elsif !options[:guest_customization][:dns_suffix_list].is_a?(Array)
470
+ 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
+ end
474
+
475
+ spec = RbVmomi::VIM::CustomizationSpec.new(
476
+ identity: RbVmomi::VIM::CustomizationLinuxPrep.new(
477
+ domain: options[:guest_customization][:dns_domain],
478
+ hostName: RbVmomi::VIM::CustomizationFixedName.new(
479
+ name: name
480
+ ),
481
+ hwClockUTC: true,
482
+ timeZone: options[:guest_customization][:timezone]
483
+ ),
484
+ globalIPSettings: RbVmomi::VIM::CustomizationGlobalIPSettings.new(
485
+ dnsServerList: options[:guest_customization][:dns_server_list],
486
+ dnsSuffixList: options[:guest_customization][:dns_suffix_list]
487
+ ),
488
+ 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
+ )
497
+ )]
498
+ )
499
+
500
+ spec
501
+ end
502
+
431
503
  def clone
432
504
  benchmark_start if benchmark?
433
505
 
434
506
  # set the datacenter name
435
507
  dc = find_datacenter
436
508
 
509
+ # get guest customization spec
510
+ guest_customization = customization_spec
511
+
437
512
  # reference template using full inventory path
438
513
  inventory_path = format("/%s/vm/%s", datacenter, options[:template])
439
514
  src_vm = root_folder.findByInventoryPath(inventory_path)
@@ -552,9 +627,15 @@ class Support
552
627
  benchmark_checkpoint("initialized") if benchmark?
553
628
  task = src_vm.InstantClone_Task(spec: clone_spec)
554
629
  else
555
- clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocate_spec,
556
- powerOn: options[:poweron] && options[:customize].nil?,
557
- template: false)
630
+ clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(
631
+ location: relocate_spec,
632
+ powerOn: options[:poweron] && options[:customize].nil?,
633
+ template: false
634
+ )
635
+
636
+ if guest_customization
637
+ clone_spec.customization = guest_customization
638
+ end
558
639
 
559
640
  benchmark_checkpoint("initialized") if benchmark?
560
641
  task = src_vm.CloneVM_Task(spec: clone_spec, folder: dest_folder, name: name)
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.0
4
+ version: 2.7.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-04-14 00:00:00.000000000 Z
11
+ date: 2020-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbvmomi
@@ -64,34 +64,6 @@ dependencies:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0.4'
67
- - !ruby/object:Gem::Dependency
68
- name: bundler
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: '0'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: '0'
81
- - !ruby/object:Gem::Dependency
82
- name: rake
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
67
  description: Test Kitchen driver for VMware vCenter using SDK
96
68
  email:
97
69
  - oss@chef.io
@@ -116,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
88
  requirements:
117
89
  - - ">="
118
90
  - !ruby/object:Gem::Version
119
- version: '2.3'
91
+ version: '2.4'
120
92
  required_rubygems_version: !ruby/object:Gem::Requirement
121
93
  requirements:
122
94
  - - ">="