chef-provisioning-vsphere 0.5.0 → 0.5.1

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
  SHA1:
3
- metadata.gz: 990036a8b6dcc42e111ed4acb92aa90c5fe59f1d
4
- data.tar.gz: 2767a8e7fd769b90954e57b06eecccfa0fd29736
3
+ metadata.gz: 9beead24ca50feddc1b634a8d2f8a5c43936c7c2
4
+ data.tar.gz: 41c0ef964853c87cee814f127cc446b4ac383bd6
5
5
  SHA512:
6
- metadata.gz: 0784aeb6843b433d16f5aa93aee499e55ed0aad8b2dd6b8c6378258d9c504ac78fcac3d6cf7e4abdda19e580b6c58ce8a58853db7d2342ab38a943f51e91329c
7
- data.tar.gz: e68182faff627baf71b3b0074cc14fac995908123f0bcdef2e263b70cd147496a40fb299b7d9797fd31da826f37176bc7ab9781bd6fb8a2b045a913b6742f0b2
6
+ metadata.gz: adc8fd6c36acc6cbcdada4c027290049ebc623334f1eeeb7f92a2fc4b6615b9f1f25f8880ab97559d9ad2da09c9b4ef73c34758c12f25d90f14d7689f700912d
7
+ data.tar.gz: dc0a7bfae64f5d89262b77d187304b81c709818e83e74d8d178c1fe5ab7b23d7233cf81dab9cc3457da9e364292b7e53eafbc48c5d88219466f40f064b4550cf
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Rally Software Development Corp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ Contribution Notice
2
+
3
+ By contributing to this Project, You grant to CenturyLink and to recipients of software distributed by CenturyLink, a perpetual worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute your contributions to this Project (“Your Contributions”), including derivative works thereof.
4
+
5
+ You grant to CenturyLink and to recipients of software distributed by CenturyLink a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section), patent license to make, have made, use, offer to sell, sell, import and otherwise transfer Your Contributions, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contributions(s) alone or by combination of Your Contribution(s) with this Project. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that Your Contribution, or this Project, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this agreement for Your Contribution or this Project shall terminate as of the date such litigation is filed.
6
+
7
+ You represent that each of Your Contributions is Your original creation and represent that You are legally entitled to grant the above license and that no other third party permission is required. If your employer(s) has rights to intellectual property that is included in Your Contributions, You represent that You have received permission to make such contributions on behalf of that employer.
@@ -155,7 +155,6 @@ module ChefProvisioningVsphere
155
155
 
156
156
  def find_or_create_vm(bootstrap_options, machine_spec, action_handler)
157
157
  vm = find_vm(
158
- bootstrap_options[:datacenter],
159
158
  bootstrap_options[:vm_folder],
160
159
  machine_spec.name
161
160
  )
@@ -167,7 +166,11 @@ module ChefProvisioningVsphere
167
166
  'already created'
168
167
  )
169
168
  else
170
- vm = clone_vm(action_handler, bootstrap_options, machine_spec.name)
169
+ vm = clone_vm(
170
+ action_handler,
171
+ bootstrap_options,
172
+ machine_spec.name
173
+ )
171
174
  end
172
175
  vm
173
176
  end
@@ -185,8 +188,7 @@ module ChefProvisioningVsphere
185
188
  end
186
189
 
187
190
  def ready_machine(action_handler, machine_spec, machine_options)
188
- start_machine(action_handler, machine_spec, machine_options)
189
- vm = vm_for(machine_spec)
191
+ vm = start_machine(action_handler, machine_spec, machine_options)
190
192
  if vm.nil?
191
193
  raise "Machine #{machine_spec.name} does not have a server "\
192
194
  'associated with it, or server does not exist.'
@@ -385,6 +387,7 @@ module ChefProvisioningVsphere
385
387
  start_vm(vm, machine_options[:bootstrap_options][:ssh][:port])
386
388
  end
