chef-provisioning-vsphere 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +22 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- data/.gitignore +3 -1
- data/.travis.yml +7 -0
- data/CHANGELOG.md +17 -2
- data/Gemfile +1 -1
- data/README.md +5 -1
- data/Rakefile +20 -13
- data/chef-provisioning-vsphere.gemspec +26 -26
- data/lib/chef/provisioning/driver_init/vsphere.rb +2 -2
- data/lib/chef/provisioning/vsphere_driver.rb +9 -2
- data/lib/chef/provisioning/vsphere_driver/clone_spec_builder.rb +37 -13
- data/lib/chef/provisioning/vsphere_driver/driver.rb +233 -86
- data/lib/chef/provisioning/vsphere_driver/version.rb +3 -1
- data/lib/chef/provisioning/vsphere_driver/vm_helper.rb +22 -5
- data/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb +118 -26
- data/lib/chef/provisioning/vsphere_driver/vsphere_url.rb +23 -13
- data/lib/kitchen/driver/vsphere.rb +29 -13
- data/spec/spec_helper.rb +19 -0
- metadata +34 -2
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
require "json"
|
3
|
+
require "kitchen"
|
4
|
+
require "chef/provisioning/vsphere_driver"
|
5
|
+
require "chef/provisioning/machine_spec"
|
6
6
|
|
7
|
+
# Main Kitchen Module
|
7
8
|
module Kitchen
|
9
|
+
# Main Kitchen::Driver Module
|
8
10
|
module Driver
|
11
|
+
# vSphere kitchen class extends the Kitchen::Driver::Base
|
9
12
|
class Vsphere < Kitchen::Driver::Base
|
10
13
|
@@chef_zero_server = false
|
11
14
|
|
@@ -17,20 +20,23 @@ module Kitchen
|
|
17
20
|
bootstrap_options: {
|
18
21
|
use_linked_clone: true,
|
19
22
|
ssh: {
|
20
|
-
user:
|
23
|
+
user: "root",
|
21
24
|
paranoid: false,
|
22
|
-
port: 22
|
25
|
+
port: 22,
|
23
26
|
},
|
24
27
|
convergence_options: {},
|
25
28
|
customization_spec: {
|
26
|
-
domain:
|
27
|
-
}
|
29
|
+
domain: "local",
|
30
|
+
},
|
28
31
|
}
|
29
32
|
|
30
33
|
default_config(:vsphere_name) do |driver|
|
31
34
|
"#{driver.instance.name}-#{SecureRandom.hex(4)}"
|
32
35
|
end
|
33
36
|
|
37
|
+
# Creates VM on the vSphere cluster
|
38
|
+
#
|
39
|
+
# @param [Object] state Uses state of the machine from Chef provisioning.
|
34
40
|
def create(state)
|
35
41
|
state[:vsphere_name] = config[:vsphere_name]
|
36
42
|
state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
|
@@ -40,18 +46,21 @@ module Kitchen
|
|
40
46
|
machine = with_provisioning_driver(state) do |action_handler, driver, machine_spec|
|
41
47
|
driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
|
42
48
|
driver.ready_machine(action_handler, machine_spec, config[:machine_options])
|
43
|
-
state[:server_id] = machine_spec.location[
|
44
|
-
state[:hostname] = machine_spec.location[
|
49
|
+
state[:server_id] = machine_spec.location["server_id"]
|
50
|
+
state[:hostname] = machine_spec.location["ipaddress"]
|
45
51
|
machine_spec.save(action_handler)
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
55
|
+
# Destroys VM on the vSphere cluster
|
56
|
+
#
|
57
|
+
# @param [Object] state Uses state of the machine from Chef provisioning.
|
49
58
|
def destroy(state)
|
50
59
|
return if state[:server_id].nil?
|
51
60
|
|
52
61
|
with_provisioning_driver(state) do |action_handler, driver, machine_spec|
|
53
|
-
machine_spec.location = {
|
54
|
-
|
62
|
+
machine_spec.location = { "driver_url" => driver.driver_url,
|
63
|
+
"server_id" => state[:server_id] }
|
55
64
|
driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
|
56
65
|
end
|
57
66
|
|
@@ -60,6 +69,9 @@ module Kitchen
|
|
60
69
|
state.delete(:vsphere_name)
|
61
70
|
end
|
62
71
|
|
72
|
+
# Leverages the chef provisioning driver options
|
73
|
+
#
|
74
|
+
# @param [Object] state Uses state of the machine from Chef provisioning.
|
63
75
|
def with_provisioning_driver(state)
|
64
76
|
config[:machine_options][:convergence_options] = { chef_server: chef_server }
|
65
77
|
machine_spec = Chef::Provisioning.chef_managed_entry_store(chef_server).get(:machine, state[:vsphere_name])
|
@@ -73,13 +85,15 @@ module Kitchen
|
|
73
85
|
yield(action_handler, driver, machine_spec)
|
74
86
|
end
|
75
87
|
|
88
|
+
# Uses either a remote Chef server or Chef Zero
|
89
|
+
#
|
76
90
|
def chef_server
|
77
91
|
unless @@chef_zero_server
|
78
92
|
vsphere_mutex.synchronize do
|
79
93
|
unless @@chef_zero_server
|
80
94
|
Chef::Config.local_mode = true
|
81
95
|
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
|
82
|
-
require
|
96
|
+
require "chef/local_mode"
|
83
97
|
Chef::LocalMode.setup_server_connectivity
|
84
98
|
@@chef_zero_server = true
|
85
99
|
end
|
@@ -89,6 +103,8 @@ module Kitchen
|
|
89
103
|
Cheffish.default_chef_server
|
90
104
|
end
|
91
105
|
|
106
|
+
# Creates a new mutex object for Kitchen
|
107
|
+
#
|
92
108
|
def vsphere_mutex
|
93
109
|
@@vsphere_mutex ||= begin
|
94
110
|
Kitchen.mutex.synchronize do
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
# add_filter do |source_file|
|
5
|
+
# # source_file.lines.count < 5
|
6
|
+
# source.filename =~ /^#{SimpleCov.root}\/chef-provisioning-fake/)
|
7
|
+
# end
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
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.3
|
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-05-
|
12
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rbvmomi
|
@@ -191,6 +191,34 @@ dependencies:
|
|
191
191
|
- - ">="
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
|
+
- !ruby/object:Gem::Dependency
|
195
|
+
name: simplecov
|
196
|
+
requirement: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
type: :development
|
202
|
+
prerelease: false
|
203
|
+
version_requirements: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
- !ruby/object:Gem::Dependency
|
209
|
+
name: yard
|
210
|
+
requirement: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
type: :development
|
216
|
+
prerelease: false
|
217
|
+
version_requirements: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
194
222
|
description: Provisioner for creating vSphere VM instances in Chef Provisioning.
|
195
223
|
email: jj@chef.io
|
196
224
|
executables: []
|
@@ -198,6 +226,8 @@ extensions: []
|
|
198
226
|
extra_rdoc_files:
|
199
227
|
- README.md
|
200
228
|
files:
|
229
|
+
- ".github/ISSUE_TEMPLATE.md"
|
230
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
201
231
|
- ".gitignore"
|
202
232
|
- ".rubocop.yml"
|
203
233
|
- ".rubocop_todo.yml"
|
@@ -221,6 +251,7 @@ files:
|
|
221
251
|
- lib/kitchen/driver/vsphere.rb
|
222
252
|
- spec/integration_tests/.gitignore
|
223
253
|
- spec/integration_tests/vsphere_driver_spec.rb
|
254
|
+
- spec/spec_helper.rb
|
224
255
|
- spec/unit_tests/VsphereDriver_spec.rb
|
225
256
|
- spec/unit_tests/VsphereUrl_spec.rb
|
226
257
|
- spec/unit_tests/clone_spec_builder_spec.rb
|
@@ -253,6 +284,7 @@ summary: Provisioner for creating vSphere VM instances in Chef Provisioning.
|
|
253
284
|
test_files:
|
254
285
|
- spec/integration_tests/.gitignore
|
255
286
|
- spec/integration_tests/vsphere_driver_spec.rb
|
287
|
+
- spec/spec_helper.rb
|
256
288
|
- spec/unit_tests/VsphereDriver_spec.rb
|
257
289
|
- spec/unit_tests/VsphereUrl_spec.rb
|
258
290
|
- spec/unit_tests/clone_spec_builder_spec.rb
|