chef-provisioning-vsphere 2.0.7 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +12 -25
- data/CHANGELOG.md +13 -2
- data/Gemfile +2 -1
- data/Rakefile +17 -16
- data/chef-provisioning-vsphere.gemspec +28 -26
- data/lib/chef/provisioning/driver_init/vsphere.rb +3 -2
- data/lib/chef/provisioning/vsphere_driver.rb +3 -2
- data/lib/chef/provisioning/vsphere_driver/clone_spec_builder.rb +11 -11
- data/lib/chef/provisioning/vsphere_driver/driver.rb +87 -86
- data/lib/chef/provisioning/vsphere_driver/version.rb +2 -1
- data/lib/chef/provisioning/vsphere_driver/vm_helper.rb +5 -4
- data/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb +27 -26
- data/lib/chef/provisioning/vsphere_driver/vsphere_url.rb +14 -13
- data/lib/kitchen/driver/vsphere.rb +14 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac457d36ea3bae1eefdf3dcaba502d925840270
|
4
|
+
data.tar.gz: 76a60e37d9861883bc4932074c9f6d80034c2245
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7996f02f1e180e2375fb790c06a961b8abcd32850085b31adc56e3b7feb12fbc5f6805199112443d143e2404c19c625f133a29922f48afc36d00245aa27bba31
|
7
|
+
data.tar.gz: 4e805e07531c27d64143917c094d3037b2e25aa2047ace08b2c2bf2eab8e78529cfc656bce0db161de72ac06d35e8510a14f67015b6ec2817806112be79754ad
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-
|
3
|
+
# on 2017-10-20 14:57:28 -0700 using RuboCop version 0.49.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -12,14 +12,13 @@ Lint/AssignmentInCondition:
|
|
12
12
|
Exclude:
|
13
13
|
- 'lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb'
|
14
14
|
|
15
|
-
# Offense count:
|
15
|
+
# Offense count: 1
|
16
16
|
# Cop supports --auto-correct.
|
17
17
|
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
|
18
18
|
# SupportedStylesAlignWith: start_of_line, def
|
19
19
|
Lint/DefEndAlignment:
|
20
20
|
Exclude:
|
21
21
|
- 'lib/chef/provisioning/vsphere_driver/driver.rb'
|
22
|
-
- 'lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb'
|
23
22
|
|
24
23
|
# Offense count: 1
|
25
24
|
# Cop supports --auto-correct.
|
@@ -29,21 +28,21 @@ Lint/EndAlignment:
|
|
29
28
|
Exclude:
|
30
29
|
- 'lib/chef/provisioning/vsphere_driver/driver.rb'
|
31
30
|
|
32
|
-
# Offense count:
|
31
|
+
# Offense count: 6
|
33
32
|
Lint/UselessAssignment:
|
34
33
|
Exclude:
|
35
34
|
- 'lib/chef/provisioning/vsphere_driver/clone_spec_builder.rb'
|
36
35
|
- 'lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb'
|
37
36
|
- 'lib/kitchen/driver/vsphere.rb'
|
38
37
|
|
39
|
-
# Offense count:
|
38
|
+
# Offense count: 34
|
40
39
|
Metrics/AbcSize:
|
41
40
|
Max: 47
|
42
41
|
|
43
42
|
# Offense count: 1
|
44
43
|
# Configuration parameters: CountComments, ExcludedMethods.
|
45
44
|
Metrics/BlockLength:
|
46
|
-
Max:
|
45
|
+
Max: 29
|
47
46
|
|
48
47
|
# Offense count: 1
|
49
48
|
# Configuration parameters: CountBlocks.
|
@@ -53,24 +52,24 @@ Metrics/BlockNesting:
|
|
53
52
|
# Offense count: 3
|
54
53
|
# Configuration parameters: CountComments.
|
55
54
|
Metrics/ClassLength:
|
56
|
-
Max:
|
55
|
+
Max: 627
|
57
56
|
|
58
|
-
# Offense count:
|
57
|
+
# Offense count: 11
|
59
58
|
Metrics/CyclomaticComplexity:
|
60
59
|
Max: 12
|
61
60
|
|
62
|
-
# Offense count:
|
61
|
+
# Offense count: 138
|
63
62
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
64
63
|
# URISchemes: http, https
|
65
64
|
Metrics/LineLength:
|
66
65
|
Max: 189
|
67
66
|
|
68
|
-
# Offense count:
|
67
|
+
# Offense count: 41
|
69
68
|
# Configuration parameters: CountComments.
|
70
69
|
Metrics/MethodLength:
|
71
70
|
Max: 62
|
72
71
|
|
73
|
-
# Offense count:
|
72
|
+
# Offense count: 8
|
74
73
|
Metrics/PerceivedComplexity:
|
75
74
|
Max: 14
|
76
75
|
|
@@ -84,24 +83,13 @@ Style/ClassVars:
|
|
84
83
|
Exclude:
|
85
84
|
- 'lib/kitchen/driver/vsphere.rb'
|
86
85
|
|
87
|
-
# Offense count: 6
|
88
|
-
Style/Documentation:
|
89
|
-
Exclude:
|
90
|
-
- 'spec/**/*'
|
91
|
-
- 'test/**/*'
|
92
|
-
- 'lib/chef/provisioning/vsphere_driver.rb'
|
93
|
-
- 'lib/chef/provisioning/vsphere_driver/clone_spec_builder.rb'
|
94
|
-
- 'lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb'
|
95
|
-
- 'lib/chef/provisioning/vsphere_driver/vsphere_url.rb'
|
96
|
-
- 'lib/kitchen/driver/vsphere.rb'
|
97
|
-
|
98
86
|
# Offense count: 5
|
99
87
|
# Configuration parameters: AllowedVariables.
|
100
88
|
Style/GlobalVars:
|
101
89
|
Exclude:
|
102
90
|
- 'lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb'
|
103
91
|
|
104
|
-
# Offense count:
|
92
|
+
# Offense count: 13
|
105
93
|
# Configuration parameters: MinBodyLength.
|
106
94
|
Style/GuardClause:
|
107
95
|
Exclude:
|
@@ -119,7 +107,7 @@ Style/NestedTernaryOperator:
|
|
119
107
|
Exclude:
|
120
108
|
- 'lib/chef/provisioning/vsphere_driver/driver.rb'
|
121
109
|
|
122
|
-
# Offense count:
|
110
|
+
# Offense count: 1
|
123
111
|
# Cop supports --auto-correct.
|
124
112
|
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
|
125
113
|
# SupportedStyles: predicate, comparison
|
@@ -127,7 +115,6 @@ Style/NumericPredicate:
|
|
127
115
|
Exclude:
|
128
116
|
- 'spec/**/*'
|
129
117
|
- 'lib/chef/provisioning/vsphere_driver/driver.rb'
|
130
|
-
- 'lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb'
|
131
118
|
|
132
119
|
# Offense count: 3
|
133
120
|
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [2.0.
|
4
|
-
[Full Changelog](https://github.com/chef-partners/chef-provisioning-vsphere/compare/v2.0.
|
3
|
+
## [2.0.8](https://github.com/chef-partners/chef-provisioning-vsphere/tree/2.0.8) (2017-10-23)
|
4
|
+
[Full Changelog](https://github.com/chef-partners/chef-provisioning-vsphere/compare/v2.0.7...2.0.8)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Action :destroy fails on powered off VM [\#59](https://github.com/chef-partners/chef-provisioning-vsphere/issues/59)
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- rubocop -a && rubocop --auto-gen-config [\#61](https://github.com/chef-partners/chef-provisioning-vsphere/pull/61) ([bemehiser](https://github.com/bemehiser))
|
13
|
+
|
14
|
+
## [v2.0.7](https://github.com/chef-partners/chef-provisioning-vsphere/tree/v2.0.7) (2017-10-19)
|
15
|
+
[Full Changelog](https://github.com/chef-partners/chef-provisioning-vsphere/compare/v2.0.6...v2.0.7)
|
5
16
|
|
6
17
|
**Closed issues:**
|
7
18
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,40 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
require "chef/provisioning/vsphere_driver/version"
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
require "rubocop/rake_task"
|
6
|
-
require "yard"
|
7
2
|
|
8
|
-
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'chef/provisioning/vsphere_driver/version'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
require 'yard'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib')
|
9
10
|
|
10
11
|
RuboCop::RakeTask.new(:style) do |task|
|
11
|
-
task.options <<
|
12
|
+
task.options << '--display-cop-names'
|
12
13
|
end
|
13
14
|
|
14
15
|
RSpec::Core::RakeTask.new(:unit) do |task|
|
15
|
-
task.pattern =
|
16
|
-
task.rspec_opts = [
|
16
|
+
task.pattern = 'spec/unit_tests/*_spec.rb'
|
17
|
+
task.rspec_opts = ['--color', '-f documentation']
|
17
18
|
end
|
18
19
|
|
19
20
|
RSpec::Core::RakeTask.new(:integration) do |task|
|
20
|
-
task.pattern =
|
21
|
-
task.rspec_opts = [
|
21
|
+
task.pattern = 'spec/integration_tests/*_spec.rb'
|
22
|
+
task.rspec_opts = ['--color', '-f documentation', '--out rspec.txt']
|
22
23
|
end
|
23
24
|
|
24
25
|
begin
|
25
|
-
require
|
26
|
+
require 'github_changelog_generator/task'
|
26
27
|
|
27
28
|
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
28
29
|
config.future_release = ChefProvisioningVsphere::VERSION
|
29
30
|
config.issues = true
|
30
31
|
end
|
31
32
|
rescue LoadError
|
32
|
-
puts
|
33
|
+
puts 'github_changelog_generator is not available. gem install github_changelog_generator to generate changelogs'
|
33
34
|
end
|
34
35
|
|
35
36
|
YARD::Rake::YardocTask.new do |t|
|
36
|
-
t.files = [
|
37
|
-
t.stats_options = [
|
37
|
+
t.files = ['lib/**/*.rb'] # optional
|
38
|
+
t.stats_options = ['--list-undoc'] # optional
|
38
39
|
end
|
39
40
|
|
40
|
-
task default: [
|
41
|
+
task default: %i[style unit]
|
@@ -1,37 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/lib")
|
3
|
-
require "chef/provisioning/vsphere_driver/version"
|
4
2
|
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib')
|
4
|
+
require 'chef/provisioning/vsphere_driver/version'
|
5
|
+
|
6
|
+
# rubocop Metrics/ModuleLength
|
5
7
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
8
|
+
s.name = 'chef-provisioning-vsphere'
|
7
9
|
s.version = ChefProvisioningVsphere::VERSION
|
8
10
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.extra_rdoc_files = [
|
10
|
-
s.summary =
|
11
|
+
s.extra_rdoc_files = ['README.md']
|
12
|
+
s.summary = 'Provisioner for creating vSphere VM instances in Chef Provisioning.'
|
11
13
|
s.description = s.summary
|
12
|
-
s.authors = [
|
13
|
-
s.email =
|
14
|
-
s.homepage =
|
15
|
-
s.license =
|
16
|
-
s.bindir =
|
17
|
-
s.executables = %w
|
18
|
-
s.require_path =
|
14
|
+
s.authors = ['CenturyLink Cloud', 'JJ Asghar']
|
15
|
+
s.email = 'jj@chef.io'
|
16
|
+
s.homepage = 'https://github.com/chef-partners/chef-provisioning-vsphere'
|
17
|
+
s.license = 'MIT'
|
18
|
+
s.bindir = 'bin'
|
19
|
+
s.executables = %w[]
|
20
|
+
s.require_path = 'lib'
|
19
21
|
s.files = `git ls-files -z`.split("\x0")
|
20
22
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
21
23
|
|
22
|
-
s.add_dependency
|
23
|
-
s.add_dependency
|
24
|
-
s.add_dependency
|
25
|
-
s.add_dependency
|
24
|
+
s.add_dependency 'chef', '>= 12.0', '< 14.0'
|
25
|
+
s.add_dependency 'chef-provisioning', '~> 2.0'
|
26
|
+
s.add_dependency 'cheffish', '>= 4.0', '< 14.0'
|
27
|
+
s.add_dependency 'rbvmomi', '~> 1.10'
|
26
28
|
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
30
|
-
s.add_development_dependency
|
31
|
-
s.add_development_dependency
|
32
|
-
s.add_development_dependency
|
33
|
-
s.add_development_dependency
|
34
|
-
s.add_development_dependency
|
35
|
-
s.add_development_dependency
|
36
|
-
s.add_development_dependency
|
29
|
+
s.add_development_dependency 'chefstyle'
|
30
|
+
s.add_development_dependency 'github_changelog_generator'
|
31
|
+
s.add_development_dependency 'pry'
|
32
|
+
s.add_development_dependency 'pry-byebug'
|
33
|
+
s.add_development_dependency 'pry-stack_explorer'
|
34
|
+
s.add_development_dependency 'rake'
|
35
|
+
s.add_development_dependency 'rb-readline'
|
36
|
+
s.add_development_dependency 'rspec'
|
37
|
+
s.add_development_dependency 'simplecov'
|
38
|
+
s.add_development_dependency 'yard'
|
37
39
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "chef/provisioning/vsphere_driver"
|
3
2
|
|
4
|
-
|
3
|
+
require 'chef/provisioning/vsphere_driver'
|
4
|
+
|
5
|
+
Chef::Provisioning.register_driver_class('vsphere', ChefProvisioningVsphere::VsphereDriver)
|
@@ -78,12 +78,12 @@ module ChefProvisioningVsphere
|
|
78
78
|
elsif vm_template.config.template && !host.nil?
|
79
79
|
rspec.pool = host.parent.resourcePool # assign to the "invisible" pool root
|
80
80
|
elsif vm_template.config.template
|
81
|
-
raise
|
81
|
+
raise 'either :host or :resource_pool must be specified when cloning from a VM Template'
|
82
82
|
end
|
83
83
|
|
84
84
|
if options[:use_linked_clone]
|
85
85
|
if vm_template.config.template
|
86
|
-
Chef::Log.warn(
|
86
|
+
Chef::Log.warn('Using a VM Template, ignoring use_linked_clone.')
|
87
87
|
else
|
88
88
|
vsphere_helper.create_delta_disk(vm_template)
|
89
89
|
rspec.diskMoveType = :moveChildMostDiskBacking
|
@@ -105,16 +105,16 @@ module ChefProvisioningVsphere
|
|
105
105
|
def customization_options_from(vm_template, vm_name, options)
|
106
106
|
if options.key?(:customization_spec)
|
107
107
|
if options[:customization_spec].is_a?(Hash) ||
|
108
|
-
|
108
|
+
options[:customization_spec].is_a?(Cheffish::MergedConfig)
|
109
109
|
cust_options = options[:customization_spec]
|
110
110
|
ip_settings = cust_options[:ipsettings]
|
111
111
|
cust_domain = cust_options[:domain]
|
112
112
|
|
113
|
-
raise ArgumentError,
|
113
|
+
raise ArgumentError, 'domain is required' unless cust_domain
|
114
114
|
cust_ip_settings = nil
|
115
115
|
if ip_settings && ip_settings.key?(:ip)
|
116
116
|
unless cust_options[:ipsettings].key?(:subnetMask)
|
117
|
-
raise ArgumentError,
|
117
|
+
raise ArgumentError, 'subnetMask is required for static ip'
|
118
118
|
end
|
119
119
|
cust_ip_settings = RbVmomi::VIM::CustomizationIPSettings.new(
|
120
120
|
ip_settings
|
@@ -145,7 +145,7 @@ module ChefProvisioningVsphere
|
|
145
145
|
cust_hwclockutc = cust_options[:hw_clock_utc]
|
146
146
|
cust_timezone = cust_options[:time_zone]
|
147
147
|
|
148
|
-
cust_prep = if vm_template.config.guestId.start_with?(
|
148
|
+
cust_prep = if vm_template.config.guestId.start_with?('win')
|
149
149
|
windows_prep_for(options, vm_name)
|
150
150
|
else
|
151
151
|
RbVmomi::VIM::CustomizationLinuxPrep.new(
|
@@ -158,7 +158,7 @@ module ChefProvisioningVsphere
|
|
158
158
|
cust_adapter_mapping = [
|
159
159
|
RbVmomi::VIM::CustomizationAdapterMapping.new(
|
160
160
|
adapter: cust_ip_settings
|
161
|
-
)
|
161
|
+
)
|
162
162
|
]
|
163
163
|
RbVmomi::VIM::CustomizationSpec.new(
|
164
164
|
identity: cust_prep,
|
@@ -179,7 +179,7 @@ module ChefProvisioningVsphere
|
|
179
179
|
hostname = options[:hostname] || vm_name
|
180
180
|
test = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])$/
|
181
181
|
unless hostname =~ test
|
182
|
-
raise
|
182
|
+
raise 'Only letters, numbers or hyphens in hostnames allowed'
|
183
183
|
end
|
184
184
|
RbVmomi::VIM::CustomizationFixedName.new(name: hostname)
|
185
185
|
end
|
@@ -200,10 +200,10 @@ module ChefProvisioningVsphere
|
|
200
200
|
plainText: true,
|
201
201
|
value: options[:ssh][:password]
|
202
202
|
)
|
203
|
-
if cust_options.key?(:domain) && (cust_options[:domain] !=
|
203
|
+
if cust_options.key?(:domain) && (cust_options[:domain] != 'local')
|
204
204
|
cust_domain_password = RbVmomi::VIM::CustomizationPassword(
|
205
205
|
plainText: true,
|
206
|
-
value: ENV[
|
206
|
+
value: ENV['domainAdminPassword'] || cust_options[:domainAdminPassword]
|
207
207
|
)
|
208
208
|
cust_id = RbVmomi::VIM::CustomizationIdentification.new(
|
209
209
|
joinDomain: cust_options[:domain],
|
@@ -214,7 +214,7 @@ module ChefProvisioningVsphere
|
|
214
214
|
with user: #{cust_options[:domainAdmin]}"
|
215
215
|
else
|
216
216
|
cust_id = RbVmomi::VIM::CustomizationIdentification.new(
|
217
|
-
joinWorkgroup:
|
217
|
+
joinWorkgroup: 'WORKGROUP'
|
218
218
|
)
|
219
219
|
end
|
220
220
|
cust_gui_unattended = RbVmomi::VIM::CustomizationGuiUnattended.new(
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
2
|
+
|
3
|
+
require 'chef'
|
4
|
+
require 'cheffish/merged_config'
|
5
|
+
require 'chef/provisioning/driver'
|
6
|
+
require 'chef/provisioning/machine/windows_machine'
|
7
|
+
require 'chef/provisioning/machine/unix_machine'
|
8
|
+
require 'chef/provisioning/vsphere_driver/clone_spec_builder'
|
9
|
+
require 'chef/provisioning/vsphere_driver/version'
|
10
|
+
require 'chef/provisioning/vsphere_driver/vsphere_helpers'
|
11
|
+
require 'chef/provisioning/vsphere_driver/vsphere_url'
|
12
|
+
require 'chef/provisioning/vsphere_driver/vm_helper'
|
12
13
|
|
13
14
|
# Provisions machines in vSphere.
|
14
15
|
module ChefProvisioningVsphere
|
@@ -73,12 +74,12 @@ module ChefProvisioningVsphere
|
|
73
74
|
|
74
75
|
uri = URI(driver_url)
|
75
76
|
@connect_options = {
|
76
|
-
provider:
|
77
|
+
provider: 'vsphere',
|
77
78
|
host: uri.host,
|
78
79
|
port: uri.port,
|
79
80
|
use_ssl: uri.use_ssl,
|
80
81
|
insecure: uri.insecure,
|
81
|
-
path: uri.path
|
82
|
+
path: uri.path
|
82
83
|
}
|
83
84
|
|
84
85
|
if driver_options
|
@@ -149,13 +150,13 @@ module ChefProvisioningVsphere
|
|
149
150
|
)
|
150
151
|
vm = vm_for(machine_spec)
|
151
152
|
if vm
|
152
|
-
Chef::Log.warn
|
153
|
+
Chef::Log.warn 'returning existing machine'
|
153
154
|
return vm
|
154
155
|
else
|
155
156
|
Chef::Log.warn machine_msg(
|
156
157
|
machine_spec.name,
|
157
|
-
machine_spec.location[
|
158
|
-
|
158
|
+
machine_spec.location['server_id'],
|
159
|
+
'no longer exists. Recreating ...'
|
159
160
|
)
|
160
161
|
end
|
161
162
|
end
|
@@ -172,7 +173,7 @@ module ChefProvisioningVsphere
|
|
172
173
|
action_handler.performed_action(machine_msg(
|
173
174
|
machine_spec.name,
|
174
175
|
vm.config.instanceUuid,
|
175
|
-
|
176
|
+
'created'
|
176
177
|
))
|
177
178
|
vm
|
178
179
|
end
|
@@ -194,12 +195,12 @@ module ChefProvisioningVsphere
|
|
194
195
|
# @param [Object] vm taken from Chef provisioning for all the vm state.
|
195
196
|
def add_machine_spec_location(vm, machine_spec)
|
196
197
|
machine_spec.location = {
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
198
|
+
'driver_url' => driver_url,
|
199
|
+
'driver_version' => VERSION,
|
200
|
+
'server_id' => vm.config.instanceUuid,
|
201
|
+
'is_windows' => is_windows?(vm),
|
202
|
+
'allocated_at' => Time.now.utc.to_s,
|
203
|
+
'ipaddress' => vm.guest.ipAddress
|
203
204
|
}
|
204
205
|
end
|
205
206
|
|
@@ -217,7 +218,7 @@ module ChefProvisioningVsphere
|
|
217
218
|
Chef::Log.info machine_msg(
|
218
219
|
machine_spec.name,
|
219
220
|
vm.config.instanceUuid,
|
220
|
-
|
221
|
+
'already created'
|
221
222
|
)
|
222
223
|
else
|
223
224
|
vm = clone_vm(
|
@@ -238,7 +239,7 @@ module ChefProvisioningVsphere
|
|
238
239
|
bootstrap_options.to_hash.each_pair do |key, value|
|
239
240
|
if value.is_a?(Hash)
|
240
241
|
temp_value = value.clone
|
241
|
-
temp_value[:password] =
|
242
|
+
temp_value[:password] = '*********' if value.key?(:password)
|
242
243
|
else
|
243
244
|
temp_value = value
|
244
245
|
end
|
@@ -269,7 +270,7 @@ module ChefProvisioningVsphere
|
|
269
270
|
vm = start_machine(action_handler, machine_spec, machine_options)
|
270
271
|
if vm.nil?
|
271
272
|
raise "Machine #{machine_spec.name} does not have a server "\
|
272
|
-
|
273
|
+
'associated with it, or server does not exist.'
|
273
274
|
end
|
274
275
|
|
275
276
|
bootstrap_options = machine_options[:bootstrap_options]
|
@@ -290,7 +291,7 @@ module ChefProvisioningVsphere
|
|
290
291
|
end
|
291
292
|
|
292
293
|
## Check if true available after added nic
|
293
|
-
@vm_helper.open_port?(machine_spec.location[
|
294
|
+
@vm_helper.open_port?(machine_spec.location['ipaddress'], @vm_helper.port) unless machine_spec.location['ipaddress'].nil?
|
294
295
|
machine
|
295
296
|
end
|
296
297
|
|
@@ -311,7 +312,7 @@ module ChefProvisioningVsphere
|
|
311
312
|
bootstrap_options,
|
312
313
|
vm
|
313
314
|
)
|
314
|
-
if is_windows?(vm) && !new_nics.nil? && @vm_helper.open_port?(machine_spec.location[
|
315
|
+
if is_windows?(vm) && !new_nics.nil? && @vm_helper.open_port?(machine_spec.location['ipaddress'], @vm_helper.port)
|
315
316
|
new_nics.each do |nic|
|
316
317
|
nic_label = nic.device.deviceInfo.label
|
317
318
|
machine.execute_always(
|
@@ -340,13 +341,13 @@ module ChefProvisioningVsphere
|
|
340
341
|
# Customization below may change this to a valid ip
|
341
342
|
wait_until_ready(action_handler, machine_spec, machine_options, vm)
|
342
343
|
|
343
|
-
if !machine_spec.location[
|
344
|
+
if !machine_spec.location['ipaddress'] || !has_ip?(machine_spec.location['ipaddress'], vm)
|
344
345
|
# find the ip we actually want
|
345
346
|
# this will be the static ip to assign
|
346
347
|
# or the ip reported back by the vm if using dhcp
|
347
348
|
# it *may* be nil if just cloned
|
348
349
|
vm_ip = ip_to_bootstrap(bootstrap_options, vm) || vm.guest.ipAddress
|
349
|
-
machine_spec.location[
|
350
|
+
machine_spec.location['ipaddress'] = vm_ip
|
350
351
|
transport = nil
|
351
352
|
unless vm_ip.nil?
|
352
353
|
transport = transport_for(machine_spec, bootstrap_options[:ssh], vm_ip)
|
@@ -355,9 +356,9 @@ module ChefProvisioningVsphere
|
|
355
356
|
unless !transport.nil? && transport.available? && has_ip?(vm_ip, vm)
|
356
357
|
attempt_ip(machine_options, action_handler, vm, machine_spec)
|
357
358
|
end
|
358
|
-
machine_spec.location[
|
359
|
+
machine_spec.location['ipaddress'] = vm_ip # vm.guest.ipAddress vmWare ip_address here can be 0.0.0.0
|
359
360
|
action_handler.report_progress(
|
360
|
-
"IP address obtained: #{machine_spec.location[
|
361
|
+
"IP address obtained: #{machine_spec.location['ipaddress']}"
|
361
362
|
)
|
362
363
|
end
|
363
364
|
|
@@ -367,14 +368,14 @@ module ChefProvisioningVsphere
|
|
367
368
|
wait_for_transport(action_handler, machine_spec, machine_options, vm)
|
368
369
|
rescue Timeout::Error
|
369
370
|
# Only ever reboot once, and only if it's been less than 10 minutes since we stopped waiting
|
370
|
-
if machine_spec.location[
|
371
|
-
|
371
|
+
if machine_spec.location['started_at'] ||
|
372
|
+
remaining_wait_time(machine_spec, machine_options) < -(10 * 60)
|
372
373
|
raise
|
373
374
|
else
|
374
375
|
Chef::Log.warn(machine_msg(
|
375
376
|
machine_spec.name,
|
376
377
|
vm.config.instanceUuid,
|
377
|
-
|
378
|
+
'started but SSH did not come up. Rebooting...'
|
378
379
|
))
|
379
380
|
restart_server(action_handler, machine_spec, machine_options)
|
380
381
|
wait_until_ready(action_handler, machine_spec, machine_options, vm)
|
@@ -391,18 +392,18 @@ module ChefProvisioningVsphere
|
|
391
392
|
# @param [Object] machine_spec The spec required to talk to the VM.
|
392
393
|
def attempt_ip(machine_options, action_handler, vm, machine_spec)
|
393
394
|
vm_ip = ip_to_bootstrap(machine_options[:bootstrap_options], vm)
|
394
|
-
machine_spec.location[
|
395
|
+
machine_spec.location['ipaddress'] = vm_ip
|
395
396
|
|
396
397
|
wait_for_ip(vm, machine_options, machine_spec, action_handler)
|
397
398
|
|
398
399
|
unless has_ip?(vm_ip, vm)
|
399
|
-
action_handler.report_progress
|
400
|
-
if vm.guest.toolsRunningStatus !=
|
401
|
-
msg =
|
400
|
+
action_handler.report_progress 'rebooting...'
|
401
|
+
if vm.guest.toolsRunningStatus != 'guestToolsRunning'
|
402
|
+
msg = 'tools have stopped. current power state is '
|
402
403
|
msg << vm.runtime.powerState
|
403
|
-
msg <<
|
404
|
+
msg << ' and tools state is '
|
404
405
|
msg << vm.guest.toolsRunningStatus
|
405
|
-
msg <<
|
406
|
+
msg << '. powering up server...'
|
406
407
|
action_handler.report_progress(msg)
|
407
408
|
vsphere_helper.start_vm(vm)
|
408
409
|
else
|
@@ -433,7 +434,7 @@ module ChefProvisioningVsphere
|
|
433
434
|
|
434
435
|
return unless domain
|
435
436
|
|
436
|
-
if is_windows?(vm) && domain !=
|
437
|
+
if is_windows?(vm) && domain != 'local'
|
437
438
|
start = Time.now.utc
|
438
439
|
trimmed_name = machine_spec.name.byteslice(0, 15)
|
439
440
|
expected_name = "#{trimmed_name}.#{domain}"
|
@@ -441,8 +442,8 @@ module ChefProvisioningVsphere
|
|
441
442
|
"waiting to domain join and be named #{expected_name}"
|
442
443
|
)
|
443
444
|
until (Time.now.utc - start) > 30 ||
|
444
|
-
|
445
|
-
print
|
445
|
+
(vm.guest.hostName == expected_name)
|
446
|
+
print '.'
|
446
447
|
sleep 5
|
447
448
|
end
|
448
449
|
end
|
@@ -459,12 +460,12 @@ module ChefProvisioningVsphere
|
|
459
460
|
ip_to_bootstrap(bootstrap_options, vm)
|
460
461
|
ready_timeout = machine_options[:ready_timeout] || 300
|
461
462
|
msg1 = "waiting up to #{ready_timeout} seconds for customization"
|
462
|
-
msg2 = " and find #{machine_spec.location[
|
463
|
+
msg2 = " and find #{machine_spec.location['ipaddress']}" unless machine_spec.location['ipaddress'].nil? # unless vm_ip == vm.guest.ipAddress # RuntimeError: can't modify frozen String
|
463
464
|
msg = [msg1, msg2].join
|
464
465
|
action_handler.report_progress msg
|
465
466
|
|
466
467
|
vm_ip = ip_to_bootstrap(bootstrap_options, vm) || vm.guest.ipAddress
|
467
|
-
machine_spec.location[
|
468
|
+
machine_spec.location['ipaddress'] = vm_ip
|
468
469
|
until transport_for(
|
469
470
|
machine_spec,
|
470
471
|
machine_options[:bootstrap_options][:ssh],
|
@@ -474,7 +475,7 @@ module ChefProvisioningVsphere
|
|
474
475
|
"IP addresses found: #{all_ips_for(vm)}"
|
475
476
|
)
|
476
477
|
vm_ip = ip_to_bootstrap(bootstrap_options, vm) || vm.guest.ipAddress
|
477
|
-
machine_spec.location[
|
478
|
+
machine_spec.location['ipaddress'] = vm_ip
|
478
479
|
if has_ip?(vm_ip, vm)
|
479
480
|
transport_for(
|
480
481
|
machine_spec,
|
@@ -526,7 +527,7 @@ module ChefProvisioningVsphere
|
|
526
527
|
vsphere_helper.stop_vm(vm, machine_options[:stop_timeout])
|
527
528
|
vm.Destroy_Task.wait_for_completion
|
528
529
|
rescue RbVmomi::Fault => fault
|
529
|
-
raise fault unless fault.fault.class.wsdl_name ==
|
530
|
+
raise fault unless fault.fault.class.wsdl_name == 'ManagedObjectNotFound'
|
530
531
|
ensure
|
531
532
|
machine_spec.location = nil
|
532
533
|
end
|
@@ -578,7 +579,7 @@ module ChefProvisioningVsphere
|
|
578
579
|
action_handler.perform_action "restart machine #{machine_spec.name} (#{driver_url})" do
|
579
580
|
stop_machine(action_handler, machine_spec, machine_options)
|
580
581
|
start_machine(action_handler, machine_spec, machine_options)
|
581
|
-
machine_spec.location[
|
582
|
+
machine_spec.location['started_at'] = Time.now.utc.to_s
|
582
583
|
end
|
583
584
|
end
|
584
585
|
|
@@ -590,24 +591,24 @@ module ChefProvisioningVsphere
|
|
590
591
|
# @param [Object] _machine_spec The machine spec required to start the VM.
|
591
592
|
# @param [Object] machine Machine object to connect to.
|
592
593
|
def setup_ubuntu_dns(machine, bootstrap_options, _machine_spec)
|
593
|
-
host_lookup = machine.execute_always(
|
594
|
+
host_lookup = machine.execute_always('host google.com')
|
594
595
|
if host_lookup.exitstatus != 0
|
595
|
-
if host_lookup.stdout.include?(
|
596
|
-
machine.execute_always(
|
596
|
+
if host_lookup.stdout.include?('setlocale: LC_ALL')
|
597
|
+
machine.execute_always('locale-gen en_US && update-locale LANG=en_US')
|
597
598
|
end
|
598
599
|
distro = machine.execute_always("lsb_release -i | sed -e 's/Distributor ID://g'").stdout.strip
|
599
600
|
Chef::Log.info "Found distro:#{distro}"
|
600
|
-
if distro ==
|
601
|
-
distro_version = machine.execute_always(
|
601
|
+
if distro == 'Ubuntu'
|
602
|
+
distro_version = machine.execute_always('lsb_release -r | sed -e s/[^0-9.]//g').stdout.strip.to_f
|
602
603
|
Chef::Log.info "Found distro version:#{distro_version}"
|
603
604
|
if distro_version >= 12.04
|
604
|
-
Chef::Log.info
|
605
|
-
interfaces_file =
|
606
|
-
nameservers = bootstrap_options[:customization_spec][:ipsettings][:dnsServerList].join(
|
605
|
+
Chef::Log.info 'Ubuntu version 12.04 or greater. Need to patch DNS.'
|
606
|
+
interfaces_file = '/etc/network/interfaces'
|
607
|
+
nameservers = bootstrap_options[:customization_spec][:ipsettings][:dnsServerList].join(' ')
|
607
608
|
machine.execute_always("if ! cat #{interfaces_file} | grep -q dns-search ; then echo 'dns-search #{bootstrap_options[:customization_spec][:domain]}' >> #{interfaces_file} ; fi")
|
608
609
|
machine.execute_always("if ! cat #{interfaces_file} | grep -q dns-nameservers ; then echo 'dns-nameservers #{nameservers}' >> #{interfaces_file} ; fi")
|
609
|
-
machine.execute_always(
|
610
|
-
machine.execute_always(
|
610
|
+
machine.execute_always('/etc/init.d/networking restart')
|
611
|
+
machine.execute_always('apt-get -qq update')
|
611
612
|
end
|
612
613
|
end
|
613
614
|
end
|
@@ -632,22 +633,22 @@ module ChefProvisioningVsphere
|
|
632
633
|
end
|
633
634
|
|
634
635
|
def remaining_wait_time(machine_spec, machine_options)
|
635
|
-
if machine_spec.location[
|
636
|
+
if machine_spec.location['started_at']
|
636
637
|
(machine_options[:start_timeout] || 600) -
|
637
|
-
(Time.now.utc - Time.parse(machine_spec.location[
|
638
|
+
(Time.now.utc - Time.parse(machine_spec.location['started_at']))
|
638
639
|
else
|
639
640
|
(machine_options[:create_timeout] || 600) -
|
640
|
-
(Time.now.utc - Time.parse(machine_spec.location[
|
641
|
+
(Time.now.utc - Time.parse(machine_spec.location['allocated_at']))
|
641
642
|
end
|
642
643
|
end
|
643
644
|
|
644
645
|
def wait_until_ready(action_handler, machine_spec, machine_options, vm)
|
645
|
-
if vm.guest.toolsRunningStatus !=
|
646
|
+
if vm.guest.toolsRunningStatus != 'guestToolsRunning'
|
646
647
|
if action_handler.should_perform_actions
|
647
648
|
action_handler.report_progress "waiting for #{machine_spec.name} (#{vm.config.instanceUuid} on #{driver_url}) to be ready ..."
|
648
649
|
until remaining_wait_time(machine_spec, machine_options) < 0 ||
|
649
|
-
|
650
|
-
print
|
650
|
+
(vm.guest.toolsRunningStatus == 'guestToolsRunning' && vm.guest.ipAddress && !vm.guest.ipAddress.empty?)
|
651
|
+
print '.'
|
651
652
|
sleep 5
|
652
653
|
end
|
653
654
|
action_handler.report_progress "#{machine_spec.name} is now ready"
|
@@ -657,7 +658,7 @@ module ChefProvisioningVsphere
|
|
657
658
|
|
658
659
|
def vm_for(machine_spec)
|
659
660
|
if machine_spec.location
|
660
|
-
vsphere_helper.find_vm_by_id(machine_spec.location[
|
661
|
+
vsphere_helper.find_vm_by_id(machine_spec.location['server_id'])
|
661
662
|
end
|
662
663
|
end
|
663
664
|
|
@@ -686,7 +687,7 @@ module ChefProvisioningVsphere
|
|
686
687
|
size = size.to_i
|
687
688
|
next if size == 0
|
688
689
|
if bootstrap_options[:datastore].to_s.empty?
|
689
|
-
raise
|
690
|
+
raise ':datastore must be specified when adding a disk to a cloned vm'
|
690
691
|
end
|
691
692
|
task = vm.ReconfigVM_Task(
|
692
693
|
spec: RbVmomi::VIM.VirtualMachineConfigSpec(
|
@@ -695,7 +696,7 @@ module ChefProvisioningVsphere
|
|
695
696
|
vm,
|
696
697
|
bootstrap_options[:datastore],
|
697
698
|
size
|
698
|
-
)
|
699
|
+
)
|
699
700
|
]
|
700
701
|
)
|
701
702
|
)
|
@@ -730,7 +731,7 @@ module ChefProvisioningVsphere
|
|
730
731
|
)
|
731
732
|
strategy = convergence_strategy_for(machine_spec, machine_options)
|
732
733
|
|
733
|
-
if machine_spec.location[
|
734
|
+
if machine_spec.location['is_windows']
|
734
735
|
Chef::Provisioning::Machine::WindowsMachine.new(
|
735
736
|
machine_spec, transport, strategy
|
736
737
|
)
|
@@ -743,13 +744,13 @@ module ChefProvisioningVsphere
|
|
743
744
|
|
744
745
|
def is_windows?(vm)
|
745
746
|
return false if vm.nil?
|
746
|
-
vm.config.guestId.start_with?(
|
747
|
+
vm.config.guestId.start_with?('win')
|
747
748
|
end
|
748
749
|
|
749
750
|
def convergence_strategy_for(machine_spec, machine_options)
|
750
|
-
require
|
751
|
-
require
|
752
|
-
require
|
751
|
+
require 'chef/provisioning/convergence_strategy/install_msi'
|
752
|
+
require 'chef/provisioning/convergence_strategy/install_cached'
|
753
|
+
require 'chef/provisioning/convergence_strategy/no_converge'
|
753
754
|
|
754
755
|
mopts = machine_options[:convergence_options].to_hash.dup
|
755
756
|
if mopts[:chef_server]
|
@@ -763,7 +764,7 @@ module ChefProvisioningVsphere
|
|
763
764
|
)
|
764
765
|
end
|
765
766
|
|
766
|
-
if machine_spec.location[
|
767
|
+
if machine_spec.location['is_windows']
|
767
768
|
Chef::Provisioning::ConvergenceStrategy::InstallMsi.new(
|
768
769
|
mopts, config
|
769
770
|
)
|
@@ -791,7 +792,7 @@ module ChefProvisioningVsphere
|
|
791
792
|
action_handler.report_progress "waiting for #{machine_spec.name} (#{vm.config.instanceUuid} on #{driver_url}) to be connectable (transport up and running) ..."
|
792
793
|
|
793
794
|
until remaining_wait_time(machine_spec, machine_options) < 0 || transport.available?
|
794
|
-
print
|
795
|
+
print '.'
|
795
796
|
sleep 5
|
796
797
|
end
|
797
798
|
|
@@ -808,9 +809,9 @@ module ChefProvisioningVsphere
|
|
808
809
|
def transport_for(
|
809
810
|
machine_spec,
|
810
811
|
remoting_options,
|
811
|
-
ip = machine_spec.location[
|
812
|
+
ip = machine_spec.location['ipaddress']
|
812
813
|
)
|
813
|
-
if machine_spec.location[
|
814
|
+
if machine_spec.location['is_windows']
|
814
815
|
create_winrm_transport(ip, remoting_options)
|
815
816
|
else
|
816
817
|
create_ssh_transport(ip, remoting_options)
|
@@ -822,7 +823,7 @@ module ChefProvisioningVsphere
|
|
822
823
|
# @param [String] host The host the VM is connecting to
|
823
824
|
# @param [Object] options Options that are required to connect to the host from Chef-Provisioning
|
824
825
|
def create_winrm_transport(host, options)
|
825
|
-
require
|
826
|
+
require 'chef/provisioning/transport/winrm'
|
826
827
|
winrm_transport = if options[:port] == 5986
|
827
828
|
:ssl
|
828
829
|
else
|
@@ -831,7 +832,7 @@ module ChefProvisioningVsphere
|
|
831
832
|
port = options[:port] || @vm_helper.port
|
832
833
|
winrm_options = {
|
833
834
|
user: (options[:user]).to_s,
|
834
|
-
pass: options[:password]
|
835
|
+
pass: options[:password]
|
835
836
|
}
|
836
837
|
if options[:winrm_opts].nil?
|
837
838
|
opt = options[:user].include?('\\') ? :disable_sspi : :basic_auth_only
|
@@ -855,14 +856,14 @@ module ChefProvisioningVsphere
|
|
855
856
|
# @param [String] host The host the VM is connecting to
|
856
857
|
# @param [Object] options Options that are required to connect to the host from Chef-Provisioning
|
857
858
|
def create_ssh_transport(host, options)
|
858
|
-
require
|
859
|
+
require 'chef/provisioning/transport/ssh'
|
859
860
|
ssh_user = options[:user]
|
860
861
|
options = options.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v; }
|
861
862
|
Chef::Provisioning::Transport::SSH.new(
|
862
863
|
host,
|
863
864
|
ssh_user,
|
864
865
|
options.to_hash,
|
865
|
-
@config[:machine_options][:sudo] ? { prefix:
|
866
|
+
@config[:machine_options][:sudo] ? { prefix: 'sudo ' } : {},
|
866
867
|
config
|
867
868
|
)
|
868
869
|
end
|
@@ -881,7 +882,7 @@ module ChefProvisioningVsphere
|
|
881
882
|
else
|
882
883
|
## Check if true available
|
883
884
|
vm_ip = bootstrap_options[:customization_spec][:ipsettings][:ip] unless vm_helper.ip?
|
884
|
-
print
|
885
|
+
print '.' until @vm_helper.open_port?(vm_ip, @vm_helper.port, 1)
|
885
886
|
end
|
886
887
|
else
|
887
888
|
if use_ipv4_during_bootstrap?(bootstrap_options)
|
@@ -920,18 +921,18 @@ module ChefProvisioningVsphere
|
|
920
921
|
# @param [Object] vm The VM object from Chef-Provisioning
|
921
922
|
def wait_for_ipv4(timeout, vm)
|
922
923
|
sleep_time = 5
|
923
|
-
print
|
924
|
+
print 'Waiting for ipv4 address.'
|
924
925
|
tries = 0
|
925
926
|
start_search_ip = true
|
926
927
|
max_tries = timeout > sleep_time ? timeout / sleep_time : 1
|
927
928
|
while start_search_ip && (tries += 1) <= max_tries
|
928
|
-
print
|
929
|
+
print '.'
|
929
930
|
sleep sleep_time
|
930
931
|
vm_ip = vm.guest.ipAddress if vm_guest_ip?(vm)
|
931
932
|
start_search_ip = false if @vm_helper.open_port?(vm_ip, @vm_helper.port, 1)
|
932
933
|
end
|
933
|
-
raise
|
934
|
-
puts
|
934
|
+
raise 'Timed out waiting for ipv4 address!' if tries > max_tries
|
935
|
+
puts 'Found ipv4 address!'
|
935
936
|
true
|
936
937
|
end
|
937
938
|
|
@@ -939,7 +940,7 @@ module ChefProvisioningVsphere
|
|
939
940
|
#
|
940
941
|
# @param [Object] vm The VM object from Chef-Provisioning
|
941
942
|
def vm_guest_ip?(vm)
|
942
|
-
vm.guest.guestState ==
|
943
|
+
vm.guest.guestState == 'running' && vm.guest.toolsRunningStatus == 'guestToolsRunning' && !vm.guest.ipAddress.nil? && IPAddr.new(vm.guest.ipAddress).ipv4?
|
943
944
|
end
|
944
945
|
end
|
945
946
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require 'chef/provisioning/driver'
|
3
4
|
|
4
5
|
# Provisions machines in vSphere.
|
5
6
|
module ChefProvisioningVsphere
|
@@ -36,16 +37,16 @@ module ChefProvisioningVsphere
|
|
36
37
|
def find_port?(vm, options)
|
37
38
|
@port = options[:ssh][:port]
|
38
39
|
customization_spec = options[:customization_spec]
|
39
|
-
if vm.config.guestId.start_with?(
|
40
|
+
if vm.config.guestId.start_with?('win')
|
40
41
|
if customization_spec.is_a?(Hash)
|
41
42
|
winrm_transport =
|
42
43
|
customization_spec[:winrm_transport].nil? ? :negotiate : customization_spec[:winrm_transport].to_sym
|
43
44
|
end
|
44
45
|
winrm_transport ||= :negotiate
|
45
|
-
default_win_port = winrm_transport == :ssl ?
|
46
|
+
default_win_port = winrm_transport == :ssl ? '5986' : '5985'
|
46
47
|
@port = default_win_port if @port.nil?
|
47
48
|
elsif port.nil?
|
48
|
-
@port =
|
49
|
+
@port = '22'
|
49
50
|
end
|
50
51
|
true
|
51
52
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
2
|
+
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
5
6
|
|
6
7
|
# Provisions machines in vSphere.
|
7
8
|
module ChefProvisioningVsphere
|
@@ -70,7 +71,7 @@ module ChefProvisioningVsphere
|
|
70
71
|
# @param [Object] _wait_on_port Defaults to port 22, to connect and verify it's up.
|
71
72
|
def start_vm(vm, _wait_on_port = 22)
|
72
73
|
state = vm.runtime.powerState
|
73
|
-
vm.PowerOnVM_Task.wait_for_completion unless state ==
|
74
|
+
vm.PowerOnVM_Task.wait_for_completion unless state == 'poweredOn'
|
74
75
|
end
|
75
76
|
|
76
77
|
# Stops the VM
|
@@ -79,12 +80,12 @@ module ChefProvisioningVsphere
|
|
79
80
|
# @param [Object] timeout Defaults to 600 seconds or 10 mins before giving up.
|
80
81
|
def stop_vm(vm, timeout = 600)
|
81
82
|
start = Time.now.utc
|
82
|
-
return if vm.runtime.powerState ==
|
83
|
+
return if vm.runtime.powerState == 'poweredOff'
|
83
84
|
begin
|
84
85
|
vm.ShutdownGuest
|
85
86
|
until (Time.now.utc - start) > timeout ||
|
86
|
-
|
87
|
-
print
|
87
|
+
vm.runtime.powerState == 'poweredOff'
|
88
|
+
print '.'
|
88
89
|
sleep 2
|
89
90
|
end
|
90
91
|
rescue
|
@@ -99,9 +100,9 @@ module ChefProvisioningVsphere
|
|
99
100
|
def find_folder(folder_name)
|
100
101
|
base = datacenter.vmFolder
|
101
102
|
unless folder_name.nil?
|
102
|
-
folder_name.split(
|
103
|
+
folder_name.split('/').reject(&:empty?).each do |item|
|
103
104
|
base = base.find(item, RbVmomi::VIM::Folder) ||
|
104
|
-
|
105
|
+
raise("vSphere Folder not found [#{folder_name}]")
|
105
106
|
end
|
106
107
|
end
|
107
108
|
base
|
@@ -151,7 +152,7 @@ module ChefProvisioningVsphere
|
|
151
152
|
)
|
152
153
|
device = RbVmomi::VIM::VirtualVmxnet3(
|
153
154
|
backing: backing_info,
|
154
|
-
deviceInfo: RbVmomi::VIM::Description(label: network_label, summary: network_name.split(
|
155
|
+
deviceInfo: RbVmomi::VIM::Description(label: network_label, summary: network_name.split('/').last),
|
155
156
|
key: device_key,
|
156
157
|
connectable: connectable
|
157
158
|
)
|
@@ -179,10 +180,10 @@ module ChefProvisioningVsphere
|
|
179
180
|
|
180
181
|
if deviceAdditions.count > 0
|
181
182
|
current_networks = find_ethernet_cards_for(vm).map { |card| network_id_for(card.backing) }
|
182
|
-
new_devices = deviceAdditions.
|
183
|
+
new_devices = deviceAdditions.reject { |device| current_networks.include?(network_id_for(device.device.backing)) }
|
183
184
|
|
184
185
|
if new_devices.count > 0
|
185
|
-
action_handler.report_progress
|
186
|
+
action_handler.report_progress 'Adding extra NICs'
|
186
187
|
task = vm.ReconfigVM_Task(spec: RbVmomi::VIM.VirtualMachineConfigSpec(deviceChange: new_devices))
|
187
188
|
task.wait_for_completion
|
188
189
|
new_devices
|
@@ -211,7 +212,7 @@ module ChefProvisioningVsphere
|
|
211
212
|
deviceChange: [
|
212
213
|
{
|
213
214
|
operation: :remove,
|
214
|
-
device: disk
|
215
|
+
device: disk
|
215
216
|
},
|
216
217
|
{
|
217
218
|
operation: :add,
|
@@ -220,9 +221,9 @@ module ChefProvisioningVsphere
|
|
220
221
|
new_disk.backing = new_disk.backing.dup
|
221
222
|
new_disk.backing.fileName = "[#{disk.backing.datastore.name}]"
|
222
223
|
new_disk.backing.parent = disk.backing
|
223
|
-
end
|
224
|
-
}
|
225
|
-
]
|
224
|
+
end
|
225
|
+
}
|
226
|
+
]
|
226
227
|
}
|
227
228
|
vm_template.ReconfigVM_Task(spec: spec).wait_for_completion
|
228
229
|
end
|
@@ -242,7 +243,7 @@ module ChefProvisioningVsphere
|
|
242
243
|
key: idx,
|
243
244
|
backing: RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
|
244
245
|
fileName: "[#{datastore}]",
|
245
|
-
diskMode:
|
246
|
+
diskMode: 'persistent',
|
246
247
|
thinProvisioned: true
|
247
248
|
),
|
248
249
|
capacityInKB: size_gb * 1024 * 1024,
|
@@ -271,14 +272,14 @@ module ChefProvisioningVsphere
|
|
271
272
|
backing_info = backing_info_for(action_handler, networks[i])
|
272
273
|
if card = cards.shift
|
273
274
|
key = card.key
|
274
|
-
operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation(
|
275
|
+
operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('edit')
|
275
276
|
action_handler.report_progress "changing template nic for #{networks[i]}"
|
276
277
|
changes.push(
|
277
278
|
network_adapter_for(operation, networks[i], label, key, backing_info)
|
278
279
|
)
|
279
280
|
else
|
280
281
|
key += 1
|
281
|
-
operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation(
|
282
|
+
operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('add')
|
282
283
|
action_handler.report_progress "will be adding nic for #{networks[i]}"
|
283
284
|
additions.push(
|
284
285
|
network_adapter_for(operation, networks[i], label, key, backing_info)
|
@@ -293,7 +294,7 @@ module ChefProvisioningVsphere
|
|
293
294
|
# @param [Object] action_handler TODO
|
294
295
|
# @param [String] network_name The network name to attach to
|
295
296
|
def backing_info_for(action_handler, network_name)
|
296
|
-
action_handler.report_progress(
|
297
|
+
action_handler.report_progress('finding networks...')
|
297
298
|
network = find_network(network_name)
|
298
299
|
action_handler.report_progress(
|
299
300
|
"network: #{network_name} is a #{network.class}"
|
@@ -308,7 +309,7 @@ module ChefProvisioningVsphere
|
|
308
309
|
)
|
309
310
|
else
|
310
311
|
RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(
|
311
|
-
deviceName: network_name.split(
|
312
|
+
deviceName: network_name.split('/').last
|
312
313
|
)
|
313
314
|
end
|
314
315
|
end
|
@@ -325,11 +326,11 @@ module ChefProvisioningVsphere
|
|
325
326
|
# @param [String] name The name of the "thing."
|
326
327
|
# @param [String] parent_folder The name of the folder to start from.
|
327
328
|
def find_entity(name, parent_folder)
|
328
|
-
parts = name.split(
|
329
|
+
parts = name.split('/').reject(&:empty?)
|
329
330
|
parts.each do |item|
|
330
331
|
Chef::Log.debug("Identifying entity part: #{item} in folder type: #{parent_folder.class}")
|
331
332
|
if parent_folder.is_a? RbVmomi::VIM::Folder
|
332
|
-
Chef::Log.debug(
|
333
|
+
Chef::Log.debug('Parent folder is a folder')
|
333
334
|
parent_folder = parent_folder.childEntity.find { |f| f.name == item }
|
334
335
|
else
|
335
336
|
parent_folder = yield(parent_folder, item)
|
@@ -393,7 +394,7 @@ module ChefProvisioningVsphere
|
|
393
394
|
# @param [String] name Name of the Network.
|
394
395
|
def find_network(name)
|
395
396
|
base = datacenter.networkFolder
|
396
|
-
entity_array = name.split(
|
397
|
+
entity_array = name.split('/').reject(&:empty?)
|
397
398
|
entity_array.each do |item|
|
398
399
|
case base
|
399
400
|
when RbVmomi::VIM::Folder
|
@@ -446,8 +447,8 @@ module ChefProvisioningVsphere
|
|
446
447
|
|
447
448
|
req = Net::HTTP::Put.new("#{uri.path}?#{uri.query}")
|
448
449
|
req.body_stream = File.open(local)
|
449
|
-
req[
|
450
|
-
req[
|
450
|
+
req['Content-Type'] = 'application/octet-stream'
|
451
|
+
req['Content-Length'] = size
|
451
452
|
res = http.request(req)
|
452
453
|
unless res.is_a?(Net::HTTPSuccess)
|
453
454
|
raise "Error: #{res.inspect} :: #{res.body} :: sending #{local} to #{remote} at #{vm.name} via #{endpoint} with a size of #{size}"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
-
|
2
|
+
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
# The main URI Module
|
5
6
|
module URI
|
@@ -8,20 +9,20 @@ module URI
|
|
8
9
|
# Default port for connecting to the vSphere cluster Webserver
|
9
10
|
DEFAULT_PORT = 443
|
10
11
|
# Default path for connecting to the vSphere cluster URL
|
11
|
-
DEFAULT_PATH =
|
12
|
+
DEFAULT_PATH = '/sdk'.freeze
|
12
13
|
|
13
14
|
# Creates the URL from options that are decided
|
14
15
|
#
|
15
16
|
def self.from_config(options)
|
16
17
|
parts = []
|
17
|
-
parts <<
|
18
|
+
parts << 'vsphere://'
|
18
19
|
parts << options[:host]
|
19
|
-
parts <<
|
20
|
+
parts << ':'
|
20
21
|
parts << (options[:port] || DEFAULT_PORT)
|
21
22
|
parts << (options[:path] || DEFAULT_PATH)
|
22
|
-
parts <<
|
23
|
+
parts << '?use_ssl='
|
23
24
|
parts << (options[:use_ssl] == false ? false : true)
|
24
|
-
parts <<
|
25
|
+
parts << '&insecure='
|
25
26
|
parts << (options[:insecure] || false)
|
26
27
|
URI parts.join
|
27
28
|
end
|
@@ -30,10 +31,10 @@ module URI
|
|
30
31
|
#
|
31
32
|
def use_ssl
|
32
33
|
if query
|
33
|
-
ssl_query = query.split(
|
34
|
-
q.start_with?(
|
34
|
+
ssl_query = query.split('&').each.select do |q|
|
35
|
+
q.start_with?('use_ssl=')
|
35
36
|
end.first
|
36
|
-
ssl_query ==
|
37
|
+
ssl_query == 'use_ssl=true'
|
37
38
|
else
|
38
39
|
true
|
39
40
|
end
|
@@ -43,14 +44,14 @@ module URI
|
|
43
44
|
#
|
44
45
|
def insecure
|
45
46
|
if query
|
46
|
-
insecure_query = query.split(
|
47
|
-
q.start_with?(
|
47
|
+
insecure_query = query.split('&').each.select do |q|
|
48
|
+
q.start_with?('insecure=')
|
48
49
|
end.first
|
49
|
-
insecure_query ==
|
50
|
+
insecure_query == 'insecure=true'
|
50
51
|
else
|
51
52
|
false
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
|
-
@@schemes[
|
56
|
+
@@schemes['VSPHERE'] = VsphereUrl
|
56
57
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'kitchen'
|
5
|
+
require 'chef/provisioning/vsphere_driver'
|
6
|
+
require 'chef/provisioning/machine_spec'
|
6
7
|
|
7
8
|
# Main Kitchen Module
|
8
9
|
module Kitchen
|
@@ -20,14 +21,14 @@ module Kitchen
|
|
20
21
|
bootstrap_options: {
|
21
22
|
use_linked_clone: true,
|
22
23
|
ssh: {
|
23
|
-
user:
|
24
|
+
user: 'root',
|
24
25
|
paranoid: false,
|
25
|
-
port: 22
|
26
|
+
port: 22
|
26
27
|
},
|
27
28
|
convergence_options: {},
|
28
29
|
customization_spec: {
|
29
|
-
domain:
|
30
|
-
}
|
30
|
+
domain: 'local'
|
31
|
+
}
|
31
32
|
}
|
32
33
|
|
33
34
|
default_config(:vsphere_name) do |driver|
|
@@ -46,8 +47,8 @@ module Kitchen
|
|
46
47
|
machine = with_provisioning_driver(state) do |action_handler, driver, machine_spec|
|
47
48
|
driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
|
48
49
|
driver.ready_machine(action_handler, machine_spec, config[:machine_options])
|
49
|
-
state[:server_id] = machine_spec.location[
|
50
|
-
state[:hostname] = machine_spec.location[
|
50
|
+
state[:server_id] = machine_spec.location['server_id']
|
51
|
+
state[:hostname] = machine_spec.location['ipaddress']
|
51
52
|
machine_spec.save(action_handler)
|
52
53
|
end
|
53
54
|
end
|
@@ -59,8 +60,8 @@ module Kitchen
|
|
59
60
|
return if state[:server_id].nil?
|
60
61
|
|
61
62
|
with_provisioning_driver(state) do |action_handler, driver, machine_spec|
|
62
|
-
machine_spec.location = {
|
63
|
-
|
63
|
+
machine_spec.location = { 'driver_url' => driver.driver_url,
|
64
|
+
'server_id' => state[:server_id] }
|
64
65
|
driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
|
65
66
|
end
|
66
67
|
|
@@ -93,7 +94,7 @@ module Kitchen
|
|
93
94
|
unless @@chef_zero_server
|
94
95
|
Chef::Config.local_mode = true
|
95
96
|
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
|
96
|
-
require
|
97
|
+
require 'chef/local_mode'
|
97
98
|
Chef::LocalMode.setup_server_connectivity
|
98
99
|
@@chef_zero_server = true
|
99
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-provisioning-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CenturyLink Cloud
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-10-
|
12
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|