387
389
  end
390
+ vm
388
391
  end
389
392
 
390
393
  def restart_server(action_handler, machine_spec, vm)
@@ -467,16 +470,13 @@ module ChefProvisioningVsphere
467
470
  end
468
471
 
469
472
  def clone_vm(action_handler, bootstrap_options, machine_name)
470
- datacenter = bootstrap_options[:datacenter]
471
-
472
- vm = find_vm(datacenter, bootstrap_options[:vm_folder], machine_name)
473
+ vm = find_vm(bootstrap_options[:vm_folder], machine_name)
473
474
  return vm if vm
474
475
 
475
476
  vm_template = vm_template_for(bootstrap_options)
476
477
 
477
478
  do_vm_clone(
478
479
  action_handler,
479
- datacenter,
480
480
  vm_template,
481
481
  machine_name,
482
482
  bootstrap_options
@@ -484,10 +484,10 @@ module ChefProvisioningVsphere
484
484
  end
485
485
 
486
486
  def vm_template_for(bootstrap_options)
487
- datacenter = bootstrap_options[:datacenter]
488
487
  template_folder = bootstrap_options[:template_folder]
489
488
  template_name = bootstrap_options[:template_name]
490
- find_vm(datacenter, template_folder, template_name) or raise("vSphere VM Template not found [#{template_folder}/#{template_name}]")
489
+ find_vm(template_folder, template_name) ||
490
+ raise("vSphere VM Template not found [#{template_folder}/#{template_name}]")
491
491
  end
492
492
 
493
493
  def machine_for(machine_spec, machine_options)
@@ -1,3 +1,3 @@
1
1
  module ChefProvisioningVsphere
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -26,13 +26,18 @@ module ChefProvisioningVsphere
26
26
  @current_connection
27
27
  end
28
28
 
29
- def find_vm(dc_name, vm_folder, vm_name)
30
- folder = find_folder(dc_name, vm_folder) or raise("vSphere Folder not found [#{vm_folder}] for vm #{vm_name}")
29
+ def find_vm(vm_folder, vm_name)
30
+ folder = find_folder(vm_folder) ||
31
+ raise("vSphere Folder not found [#{vm_folder}] for vm #{vm_name}")
31
32
  vm = folder.find(vm_name, RbVmomi::VIM::VirtualMachine)
32
33
  end
33
34
 
34
35
  def find_vm_by_id(uuid, connection = vim)
35
- vm = connection.searchIndex.FindByUuid({:uuid => uuid, :vmSearch => true, :instanceUuid => true})
36
+ vm = connection.searchIndex.FindByUuid(
37
+ uuid: uuid,
38
+ vmSearch: true,
39
+ instanceUuid: true
40
+ )
36
41
  end
37
42
 
38
43
  def vm_started?(vm, wait_on_port = 22)
@@ -92,21 +97,23 @@ module ChefProvisioningVsphere
92
97
  end
93
98
 
94
99
  #folder could be like: /Level1/Level2/folder_name
95
- def find_folder(dc_name, folder_name)
96
- baseEntity = dc(dc_name).vmFolder
100
+ def find_folder(folder_name)
101
+ base = datacenter.vmFolder
97
102
  if folder_name && folder_name.length > 0
98
- entityArray = folder_name.split('/')
99
- entityArray.each do |entityArrItem|
100
- if entityArrItem != ''
101
- baseEntity = baseEntity.childEntity.grep(RbVmomi::VIM::Folder).find { |f| f.name == entityArrItem }
103
+ entityArray = folder_name.split('/').reject(&:empty?)
104
+ entityArray.each do |item|
105
+ base = base.childEntity.grep(RbVmomi::VIM::Folder).find do |f|
106
+ f.name == item
102
107
  end
103
108
  end
104
109
  end
105
- baseEntity
110
+ base
106
111
  end
107
112
 
108
- def dc(dc_name)
109
- vim.serviceInstance.find_datacenter(dc_name) or raise("vSphere Datacenter not found [#{dc_name}]")
113
+ def datacenter
114
+ dc_name = config[:machine_options][:bootstrap_options][:datacenter]
115
+ @datacenter ||= vim.serviceInstance.find_datacenter(dc_name) ||
116
+ raise("vSphere Datacenter not found [#{dc_name}]")
110
117
  end
111
118
 
112
119
  def network_adapter_for(operation, network_name, network_label, device_key, backing_info)
@@ -116,7 +123,7 @@ module ChefProvisioningVsphere
116
123
  :startConnected => true)
