chef-provisioning-vsphere 0.9.0 → 0.10.0

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: d54830a37d53c9a2d1bdb64ebb6629b301b16695
4
- data.tar.gz: b36937d0a2d33f183e7b3e896b14176d599a27c8
3
+ metadata.gz: 122ef0d030113564796d19efc129ee65e1714dd3
4
+ data.tar.gz: eaf4d9767af209f6defa4dba89ad740ae9d3bed6
5
5
  SHA512:
6
- metadata.gz: 2ebfe1f94f677a9b17726ec60d30f4291bb5fe1e0256ffe1e06e5a010be0ff2ee5ab1de8b7b0aff340e5c7d0f51f05b775a2991d52982fa49156cc0422482283
7
- data.tar.gz: bd712a3c8c64700f6f5eaffd12ca53194a20076b35f8c1a5dcba7e804103ae749f47fe13e06525b19e60011bb657191052a2d579063e14bcb078d8ad65ace082
6
+ metadata.gz: 5ed0544f3514340869dcf6c3fd36285399d627af1483c474b10d28ff51f9caebf1020cf08cff87ee344b45a25a9fe3d235eed158d00fa0e9a6d918ec421a873a
7
+ data.tar.gz: 535e22f53664418ace53f14b6ce726a5d4bab4ed7f71d4194c7ff424b77b8401982540cc8a6658a24b98a04bf24f2d8f37ff5e09f7f95477252aa4bf880a17d7
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
- # -*- encoding: utf-8 -*-
2
- source "https://rubygems.org"
3
- gemspec
4
-
5
- gem "chef", "~> 12.3"
1
+ # -*- encoding: utf-8 -*-
2
+ source "https://rubygems.org"
3
+ gemspec
4
+
5
+ gem "chef", "~> 12.3"
data/README.md CHANGED
@@ -84,13 +84,13 @@ This will use chef-zero and needs no chef server (only works for ssh). Note that
84
84
  - `[:memory_mb]` - number of megabytes to allocate for machine
85
85
  - `[:host]` - `{cluster}`/`{host}` to use during provisioning
86
86
  - `[:resource_pool]` - `{cluster}`/`{resource pool}` to use during provisioning
87
- - `[:additional_disk_size_gb]` - an array of numbers, each signifying the number of gigabytes to assign to an additional disk (*his requires a datastore to be specified*)
87
+ - `[:additional_disk_size_gb]` - an array of numbers, each signifying the number of gigabytes to assign to an additional disk (*this requires a datastore to be specified*)
88
88
  - `[:ssh][:user]` user to use for ssh/winrm (defaults to root on linux/administrator on windows)
89
89
  - `[:ssh][:password]` - password to use for ssh/winrm
90
90
  - `[:ssh][:paranoid]` - specifies the strictness of the host key verification checking
91
91
  - `[:ssh][:port]` port to use for ssh/winrm (defaults to 22 for ssh or 5985 for winrm)
92
- - `[:convergence_options][:install_msi_url]` - url to chef client msi to use (defaults to latest)
93
- - `[:convergence_options][:install_sh_url]` - the bach script to install chef client on linux (defaults to latest)
92
+ - `[:convergence_options][:install_msi_url]` - url to chef client msi to use (defaults to latest)
93
+ - `[:convergence_options][:install_sh_url]` - the bash script to install chef client on linux (defaults to latest)
94
94
  - `[:customization_spec][:ipsettings][:ip]` static ip to assign to machine
95
95
  - `[:customization_spec][:ipsettings][:subnetMask]` - subnet to use
96
96
  - `[:customization_spec][:ipsettings][:gateway]` - array of possible gateways to use (this will most often be an array of 1)
@@ -21,8 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
22
22
 
23
23
  s.add_dependency 'rbvmomi', '~> 1.8.0', '>= 1.8.2'
24
- s.add_dependency 'chef-provisioning', '~>1.1'
25
- s.add_dependency 'winrm', '~> 1.6'
24
+ s.add_dependency 'chef-provisioning', '~>2.0', '>= 2.0.1'
26
25
 
27
26
  s.add_development_dependency 'rspec'
28
27
  s.add_development_dependency 'rake'
@@ -144,7 +144,7 @@ module ChefProvisioningVsphere
144
144
  :nicSettingMap => cust_adapter_mapping
145
145
  )
146
146
  else
147
- vsphere_helper.find_customization_spec(cust_options)
147
+ vsphere_helper.find_customization_spec(options[:customization_spec])
148
148
  end
