vagrant-vsphere 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.bumpversion.cfg +1 -1
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +37 -0
- data/CHANGELOG.md +189 -0
- data/DEVELOPMENT.md +67 -0
- data/Gemfile +2 -3
- data/README.md +86 -175
- data/Rakefile +4 -1
- data/lib/vSphere/action.rb +22 -28
- data/lib/vSphere/action/clone.rb +46 -46
- data/lib/vSphere/action/close_vsphere.rb +8 -10
- data/lib/vSphere/action/connect_vsphere.rb +6 -6
- data/lib/vSphere/action/destroy.rb +6 -6
- data/lib/vSphere/action/get_ssh_info.rb +4 -5
- data/lib/vSphere/action/get_state.rb +3 -5
- data/lib/vSphere/action/is_created.rb +2 -2
- data/lib/vSphere/action/is_running.rb +2 -2
- data/lib/vSphere/action/message_already_created.rb +2 -2
- data/lib/vSphere/action/message_not_created.rb +1 -1
- data/lib/vSphere/action/message_not_running.rb +1 -1
- data/lib/vSphere/action/power_off.rb +2 -2
- data/lib/vSphere/action/power_on.rb +4 -4
- data/lib/vSphere/config.rb +2 -2
- data/lib/vSphere/plugin.rb +5 -6
- data/lib/vSphere/provider.rb +1 -1
- data/lib/vSphere/util/machine_helpers.rb +6 -6
- data/lib/vSphere/util/vim_helpers.rb +27 -23
- data/lib/vSphere/util/vm_helpers.rb +1 -2
- data/lib/vSphere/version.rb +1 -1
- data/lib/vagrant-vsphere.rb +1 -1
- data/spec/action_spec.rb +1 -0
- data/spec/clone_spec.rb +40 -42
- data/spec/connect_vsphere_spec.rb +8 -8
- data/spec/get_ssh_info_spec.rb +2 -2
- data/spec/spec_helper.rb +59 -63
- data/vSphere.gemspec +5 -4
- metadata +19 -1
@@ -9,7 +9,7 @@ module VagrantPlugins
|
|
9
9
|
include Util::VimHelpers
|
10
10
|
include Util::VmHelpers
|
11
11
|
|
12
|
-
def initialize(app,
|
12
|
+
def initialize(app, _env)
|
13
13
|
@app = app
|
14
14
|
end
|
15
15
|
|
@@ -26,9 +26,7 @@ module VagrantPlugins
|
|
26
26
|
|
27
27
|
vm = get_vm_by_uuid connection, machine
|
28
28
|
|
29
|
-
if vm.nil?
|
30
|
-
return :not_created
|
31
|
-
end
|
29
|
+
return :not_created if vm.nil?
|
32
30
|
|
33
31
|
if powered_on?(vm)
|
34
32
|
:running
|
@@ -40,4 +38,4 @@ module VagrantPlugins
|
|
40
38
|
end
|
41
39
|
end
|
42
40
|
end
|
43
|
-
end
|
41
|
+
end
|
@@ -12,7 +12,7 @@ module VagrantPlugins
|
|
12
12
|
include Util::VmHelpers
|
13
13
|
include Util::MachineHelpers
|
14
14
|
|
15
|
-
def initialize(app,
|
15
|
+
def initialize(app, _env)
|
16
16
|
@app = app
|
17
17
|
end
|
18
18
|
|
@@ -21,10 +21,10 @@ module VagrantPlugins
|
|
21
21
|
|
22
22
|
env[:ui].info I18n.t('vsphere.power_on_vm')
|
23
23
|
power_on_vm(vm)
|
24
|
-
|
25
|
-
# wait for SSH to be available
|
24
|
+
|
25
|
+
# wait for SSH to be available
|
26
26
|
wait_for_ssh env
|
27
|
-
|
27
|
+
|
28
28
|
@app.call env
|
29
29
|
end
|
30
30
|
end
|
data/lib/vSphere/config.rb
CHANGED
@@ -28,7 +28,7 @@ module VagrantPlugins
|
|
28
28
|
errors = _detected_errors
|
29
29
|
|
30
30
|
if password == :ask || password.nil?
|
31
|
-
self.password = machine.ui.ask(
|
31
|
+
self.password = machine.ui.ask('vSphere Password (will be hidden): ', echo: false)
|
32
32
|
end
|
33
33
|
|
34
34
|
# TODO: add blank?
|
@@ -38,7 +38,7 @@ module VagrantPlugins
|
|
38
38
|
errors << I18n.t('vsphere.config.template') if template_name.nil?
|
39
39
|
|
40
40
|
# Only required if we're cloning from an actual template
|
41
|
-
errors << I18n.t('vsphere.config.compute_resource') if compute_resource_name.nil?
|
41
|
+
errors << I18n.t('vsphere.config.compute_resource') if compute_resource_name.nil? && !clone_from_vm
|
42
42
|
|
43
43
|
{ 'vSphere Provider' => errors }
|
44
44
|
end
|
data/lib/vSphere/plugin.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require 'vagrant'
|
3
3
|
rescue LoadError
|
4
|
-
raise
|
4
|
+
raise 'The Vagrant vSphere plugin must be run within Vagrant.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# This is a sanity check to make sure no one is attempting to install
|
8
8
|
# this into an early Vagrant version.
|
9
|
-
if Vagrant::VERSION <
|
10
|
-
|
9
|
+
if Vagrant::VERSION < '1.5'
|
10
|
+
fail 'The Vagrant vSphere plugin is only compatible with Vagrant 1.5+'
|
11
11
|
end
|
12
12
|
|
13
13
|
module VagrantPlugins
|
@@ -30,11 +30,10 @@ module VagrantPlugins
|
|
30
30
|
Provider
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
33
|
def self.setup_i18n
|
35
34
|
I18n.load_path << File.expand_path('locales/en.yml', VSphere.source_root)
|
36
35
|
I18n.reload!
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
|
-
end
|
39
|
+
end
|
data/lib/vSphere/provider.rb
CHANGED
@@ -3,16 +3,16 @@ module VagrantPlugins
|
|
3
3
|
module Util
|
4
4
|
module MachineHelpers
|
5
5
|
def wait_for_ssh(env)
|
6
|
-
if
|
7
|
-
env[:ui].info(I18n.t(
|
6
|
+
if !env[:machine].config.vm.communicator.nil? && env[:machine].config.vm.communicator == :winrm
|
7
|
+
env[:ui].info(I18n.t('vsphere.waiting_for_winrm'))
|
8
8
|
else
|
9
|
-
env[:ui].info(I18n.t(
|
9
|
+
env[:ui].info(I18n.t('vsphere.waiting_for_ssh'))
|
10
10
|
end
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
loop do
|
13
13
|
break if env[:machine].communicate.ready?
|
14
14
|
sleep 5
|
15
|
-
end
|
15
|
+
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -5,7 +5,7 @@ module VagrantPlugins
|
|
5
5
|
module Util
|
6
6
|
module VimHelpers
|
7
7
|
def get_datacenter(connection, machine)
|
8
|
-
connection.serviceInstance.find_datacenter(machine.provider_config.data_center_name)
|
8
|
+
connection.serviceInstance.find_datacenter(machine.provider_config.data_center_name) || fail(Errors::VSphereError, :missing_datacenter)
|
9
9
|
end
|
10
10
|
|
11
11
|
def get_vm_by_uuid(connection, machine)
|
@@ -13,16 +13,18 @@ module VagrantPlugins
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def get_resource_pool(datacenter, machine)
|
16
|
-
|
17
|
-
rp =
|
18
|
-
|
19
|
-
rp =
|
16
|
+
compute_resource = get_compute_resource(datacenter, machine)
|
17
|
+
rp = compute_resource.resourcePool
|
18
|
+
unless machine.provider_config.resource_pool_name.nil?
|
19
|
+
rp = compute_resource.resourcePool.find(machine.provider_config.resource_pool_name)
|
20
|
+
fail Errors::VSphereError, :missing_resource_pool if rp.nil?
|
20
21
|
end
|
21
22
|
rp
|
22
23
|
end
|
23
24
|
|
24
25
|
def get_compute_resource(datacenter, machine)
|
25
|
-
cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name)
|
26
|
+
cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name)
|
27
|
+
fail Errors::VSphereError, :missing_compute_resource if cr.nil?
|
26
28
|
cr
|
27
29
|
end
|
28
30
|
|
@@ -36,50 +38,52 @@ module VagrantPlugins
|
|
36
38
|
end
|
37
39
|
return datacenter.hostFolder if es.empty?
|
38
40
|
final = es.pop
|
39
|
-
|
40
|
-
p = es.inject(datacenter.hostFolder) do |f,e|
|
41
|
+
|
42
|
+
p = es.inject(datacenter.hostFolder) do |f, e|
|
41
43
|
f.find(e, RbVmomi::VIM::Folder) || return
|
42
44
|
end
|
43
45
|
|
44
46
|
begin
|
45
|
-
if x = p.find(final, RbVmomi::VIM::ComputeResource)
|
47
|
+
if (x = p.find(final, RbVmomi::VIM::ComputeResource))
|
46
48
|
x
|
47
|
-
elsif x = p.find(final, RbVmomi::VIM::ClusterComputeResource)
|
49
|
+
elsif (x = p.find(final, RbVmomi::VIM::ClusterComputeResource))
|
48
50
|
x
|
49
|
-
else
|
50
|
-
nil
|
51
51
|
end
|
52
|
-
rescue Exception
|
53
|
-
# When looking for the ClusterComputeResource there seems to be some parser error in RbVmomi Folder.find, try this instead
|
54
|
-
x = p.childEntity.find { |
|
55
|
-
if x.is_a?
|
52
|
+
rescue Exception
|
53
|
+
# When looking for the ClusterComputeResource there seems to be some parser error in RbVmomi Folder.find, try this instead
|
54
|
+
x = p.childEntity.find { |x2| x2.name == final }
|
55
|
+
if x.is_a?(RbVmomi::VIM::ClusterComputeResource) || x.is_a?(RbVmomi::VIM::ComputeResource)
|
56
56
|
x
|
57
57
|
else
|
58
|
-
puts
|
58
|
+
puts 'ex unknown type ' + x.to_json
|
59
59
|
nil
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
62
|
end
|
64
63
|
|
65
64
|
def get_customization_spec_info_by_name(connection, machine)
|
66
65
|
name = machine.provider_config.customization_spec_name
|
67
66
|
return if name.nil? || name.empty?
|
68
67
|
|
69
|
-
manager = connection.serviceContent.customizationSpecManager
|
70
|
-
|
68
|
+
manager = connection.serviceContent.customizationSpecManager
|
69
|
+
fail Errors::VSphereError, :null_configuration_spec_manager if manager.nil?
|
70
|
+
|
71
|
+
spec = manager.GetCustomizationSpec(name: name)
|
72
|
+
fail Errors::VSphereError, :missing_configuration_spec if spec.nil?
|
73
|
+
|
74
|
+
spec
|
71
75
|
end
|
72
76
|
|
73
77
|
def get_datastore(datacenter, machine)
|
74
78
|
name = machine.provider_config.data_store_name
|
75
79
|
return if name.nil? || name.empty?
|
76
80
|
|
77
|
-
# find_datastore uses folder datastore that only lists Datastore and not StoragePod, if not found also try datastoreFolder which contains StoragePod(s)
|
78
|
-
datacenter.find_datastore
|
81
|
+
# find_datastore uses folder datastore that only lists Datastore and not StoragePod, if not found also try datastoreFolder which contains StoragePod(s)
|
82
|
+
datacenter.find_datastore(name) || datacenter.datastoreFolder.traverse(name) || fail(Errors::VSphereError, :missing_datastore)
|
79
83
|
end
|
80
84
|
|
81
85
|
def get_network_by_name(dc, name)
|
82
|
-
dc.network.find { |f| f.name == name }
|
86
|
+
dc.network.find { |f| f.name == name } || fail(Errors::VSphereError, :missing_vlan)
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
data/lib/vSphere/version.rb
CHANGED
data/lib/vagrant-vsphere.rb
CHANGED
data/spec/action_spec.rb
CHANGED
data/spec/clone_spec.rb
CHANGED
@@ -9,26 +9,26 @@ describe VagrantPlugins::VSphere::Action::Clone do
|
|
9
9
|
|
10
10
|
it "should create a CloneVM task with template's parent" do
|
11
11
|
call
|
12
|
-
expect(@template).to have_received(:CloneVM_Task).with(
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
|
17
|
-
|
12
|
+
expect(@template).to have_received(:CloneVM_Task).with(
|
13
|
+
folder: @data_center,
|
14
|
+
name: NAME,
|
15
|
+
spec: { location: { pool: @child_resource_pool },
|
16
|
+
config: RbVmomi::VIM.VirtualMachineConfigSpec }
|
17
|
+
)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should create a CloneVM task with custom folder when given vm base path' do
|
21
21
|
custom_base_folder = double(CUSTOM_VM_FOLDER,
|
22
|
-
:
|
22
|
+
pretty_path: "#{@data_center.pretty_path}/#{CUSTOM_VM_FOLDER}")
|
23
23
|
@machine.provider_config.stub(:vm_base_path).and_return(CUSTOM_VM_FOLDER)
|
24
24
|
@data_center.vmFolder.stub(:traverse).with(CUSTOM_VM_FOLDER, RbVmomi::VIM::Folder, true).and_return(custom_base_folder)
|
25
25
|
call
|
26
|
-
expect(@template).to have_received(:CloneVM_Task).with(
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
|
31
|
-
|
26
|
+
expect(@template).to have_received(:CloneVM_Task).with(
|
27
|
+
folder: custom_base_folder,
|
28
|
+
name: NAME,
|
29
|
+
spec: { location: { pool: @child_resource_pool },
|
30
|
+
config: RbVmomi::VIM.VirtualMachineConfigSpec }
|
31
|
+
)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should set the machine id to be the new UUID' do
|
@@ -43,46 +43,44 @@ describe VagrantPlugins::VSphere::Action::Clone do
|
|
43
43
|
|
44
44
|
it 'should create a CloneVM spec with configured vlan' do
|
45
45
|
@machine.provider_config.stub(:vlan).and_return('vlan')
|
46
|
-
network = double('network', :
|
46
|
+
network = double('network', name: 'vlan')
|
47
47
|
network.stub(:config).and_raise(StandardError)
|
48
48
|
@data_center.stub(:network).and_return([network])
|
49
49
|
call
|
50
50
|
|
51
|
-
expected_config = RbVmomi::VIM.VirtualMachineConfigSpec(:
|
52
|
-
expected_dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(:
|
51
|
+
expected_config = RbVmomi::VIM.VirtualMachineConfigSpec(deviceChange: Array.new)
|
52
|
+
expected_dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: @device, operation: 'edit')
|
53
53
|
expected_config[:deviceChange].push expected_dev_spec
|
54
54
|
|
55
|
-
expect(@template).to have_received(:CloneVM_Task).with(
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
|
60
|
-
:config => expected_config
|
55
|
+
expect(@template).to have_received(:CloneVM_Task).with(
|
56
|
+
folder: @data_center,
|
57
|
+
name: NAME,
|
58
|
+
spec: { location: { pool: @child_resource_pool },
|
59
|
+
config: expected_config
|
61
60
|
}
|
62
|
-
|
61
|
+
)
|
63
62
|
end
|
64
63
|
|
65
64
|
it 'should create a CloneVM spec with configured memory_mb' do
|
66
65
|
@machine.provider_config.stub(:memory_mb).and_return(2048)
|
67
66
|
call
|
68
|
-
expect(@template).to have_received(:CloneVM_Task).with(
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
|
73
|
-
|
67
|
+
expect(@template).to have_received(:CloneVM_Task).with(
|
68
|
+
folder: @data_center,
|
69
|
+
name: NAME,
|
70
|
+
spec: { location: { pool: @child_resource_pool },
|
71
|
+
config: RbVmomi::VIM.VirtualMachineConfigSpec(memoryMB: 2048) }
|
72
|
+
)
|
74
73
|
end
|
75
74
|
|
76
|
-
|
77
75
|
it 'should create a CloneVM spec with configured number of cpus' do
|
78
76
|
@machine.provider_config.stub(:cpu_count).and_return(4)
|
79
77
|
call
|
80
|
-
expect(@template).to have_received(:CloneVM_Task).with(
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
84
|
-
|
85
|
-
|
78
|
+
expect(@template).to have_received(:CloneVM_Task).with(
|
79
|
+
folder: @data_center,
|
80
|
+
name: NAME,
|
81
|
+
spec: { location: { pool: @child_resource_pool },
|
82
|
+
config: RbVmomi::VIM.VirtualMachineConfigSpec(numCPUs: 4) }
|
83
|
+
)
|
86
84
|
end
|
87
85
|
|
88
86
|
it 'should set static IP when given config spec' do
|
@@ -94,11 +92,11 @@ describe VagrantPlugins::VSphere::Action::Clone do
|
|
94
92
|
it 'should use root resource pool when cloning from template and no resource pool specified' do
|
95
93
|
@machine.provider_config.stub(:resource_pool_name).and_return(nil)
|
96
94
|
call
|
97
|
-
expect(@template).to have_received(:CloneVM_Task).with(
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
101
|
-
|
102
|
-
|
95
|
+
expect(@template).to have_received(:CloneVM_Task).with(
|
96
|
+
folder: @data_center,
|
97
|
+
name: NAME,
|
98
|
+
spec: { location: { pool: @root_resource_pool },
|
99
|
+
config: RbVmomi::VIM.VirtualMachineConfigSpec }
|
100
|
+
)
|
103
101
|
end
|
104
102
|
end
|