117
124
  device = RbVmomi::VIM::VirtualVmxnet3(
118
125
  :backing => backing_info,
119
- :deviceInfo => RbVmomi::VIM::Description(:label => network_label, :summary => network_name),
126
+ :deviceInfo => RbVmomi::VIM::Description(:label => network_label, :summary => network_name.split('/').last),
120
127
  :key => device_key,
121
128
  :connectable => connectable)
122
129
  RbVmomi::VIM::VirtualDeviceConfigSpec(
@@ -128,11 +135,11 @@ module ChefProvisioningVsphere
128
135
  vm.config.hardware.device.select {|d| d.is_a?(RbVmomi::VIM::VirtualEthernetCard)}
129
136
  end
130
137
 
131
- def do_vm_clone(action_handler, dc_name, vm_template, vm_name, options)
138
+ def do_vm_clone(action_handler, vm_template, vm_name, options)
132
139
  deviceAdditions = []
133
140
 
134
141
  clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(
135
- location: relocate_spec_for(dc_name, vm_template, options),
142
+ location: relocate_spec_for(vm_template, options),
136
143
  powerOn: false,
137
144
  template: false,
138
145
  config: RbVmomi::VIM.VirtualMachineConfigSpec(
@@ -163,11 +170,11 @@ module ChefProvisioningVsphere
163
170
 
164
171
  vm_template.CloneVM_Task(
165
172
  name: vm_name,
166
- folder: find_folder(dc_name, options[:vm_folder]),
173
+ folder: find_folder(options[:vm_folder]),
167
174
  spec: clone_spec
168
175
  ).wait_for_completion
169
176
 
170
- vm = find_vm(dc_name, options[:vm_folder], vm_name)
177
+ vm = find_vm(options[:vm_folder], vm_name)
171
178
 
172
179
  if options[:additional_disk_size_gb].to_i > 0
173
180
  task = vm.ReconfigVM_Task(:spec => RbVmomi::VIM.VirtualMachineConfigSpec(:deviceChange => [virtual_disk_for(vm, options)]))
@@ -201,13 +208,12 @@ module ChefProvisioningVsphere
201
208
  end
202
209
  end
203
210
 
204
- def relocate_spec_for(dc_name, vm_template, options)
205
- datacenter = dc(dc_name)
211
+ def relocate_spec_for(vm_template, options)
206
212
  if options.has_key?(:host)
207
- host = find_host(datacenter, options[:host])
213
+ host = find_host(options[:host])
208
214
  rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(host: host)
209
215
  else
210
- pool = options[:resource_pool] ? find_pool(datacenter, options[:resource_pool]) : vm_template.resourcePool
216
+ pool = options[:resource_pool] ? find_pool(options[:resource_pool]) : vm_template.resourcePool
211
217
  rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(pool: pool)
212
218
  raise 'either :host or :resource_pool must be specified when cloning from a VM Template' if pool.nil?
213
219
  end
@@ -218,55 +224,55 @@ module ChefProvisioningVsphere
218
224
  end
219
225
 
220
226
  unless options[:datastore].to_s.empty?
221
- rspec.datastore = find_datastore(datacenter, options[:datastore])
227
+ rspec.datastore = find_datastore(options[:datastore])
222
228
  end
223
229
 
224
230
  rspec
225
231
  end
226
232
 
227
233
  def create_delta_disk(vm_template)
228
- disks = vm_template.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
229
- disks.select { |disk| disk.backing.parent == nil }.each do |disk|
230
- spec = {
231
- :deviceChange => [
232
- {
233
- :operation => :remove,
234
- :device => disk
235
- },
236
- {
237
- :operation => :add,
238
- :fileOperation => :create,
239
- :device => disk.dup.tap { |new_disk|
240
- new_disk.backing = new_disk.backing.dup
241
- new_disk.backing.fileName = "[#{disk.backing.datastore.name}]"
242
- new_disk.backing.parent = disk.backing
243
- },
244
- }
245
- ]
246
- }
247
- vm_template.ReconfigVM_Task(:spec => spec).wait_for_completion
248
- end
234
+ disks = vm_template.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
235
+ disks.select { |disk| disk.backing.parent == nil }.each do |disk|
236
+ spec = {
237
+ :deviceChange => [
238
+ {
239
+ :operation => :remove,
240
+ :device => disk
241
+ },
242
+ {
243
+ :operation => :add,
244
+ :fileOperation => :create,
245
+ :device => disk.dup.tap { |new_disk|
246
+ new_disk.backing = new_disk.backing.dup
247
+ new_disk.backing.fileName = "[#{disk.backing.datastore.name}]"
248
+ new_disk.backing.parent = disk.backing
249
+ },
250
+ }
251
+ ]
252
+ }
253
+ vm_template.ReconfigVM_Task(:spec => spec).wait_for_completion
254
+ end
249
255
  end
250
256
 
251
257
  def virtual_disk_for(vm, options)
252
258
  if options[:datastore].to_s.empty?
253
- raise ":datastore must be specified when adding a disk to a cloned vm"
259
+ raise ':datastore must be specified when adding a disk to a cloned vm'
254
260
  end
255
261
  idx = vm.disks.count
256
262
  RbVmomi::VIM::VirtualDeviceConfigSpec(
257
- :operation => :add,
258
- :fileOperation => :create,
259
- :device => RbVmomi::VIM.VirtualDisk(
260
- :key => idx,
261
- :backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
262
- :fileName => "[#{options[:datastore]}]",
263
- :diskMode => 'persistent',
264
- :thinProvisioned => true
265
- ),
266
- :capacityInKB => options[:additional_disk_size_gb] * 1024 * 1024,
267
- :controllerKey => 1000,
268
- :unitNumber => idx
269
- )
263
+ :operation => :add,
264
+ :fileOperation => :create,
265
+ :device => RbVmomi::VIM.VirtualDisk(
266
+ :key => idx,
267
+ :backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
268
+ :fileName => "[#{options[:datastore]}]",
269
+ :diskMode => 'persistent',
270
+ :thinProvisioned => true
271
+ ),
272
+ :capacityInKB => options[:additional_disk_size_gb] * 1024 * 1024,
273
+ :controllerKey => 1000,
274
+ :unitNumber => idx
275
+ )
270
276
  )
271
277
  end
272
278
 
@@ -283,7 +289,7 @@ module ChefProvisioningVsphere
283
289
  key = 4000
284
290
  networks.each_index do | i |
285
291
  label = "Ethernet #{i+1}"
286
- backing_info = backing_info_for(action_handler, dc(options[:datacenter]), networks[i])
292
+ backing_info = backing_info_for(action_handler, networks[i])
287
293
  if card = cards.shift
288
294
  key = card.key
289
295
  operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('edit')
@@ -301,73 +307,76 @@ module ChefProvisioningVsphere
301
307
  [additions, changes]
302
308
  end
303
309
 
304
- def backing_info_for(action_handler, datacenter, network_name)
305
- networks = datacenter.network.select {|net| net.name == network_name}
306
- if networks.count > 0
307
- dpg = networks.select { |net| net.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) }
308
- networks = dpg unless dpg.empty?
309
- end
310
- action_handler.report_progress "network: #{network_name} is a #{networks[0].class}}"
311
- if networks[0].is_a?(RbVmomi::VIM::DistributedVirtualPortgroup)
310
+ def backing_info_for(action_handler, network_name)
311
+ network = find_network(network_name)
312
+ action_handler.report_progress(
313
+ "network: #{network_name} is a #{network.class}")
314
+ if network.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup)
312
315
  port = RbVmomi::VIM::DistributedVirtualSwitchPortConnection(
313
- :switchUuid => networks[0].config.distributedVirtualSwitch.uuid,
314
- :portgroupKey => networks[0].key
316
+ :switchUuid => network.config.distributedVirtualSwitch.uuid,
317
+ :portgroupKey => network.key
315
318
  )