149
149
  end
150
150
  end
@@ -46,7 +46,7 @@ module ChefProvisioningVsphere
46
46
  super(driver_url, config)
47
47
 
48
48
  uri = URI(driver_url)
49
- @connect_options = {
49
+ @connect_options = {
50
50
  provider: 'vsphere',
51
51
  host: uri.host,
52
52
  port: uri.port,
@@ -131,7 +131,7 @@ module ChefProvisioningVsphere
131
131
 
132
132
  action_handler.report_progress full_description(
133
133
  machine_spec, bootstrap_options)
134
-
134
+
135
135
  vm = find_or_create_vm(bootstrap_options, machine_spec, action_handler)
136
136
 
137
137
  add_machine_spec_location(vm, machine_spec)
@@ -183,10 +183,16 @@ module ChefProvisioningVsphere
183
183
  vm
184
184
  end
185
185
 
186
- def full_description(machine_spec, bootstrap_options)
186
+ def full_description(machine_spec, bootstrap_options)
187
187
  description = [ "creating machine #{machine_spec.name} on #{driver_url}" ]
188
188
  bootstrap_options.to_hash.each_pair do |key,value|
189
- description << " #{key}: #{value.inspect}"
189
+ if value.is_a?(Hash) then
190
+ temp_value = value.clone
191
+ temp_value[:password] = "*********" if value.has_key?(:password)
192
+ else
193
+ temp_value = value
194
+ end
195
+ description << " #{key}: #{temp_value.inspect}"
190
196
  end
191
197
  description
192
198
  end
@@ -258,7 +264,7 @@ module ChefProvisioningVsphere
258
264
  # This may just be the ip of a newly cloned machine
259
265
  # Customization below may change this to a valid ip
260
266
  wait_until_ready(action_handler, machine_spec, machine_options, vm)
261
-
267
+
262
268
  if !machine_spec.location['ipaddress'] || !has_ip?(machine_spec.location['ipaddress'], vm)
263
269
  # find the ip we actually want
264
270
  # this will be the static ip to assign
@@ -303,7 +309,7 @@ module ChefProvisioningVsphere
303
309
 
304
310
  def attempt_ip(machine_options, action_handler, vm, machine_spec)
305
311
  vm_ip = ip_to_bootstrap(machine_options[:bootstrap_options], vm)
306
-
312
+
307
313
  wait_for_ip(vm, machine_options, machine_spec, action_handler)
308
314
 
309
315
  unless has_ip?(vm_ip, vm)
@@ -314,7 +320,7 @@ module ChefProvisioningVsphere
314
320
  msg << ' and tools state is '
315
321
  msg << vm.guest.toolsRunningStatus
316
322
  msg << '. powering up server...'
317
- action_handler.report_progress(msg.join)
323
+ action_handler.report_progress(msg)
318
324
  vsphere_helper.start_vm(vm)
319
325
  else
320
326
  restart_server(action_handler, machine_spec, machine_options)
@@ -325,9 +331,19 @@ module ChefProvisioningVsphere
325
331
 
326
332
  def wait_for_domain(bootstrap_options, vm, machine_spec, action_handler)
327
333
  return unless bootstrap_options[:customization_spec]
328
- return unless bootstrap_options[:customization_spec][:domain]
329
334
 
330
- domain = bootstrap_options[:customization_spec][:domain]
335
+ domain = if bootstrap_options[:customization_spec].is_a?(String) && is_windows?(vm)
336
+ spec = vsphere_helper.find_customization_spec(bootstrap_options[:customization_spec])
337
+ spec.identity.identification.joinDomain
338
+ elsif bootstrap_options[:customization_spec].is_a?(String) && !is_windows?(vm)
339
+ spec = vsphere_helper.find_customization_spec(bootstrap_options[:customization_spec])
340
+ spec.identity.domain
341
+ else
342
+ bootstrap_options[:customization_spec][:domain]
343
+ end
344
+
345
+ return unless domain
346
+
331
347
  if is_windows?(vm) && domain != 'local'
332
348
  start = Time.now.utc
333
349
  trimmed_name = machine_spec.name.byteslice(0,15)
@@ -458,11 +474,13 @@ module ChefProvisioningVsphere
458
474
  def has_static_ip(bootstrap_options)
459
475
  if bootstrap_options.has_key?(:customization_spec)
460
476
  bootstrap_options = bootstrap_options[:customization_spec]
461
- if bootstrap_options.has_key?(:ipsettings)
477
+
478
+ if bootstrap_options.is_a?(String)
479
+ spec = vsphere_helper.find_customization_spec(bootstrap_options)
480
+ return spec.nicSettingMap[0].adapter.ip.is_a?(RbVmomi::VIM::CustomizationFixedIp)
481
+ elsif bootstrap_options.has_key?(:ipsettings)
462
482
  bootstrap_options = bootstrap_options[:ipsettings]
463
- if bootstrap_options.has_key?(:ip)
464
- return true
465
- end
483
+ return bootstrap_options.has_key?(:ip)
466
484
  end
467
485
  end
468
486
  false
@@ -473,7 +491,7 @@ module ChefProvisioningVsphere
473
491
  (machine_options[:start_timeout] || 600) -
474
492
  (Time.now.utc - Time.parse(machine_spec.location['started_at']))
475
493
  else
476
- (machine_options[:create_timeout] || 600) -
494
+ (machine_options[:create_timeout] || 600) -
477
495
  (Time.now.utc - Time.parse(machine_spec.location['allocated_at']))
478
496
  end
479
497
  end
@@ -483,7 +501,7 @@ module ChefProvisioningVsphere
483
501
  if action_handler.should_perform_actions
484
502
  action_handler.report_progress "waiting for #{machine_spec.name} (#{vm.config.instanceUuid} on #{driver_url}) to be ready ..."
485
503
  until remaining_wait_time(machine_spec, machine_options) < 0 ||
486
- (vm.guest.toolsRunningStatus == "guestToolsRunning" && !vm.guest.ipAddress.nil? && vm.guest.ipAddress.length > 0) do
504
+ (vm.guest.toolsRunningStatus == "guestToolsRunning" && vm.guest.ipAddress && !vm.guest.ipAddress.empty?) do
487
505
  print "."
488
506
  sleep 5
489
507
  end
@@ -519,12 +537,12 @@ module ChefProvisioningVsphere
519
537
  additional_disk_size_gb = bootstrap_options[:additional_disk_size_gb]
520
538
  if !additional_disk_size_gb.is_a?(Array)
521
539
  additional_disk_size_gb = [additional_disk_size_gb]
522
- end
540
+ end
523
541
 
524
542
  additional_disk_size_gb.each do |size|
525
543
  size = size.to_i
526
544
  next if size == 0
527
- if bootstrap_options[:datastore].to_s.empty?
545
+ if bootstrap_options[:datastore].to_s.empty?
528
546
  raise ':datastore must be specified when adding a disk to a cloned vm'
529
547
  end
530
548
  task = vm.ReconfigVM_Task(
@@ -546,7 +564,7 @@ module ChefProvisioningVsphere
546
564
 
547
565
  def vsphere_helper
548
566
  @vsphere_helper ||= VsphereHelper.new(
549
- connect_options,
567
+ connect_options,
550
568
  config[:machine_options][:bootstrap_options][:datacenter]
551
569
  )
552
570
  end
@@ -564,11 +582,11 @@ module ChefProvisioningVsphere
564
582
  end
565
583
 
566
584
  transport = transport_for(
567
- machine_spec,
585
+ machine_spec,
568
586
  machine_options[:bootstrap_options][:ssh]
569
587
  )
570
588
  strategy = convergence_strategy_for(machine_spec, machine_options)
571
-
589
+
572
590
  if machine_spec.location['is_windows']
573
591
  Chef::Provisioning::Machine::WindowsMachine.new(
574
592
  machine_spec, transport, strategy)
@@ -628,8 +646,8 @@ module ChefProvisioningVsphere
628
646
  end
629
647
 
630
648
  def transport_for(
631
- machine_spec,
632
- remoting_options,
649
+ machine_spec,
650
+ remoting_options,
633
651
  ip = machine_spec.location['ipaddress']
634
652
  )
635
653
  if machine_spec.location['is_windows']
@@ -679,9 +697,14 @@ module ChefProvisioningVsphere
679
697
 
680
698
  def ip_to_bootstrap(bootstrap_options, vm)
681
699
  if has_static_ip(bootstrap_options)
682
- bootstrap_options[:customization_spec][:ipsettings][:ip]
700
+ if bootstrap_options[:customization_spec].is_a?(String)
701
+ spec = vsphere_helper.find_customization_spec(bootstrap_options[:customization_spec])
702
+ spec.nicSettingMap[0].adapter.ip.ipAddress
703
+ else
704
+ bootstrap_options[:customization_spec][:ipsettings][:ip]
705
+ end
683
706
  else
684
- vm.guest.ipAddress
707
+ vm.guest.ipAddress
685
708
  end
686
709
  end
687
710
  end
@@ -1,3 +1,3 @@
1
1
  module ChefProvisioningVsphere
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -83,8 +83,14 @@ module ChefProvisioningVsphere
83
83
 
84
84
  def datacenter
85
85
  vim # ensure connection is valid
86
- @datacenter ||= vim.serviceInstance.find_datacenter(datacenter_name) ||
87
- raise("vSphere Datacenter not found [#{datacenter_name}]")
86
+ @datacenter ||= begin
87
+ rootFolder = vim.serviceInstance.content.rootFolder
88
+ dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).find do |x|
89
+ x.name == datacenter_name
90
+ end
91
+ raise("vSphere Datacenter not found [#{datacenter_name}]") if dc.nil?
92
+ dc
93
+ end
88
94
  end
89
95
 
90
96
  def network_adapter_for(operation, network_name, network_label, device_key, backing_info)
@@ -1,104 +1,104 @@
1
- require 'json'
2
- require 'kitchen'
3
- require 'chef/provisioning/vsphere_driver'
4
- require 'chef/provisioning/machine_spec'
5
-
6
- module Kitchen
7
- module Driver
8
- class Vsphere < Kitchen::Driver::Base
9
-
10
- @@chef_zero_server = false
11
-
12
- default_config :machine_options,
13
- :start_timeout => 600,
14
- :create_timeout => 600,
15
- :stop_timeout => 600,
16
- :ready_timeout => 90,
17
- :bootstrap_options => {
18
- :use_linked_clone => true,
19
- :ssh => {
20
- :user => 'root',
21
- :paranoid => false,
22
- :port => 22
23
- },
24
- :convergence_options => {},
25
- :customization_spec => {
26
- :domain => 'local'
27
- }
28
- }
29
-
30
- default_config(:vsphere_name) do |driver|
31
- "#{driver.instance.name}-#{SecureRandom.hex(4)}"
32
- end
33
-
34
- def create(state)
35
- state[:vsphere_name] = config[:vsphere_name]
36
- state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
37
- state[:password] = config[:machine_options][:bootstrap_options][:ssh][:password]
38
- config[:server_name] = state[:vsphere_name]
39
-
40
- machine = with_provisioning_driver(state) do | action_handler, driver, machine_spec|
41
- driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
42
- driver.ready_machine(action_handler, machine_spec, config[:machine_options])
43
- state[:server_id] = machine_spec.location['server_id']
44
- state[:hostname] = machine_spec.location['ipaddress']
45
- machine_spec.save(action_handler)
46
- end
47
- end
48
-
49
- def destroy(state)
50
- return if state[:server_id].nil?
51
-
52
- with_provisioning_driver(state) do | action_handler, driver, machine_spec|
53
- machine_spec.location = { 'driver_url' => driver.driver_url,
54
- 'server_id' => state[:server_id]}
55
- driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
56
- end
57
-
58
- state.delete(:server_id)
59
- state.delete(:hostname)
60
- state.delete(:vsphere_name)
61
- end
62
-
63
- def with_provisioning_driver(state, &block)
64
- config[:machine_options][:convergence_options] = {:chef_server => chef_server}
65
- machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).get(:machine, state[:vsphere_name])
66
- if machine_spec.nil?
67
- machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server)
68
- .new_entry(:machine, state[:vsphere_name])
69
- end
70
- url = URI::VsphereUrl.from_config(@config[:driver_options]).to_s
71
- driver = Chef::Provisioning.driver_for_url(url, config)
72
- action_handler = Chef::Provisioning::ActionHandler.new
73
- block.call(action_handler, driver, machine_spec)
74
- end
75
-
76
- def chef_server
77
- if !@@chef_zero_server
78
- vsphere_mutex.synchronize do
79
- if !@@chef_zero_server
80
- Chef::Config.local_mode = true
81
- Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
82
- require 'chef/local_mode'
83
- Chef::LocalMode.setup_server_connectivity
84
- @@chef_zero_server = true
85
- end
86
- end
87
- end
88
-
89
- Cheffish.default_chef_server
90
- end
91
-
92
- def vsphere_mutex
93
- @@vsphere_mutex ||= begin
94
- Kitchen.mutex.synchronize do
95
- instance.class.mutexes ||= Hash.new
96
- instance.class.mutexes[self.class] = Mutex.new
97
- end
98
-
99
- instance.class.mutexes[self.class]
100
- end
101
- end
102
- end
103
- end
104
- end
1
+ require 'json'
2
+ require 'kitchen'
3
+ require 'chef/provisioning/vsphere_driver'
4
+ require 'chef/provisioning/machine_spec'
5
+
6
+ module Kitchen
7
+ module Driver
8
+ class Vsphere < Kitchen::Driver::Base
9
+
10
+ @@chef_zero_server = false
11
+
12
+ default_config :machine_options,
13
+ :start_timeout => 600,
14
+ :create_timeout => 600,
15
+ :stop_timeout => 600,
16
+ :ready_timeout => 90,
17
+ :bootstrap_options => {
18
+ :use_linked_clone => true,
19
+ :ssh => {
20
+ :user => 'root',
21
+ :paranoid => false,
22
+ :port => 22
23
+ },
24
+ :convergence_options => {},
25
+ :customization_spec => {
26
+ :domain => 'local'
27
+ }
28
+ }
29
+
30
+ default_config(:vsphere_name) do |driver|
31
+ "#{driver.instance.name}-#{SecureRandom.hex(4)}"
32
+ end
33
+
34
+ def create(state)
35
+ state[:vsphere_name] = config[:vsphere_name]
36
+ state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
37
+ state[:password] = config[:machine_options][:bootstrap_options][:ssh][:password]
38
+ config[:server_name] = state[:vsphere_name]
39
+
40
+ machine = with_provisioning_driver(state) do | action_handler, driver, machine_spec|
41
+ driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
42
+ driver.ready_machine(action_handler, machine_spec, config[:machine_options])
43
+ state[:server_id] = machine_spec.location['server_id']
44
+ state[:hostname] = machine_spec.location['ipaddress']
45
+ machine_spec.save(action_handler)
46
+ end
47
+ end
48
+
49
+ def destroy(state)
50
+ return if state[:server_id].nil?
51
+
52
+ with_provisioning_driver(state) do | action_handler, driver, machine_spec|
53
+ machine_spec.location = { 'driver_url' => driver.driver_url,
54
+ 'server_id' => state[:server_id]}
55
+ driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
56
+ end
57
+
58
+ state.delete(:server_id)
59
+ state.delete(:hostname)
60
+ state.delete(:vsphere_name)
61
+ end
62
+
63
+ def with_provisioning_driver(state, &block)
64
+ config[:machine_options][:convergence_options] = {:chef_server => chef_server}
65
+ machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).get(:machine, state[:vsphere_name])
66
+ if machine_spec.nil?
67
+ machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server)
68
+ .new_entry(:machine, state[:vsphere_name])
69
+ end
70
+ url = URI::VsphereUrl.from_config(@config[:driver_options]).to_s
71
+ driver = Chef::Provisioning.driver_for_url(url, config)
72
+ action_handler = Chef::Provisioning::ActionHandler.new
73
+ block.call(action_handler, driver, machine_spec)
74
+ end
75
+
76
+ def chef_server
77
+ if !@@chef_zero_server
78
+ vsphere_mutex.synchronize do
79
+ if !@@chef_zero_server
80
+ Chef::Config.local_mode = true
81
+ Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
82
+ require 'chef/local_mode'
83
+ Chef::LocalMode.setup_server_connectivity
84
+ @@chef_zero_server = true
85
+ end
86
+ end
87
+ end
88
+
89
+ Cheffish.default_chef_server
90
+ end
91
+
92
+ def vsphere_mutex
93
+ @@vsphere_mutex ||= begin
94
+ Kitchen.mutex.synchronize do
95
+ instance.class.mutexes ||= Hash.new
96
+ instance.class.mutexes[self.class] = Mutex.new
97
+ end
98
+
99
+ instance.class.mutexes[self.class]
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbvmomi
@@ -36,28 +36,20 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.1'
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '1.1'
47
- - !ruby/object:Gem::Dependency
48
- name: winrm
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
39
+ version: '2.0'
40
+ - - ">="
52
41
  - !ruby/object:Gem::Version
53
- version: '1.6'
42
+ version: 2.0.1
54
43
  type: :runtime
55
44
  prerelease: false
56
45
  version_requirements: !ruby/object:Gem::Requirement
57
46
  requirements:
58
47
  - - "~>"
59
48
  - !ruby/object:Gem::Version
60
- version: '1.6'
49
+ version: '2.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.1
61
53
  - !ruby/object:Gem::Dependency
62
54
  name: rspec
63
55
  requirement: !ruby/object:Gem::Requirement