316
- RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo(:port => port)
319
+ RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo(
320
+ :port => port)
317
321
  else
318
- RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(:deviceName => network_name)
322
+ RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(
323
+ deviceName: network_name.split('/').last)
319
324
  end
320
325
  end
321
326
 
322
- def find_datastore(dc, datastore_name)
323
- baseEntity = dc.datastore
324
- baseEntity.find { |f| f.info.name == datastore_name } or raise "no such datastore #{datastore_name}"
327
+ def find_datastore(datastore_name)
328
+ datacenter.datastore.find { |f| f.info.name == datastore_name } or raise "no such datastore #{datastore_name}"
325
329
  end
326
330
 
327
331
  def customization_options_from(action_handler, vm_template, vm_name, options)
328
332
  if options.has_key?(:customization_spec)
329
333
  if(options[:customization_spec].is_a?(Hash))
330
- cust_options = options[:customization_spec]
331
- raise ArgumentError, "domain is required" unless cust_options.key?(:domain)
332
- cust_ip_settings = nil
333
- if cust_options.key?(:ipsettings) and cust_options[:ipsettings].key?(:ip)
334
- raise ArgumentError, "ip and subnetMask is required for static ip" unless cust_options[:ipsettings].key?(:ip) and
335
- cust_options[:ipsettings].key?(:subnetMask)
336
- cust_ip_settings = RbVmomi::VIM::CustomizationIPSettings.new(cust_options[:ipsettings])
337
- action_handler.report_progress "customizing #{vm_name} with static IP #{cust_options[:ipsettings][:ip]}"
338
- cust_ip_settings.ip = RbVmomi::VIM::CustomizationFixedIp(:ipAddress => cust_options[:ipsettings][:ip])
339
- end
340
- cust_domain = cust_options[:domain]
341
- if cust_ip_settings.nil?
342
- cust_ip_settings= RbVmomi::VIM::CustomizationIPSettings.new(:ip => RbVmomi::VIM::CustomizationDhcpIpGenerator.new())
343
- cust_ip_settings.dnsServerList = cust_options[:ipsettings][:dnsServerList]
344
- action_handler.report_progress "customizing #{vm_name} with dynamic IP and DNS: #{cust_options[:ipsettings][:dnsServerList]}"
334
+ cust_options = options[:customization_spec]
335
+ ip_settings = cust_options[:ipsettings]
336
+ cust_domain = cust_options[:domain]
337
+
338
+ raise ArgumentError, 'domain is required' unless cust_domain
339
+ cust_ip_settings = nil
340
+ if ip_settings && ip_settings.key?(:ip)
341
+ unless cust_options[:ipsettings].key?(:subnetMask)
342
+ raise ArgumentError, 'subnetMask is required for static ip'
345
343
  end
344
+ cust_ip_settings = RbVmomi::VIM::CustomizationIPSettings.new(ip_settings)
345
+ action_handler.report_progress "customizing #{vm_name} with static IP #{ip_settings[:ip]}"
346
+ cust_ip_settings.ip = RbVmomi::VIM::CustomizationFixedIp(:ipAddress => ip_settings[:ip])
347
+ end
348
+ if cust_ip_settings.nil?
349
+ cust_ip_settings= RbVmomi::VIM::CustomizationIPSettings.new(:ip => RbVmomi::VIM::CustomizationDhcpIpGenerator.new())
350
+ cust_ip_settings.dnsServerList = ip_settings[:dnsServerList]
351
+ action_handler.report_progress "customizing #{vm_name} with dynamic IP and DNS: #{ip_settings[:dnsServerList]}"
352
+ end
346
353
 
347
- cust_ip_settings.dnsDomain = cust_domain
348
- cust_global_ip_settings = RbVmomi::VIM::CustomizationGlobalIPSettings.new
349
- cust_global_ip_settings.dnsServerList = cust_ip_settings.dnsServerList
350
- cust_global_ip_settings.dnsSuffixList = [cust_domain]
351
- cust_hostname = hostname_from(options[:customization_spec], vm_name)
352
- cust_hwclockutc = cust_options[:hw_clock_utc]
353
- cust_timezone = cust_options[:time_zone]
354
-
355
- if vm_template.config.guestId.start_with?('win')
356
- cust_prep = windows_prep_for(action_handler, options, vm_name)
357
- else
358
- cust_prep = RbVmomi::VIM::CustomizationLinuxPrep.new(
359
- :domain => cust_domain,
360
- :hostName => cust_hostname,
361
- :hwClockUTC => cust_hwclockutc,
362
- :timeZone => cust_timezone)
363
- end
364
- cust_adapter_mapping = [RbVmomi::VIM::CustomizationAdapterMapping.new(:adapter => cust_ip_settings)]
365
- RbVmomi::VIM::CustomizationSpec.new(
366
- :identity => cust_prep,
367
- :globalIPSettings => cust_global_ip_settings,
368
- :nicSettingMap => cust_adapter_mapping)
354
+ cust_ip_settings.dnsDomain = cust_domain
355
+ cust_global_ip_settings = RbVmomi::VIM::CustomizationGlobalIPSettings.new
356
+ cust_global_ip_settings.dnsServerList = cust_ip_settings.dnsServerList
357
+ cust_global_ip_settings.dnsSuffixList = [cust_domain]
358
+ cust_hostname = hostname_from(cust_options, vm_name)
359
+ cust_hwclockutc = cust_options[:hw_clock_utc]
360
+ cust_timezone = cust_options[:time_zone]
361
+
362
+ if vm_template.config.guestId.start_with?('win')
363
+ cust_prep = windows_prep_for(action_handler, options, vm_name)
364
+ else
365
+ cust_prep = RbVmomi::VIM::CustomizationLinuxPrep.new(
366
+ :domain => cust_domain,
367
+ :hostName => cust_hostname,
368
+ :hwClockUTC => cust_hwclockutc,
369
+ :timeZone => cust_timezone
370
+ )
371
+ end
372
+ cust_adapter_mapping = [RbVmomi::VIM::CustomizationAdapterMapping.new(:adapter => cust_ip_settings)]
373
+ RbVmomi::VIM::CustomizationSpec.new(
374
+ :identity => cust_prep,
375
+ :globalIPSettings => cust_global_ip_settings,
376
+ :nicSettingMap => cust_adapter_mapping
377
+ )
369
378
  else
370
- find_customization_spec(options[:customization_spec])
379
+ find_customization_spec(cust_options)
371
380
  end
372
381
  end
373
382
  end
@@ -423,50 +432,74 @@ module ChefProvisioningVsphere
423
432
  end
424
433
  end
425
434
 
426
- def find_host(dc, host_name)
427
- baseEntity = dc.hostFolder
428
- entityArray = host_name.split('/')
429
- entityArray.each do |entityArrItem|
430
- if entityArrItem != ''
431
- if baseEntity.is_a? RbVmomi::VIM::Folder
432
- baseEntity = baseEntity.childEntity.find { |f| f.name == entityArrItem } or nil
433
- elsif baseEntity.is_a? RbVmomi::VIM::ClusterComputeResource or baseEntity.is_a? RbVmomi::VIM::ComputeResource
434
- baseEntity = baseEntity.host.find { |f| f.name == entityArrItem } or nil
435
- elsif baseEntity.is_a? RbVmomi::VIM::HostSystem
436
- baseEntity = baseEntity.host.find { |f| f.name == entityArrItem } or nil
437
- else
438
- baseEntity = nil
439
- end
435
+ def find_entity(name, parent_folder, &block)
436
+ parts = name.split('/').reject(&:empty?)
437
+ parts.each do |item|
438
+ if parent_folder.is_a? RbVmomi::VIM::Folder
439
+ parent_folder = parent_folder.childEntity.find { |f| f.name == item }
440
+ else
441
+ parent_folder = block.call(parent_folder, item)
442
+ end
443
+ end
444
+ parent_folder
445
+ end
446
+
447
+ def find_host(host_name)
448
+ host = find_entity(host_name, datacenter.hostFolder) do |parent, part|
449
+ case parent
450
+ when RbVmomi::VIM::ClusterComputeResource || RbVmomi::VIM::ComputeResource
451
+ parent.host.find { |f| f.name == part }
452
+ when RbVmomi::VIM::HostSystem
453
+ parent.host.find { |f| f.name == part }
454
+ else
455
+ nil
440
456
  end
441
457
  end
442
458
 
443
- raise "vSphere Host not found [#{host_name}]" if baseEntity.nil?
459
+ raise "vSphere Host not found [#{host_name}]" if host.nil?
444
460
 
445
- baseEntity = baseEntity.host if not baseEntity.is_a?(RbVmomi::VIM::HostSystem) and baseEntity.respond_to?(:host)
446
- baseEntity
461
+ if !host.is_a?(RbVmomi::VIM::HostSystem) && host.respond_to?(:host)
462
+ host = host.host
463
+ end
464
+ host
447
465
  end
448
466
 
449
- def find_pool(dc, pool_name)
450
- baseEntity = dc.hostFolder
451
- entityArray = pool_name.split('/')
452
- entityArray.each do |entityArrItem|
453
- if entityArrItem != ''
454
- if baseEntity.is_a? RbVmomi::VIM::Folder
455
- baseEntity = baseEntity.childEntity.find { |f| f.name == entityArrItem } or nil
456
- elsif baseEntity.is_a? RbVmomi::VIM::ClusterComputeResource or baseEntity.is_a? RbVmomi::VIM::ComputeResource
457
- baseEntity = baseEntity.resourcePool.resourcePool.find { |f| f.name == entityArrItem } or nil
458
- elsif baseEntity.is_a? RbVmomi::VIM::ResourcePool
459
- baseEntity = baseEntity.resourcePool.find { |f| f.name == entityArrItem } or nil
460
- else
461
- baseEntity = nil
462
- end
467
+ def find_pool(pool_name)
468
+ pool = find_entity(pool_name, datacenter.hostFolder) do |parent, part|
469
+ case parent
470
+ when RbVmomi::VIM::ClusterComputeResource || RbVmomi::VIM::ComputeResource
471
+ parent.resourcePool.resourcePool.find { |f| f.name == part }
472
+ when RbVmomi::VIM::ResourcePool
473
+ parent.resourcePool.find { |f| f.name == part }
474
+ else
475
+ nil
476
+ end
477
+ end
478
+
479
+ raise "vSphere ResourcePool not found [#{pool_name}]" if pool.nil?
480
+
481
+ if !pool.is_a?(RbVmomi::VIM::ResourcePool) && pool.respond_to?(:resourcePool)
482
+ pool = pool.resourcePool
483
+ end
484
+ pool
485
+ end
486
+
487
+ def find_network(name)
488
+ base = datacenter.networkFolder
489
+ entity_array = name.split('/').reject(&:empty?)
490
+ entity_array.each do |item|
491
+ case base
492
+ when RbVmomi::VIM::Folder
493
+ base = base.childEntity.find { |f| f.name == item }
494
+ when RbVmomi::VIM::VmwareDistributedVirtualSwitch
495
+ idx = base.summary.portgroupName.find_index(item)
496
+ base = idx.nil? ? nil : base.portgroup[idx]
463
497
  end
464
498
  end
465
499
 
466
- raise "vSphere ResourcePool not found [#{pool_name}]" if baseEntity.nil?
500
+ raise "vSphere Network not found [#{name}]" if base.nil?
467
501
 
468
- baseEntity = baseEntity.resourcePool if not baseEntity.is_a?(RbVmomi::VIM::ResourcePool) and baseEntity.respond_to?(:resourcePool)
469
- baseEntity
502
+ base
470
503
  end
471
504
 
472
505
  def find_customization_spec(customization_spec)
@@ -86,30 +86,13 @@ describe ChefProvisioningVsphere::VsphereDriver do
86
86
  context "when no url is in the config" do
87
87
  let(:metal_config) do
88
88
  {
89
- :driver_options => {
90
- :user => 'vmapi',
91
- :password => '<password>',
92
- :host => '4.4.4.4',
93
- :port => 888,
94
- :path => '/yoda',
95
- :use_ssl => false,
96
- :insecure => true
97
- },
98
- :machine_options => {
99
- :ssh => {
100
- :password => '<password>',
101
- :paranoid => false
102
- },
103
- :bootstrap_options => {
104
- :datacenter => 'QA1',
105
- :template_name => 'UBUNTU-12-64-TEMPLATE',
106
- :vm_folder => 'DLAB',
107
- :num_cpus => 2,
108
- :memory_mb => 4096,
109
- :resource_pool => 'CLSTR02/DLAB'
110
- }
111
- },
112
- :log_level => :debug
89
+ :user => 'vmapi',
90
+ :password => '<password>',
91
+ :host => '4.4.4.4',
92
+ :port => 888,
93
+ :path => '/yoda',
94
+ :use_ssl => false,
95
+ :insecure => true
113
96
  }
114
97
  end
115
98
 
@@ -128,26 +111,9 @@ describe ChefProvisioningVsphere::VsphereDriver do
128
111
  context "when no url is in the config and config is missing defaulted values" do
129
112
  let(:metal_config) do
130
113
  {
131
- :driver_options => {
132
- :user => 'vmapi',
133
- :password => '<password>',
134
- :host => '4.4.4.4'
135
- },
136
- :machine_options => {
137
- :bootstrap_options => {
138
- :datacenter => 'QA1',
139
- :template_name => 'UBUNTU-12-64-TEMPLATE',
140
- :vm_folder => 'DLAB',
141
- :num_cpus => 2,
142
- :memory_mb => 4096,
143
- :resource_pool => 'CLSTR02/DLAB',
144
- :ssh => {
145
- :password => '<password>',
146
- :paranoid => false
147
- }
148
- }
149
- },
150
- :log_level => :debug
114
+ :user => 'vmapi',
115
+ :password => '<password>',
116
+ :host => '4.4.4.4'
151
117
  }
152
118
  end
153
119
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-16 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbvmomi
@@ -82,9 +82,11 @@ files:
82
82
  - ".gitignore"
83
83
  - Gemfile
84
84
  - LICENSE
85
+ - LICENSE-Rally
85
86
  - README.md
86
87
  - Rakefile
87
88
  - chef-provisioning-vsphere.gemspec
89
+ - contribution-notice
88
90
  - lib/chef/provisioning/driver_init/vsphere.rb
89
91
  - lib/chef/provisioning/vsphere_driver.rb
90
92
  - lib/chef/provisioning/vsphere_driver/driver.rb