vagrant-vcenter 0.3.2 → 0.3.3
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/.ruby-version +1 -0
- data/README.md +18 -4
- data/Rakefile +2 -12
- data/lib/vagrant-vcenter/action.rb +20 -3
- data/lib/vagrant-vcenter/action/announce_ssh_exec.rb +9 -2
- data/lib/vagrant-vcenter/action/build_vm.rb +143 -130
- data/lib/vagrant-vcenter/action/connect_vcenter.rb +15 -14
- data/lib/vagrant-vcenter/action/destroy.rb +5 -8
- data/lib/vagrant-vcenter/action/disconnect_vcenter.rb +6 -5
- data/lib/vagrant-vcenter/action/inventory_check.rb +86 -81
- data/lib/vagrant-vcenter/action/is_created.rb +2 -24
- data/lib/vagrant-vcenter/action/is_paused.rb +0 -2
- data/lib/vagrant-vcenter/action/message_cannot_suspend.rb +3 -2
- data/lib/vagrant-vcenter/action/message_will_not_destroy.rb +6 -2
- data/lib/vagrant-vcenter/action/power_off.rb +5 -8
- data/lib/vagrant-vcenter/action/power_on.rb +6 -8
- data/lib/vagrant-vcenter/action/prepare_nfs_settings.rb +10 -4
- data/lib/vagrant-vcenter/action/read_ssh_info.rb +5 -6
- data/lib/vagrant-vcenter/action/read_state.rb +9 -12
- data/lib/vagrant-vcenter/action/resume.rb +5 -8
- data/lib/vagrant-vcenter/action/suspend.rb +5 -8
- data/lib/vagrant-vcenter/config.rb +36 -10
- data/lib/vagrant-vcenter/errors.rb +28 -0
- data/lib/vagrant-vcenter/plugin.rb +4 -2
- data/lib/vagrant-vcenter/version.rb +1 -1
- data/locales/en.yml +32 -4
- data/vagrant-vcenter.gemspec +4 -2
- metadata +39 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 297064f386d506f98c1ee81b435f71e21afcce8c
|
4
|
+
data.tar.gz: ba4e9971b70a7d6394fbdde4091e30b00dd27501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5fafe134b920ce9c684671e3f107b7f4ee2599f43510f94275536f27b9c3435daf04e756ef152e5c8aedd461104def93841d7c800a4e3767723bb429d69608f
|
7
|
+
data.tar.gz: 271cebf64fbe9b780422dc2ed4a1d6c1d086e5824f2f453f8d82f1e70c24edba6dbb9da285c01878ef36291761399e749de6e20fed5d2450c314c80b060df497
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
[Vagrant](http://www.vagrantup.com) provider for VMware vCenter®
|
2
2
|
=============
|
3
3
|
|
4
|
-
[
|
4
|
+
[](https://gitter.im/frapposelli/vagrant-vcenter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
|
+
|
6
|
+
[Version 0.3.3](../../releases/tag/v0.3.3) has been released!
|
5
7
|
-------------
|
6
8
|
|
7
9
|
Please note that this software is still Alpha/Beta quality and is not recommended for production usage.
|
@@ -10,6 +12,18 @@ We have a wide array of boxes available at [Vagrant Cloud](https://vagrantcloud.
|
|
10
12
|
|
11
13
|
This plugin supports the universal [```vmware_ovf``` box format](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf/wiki/vmware_ovf-Box-Format), that is 100% portable between [vagrant-vcloud](https://github.com/frapposelli/vagrant-vcloud), [vagrant-vcenter](https://github.com/gosddc/vagrant-vcenter) and [vagrant-vcloudair](https://github.com/gosddc/vagrant-vcloudair), no more double boxes!.
|
12
14
|
|
15
|
+
Changes in [version 0.3.3](../../releases/tag/v0.3.3) include:
|
16
|
+
|
17
|
+
Changes
|
18
|
+
|
19
|
+
- Configuration setting ```computer_name``` renamed to ```compute_name``` as this can be either a vSphere host or a Cluster name.
|
20
|
+
|
21
|
+
Fixes
|
22
|
+
|
23
|
+
- Better error management
|
24
|
+
- Fixed some commands in unwanted situations (SSH when machine suspended/off)
|
25
|
+
- Refactored code to avoid code duplication
|
26
|
+
|
13
27
|
Install
|
14
28
|
-------------
|
15
29
|
|
@@ -64,7 +78,7 @@ Vagrant.configure('2') do |config|
|
|
64
78
|
vcenter.password = 'myPassword'
|
65
79
|
vcenter.folder_name = 'myFolderName'
|
66
80
|
vcenter.datacenter_name = 'MyDatacenterName'
|
67
|
-
vcenter.
|
81
|
+
vcenter.compute_name = 'MyHostOrCluster'
|
68
82
|
vcenter.datastore_name = 'MyDatastore'
|
69
83
|
vcenter.network_name = 'myNetworkName'
|
70
84
|
vcenter.linked_clones = true
|
@@ -82,7 +96,7 @@ Vagrant.configure('2') do |config|
|
|
82
96
|
gateway: '10.250.254.254',
|
83
97
|
dns_server_list: ['8.8.4.4', '8.8.8.8'],
|
84
98
|
dns_suffix_list: ['ad.lab.gosddc.com']
|
85
|
-
|
99
|
+
|
86
100
|
# Let's override some provider settings for specific VMs
|
87
101
|
node_config.vm.provider :vcenter do |override|
|
88
102
|
# Override number of cpu and memory based on what's in the nodes array
|
@@ -116,4 +130,4 @@ What is still missing:
|
|
116
130
|
- Some spaghetti code here and there.
|
117
131
|
- Bugs, bugs and BUGS!.
|
118
132
|
|
119
|
-
If you're a developer and want to lend us a hand,
|
133
|
+
If you're a developer and want to lend us a hand, send us PRs!
|
data/Rakefile
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
+
require 'bundler/gem_tasks'
|
3
4
|
require 'rspec/core/rake_task'
|
4
5
|
|
5
|
-
# Immediately sync all stdout so that tools like buildbot can
|
6
|
-
# immediately load in the output.
|
7
|
-
$stdout.sync = true
|
8
|
-
$stderr.sync = true
|
9
|
-
|
10
|
-
# Change to the y of this file.
|
11
|
-
Dir.chdir(File.expand_path('../', __FILE__))
|
12
|
-
|
13
|
-
Bundler::GemHelper.install_tasks
|
14
|
-
|
15
6
|
RSpec::Core::RakeTask.new
|
16
|
-
|
17
|
-
task :default => 'spec'
|
7
|
+
task :default => 'spec'
|
@@ -23,6 +23,7 @@ module VagrantPlugins
|
|
23
23
|
Vagrant::Action::Builder.new.tap do |b|
|
24
24
|
b.use ConfigValidate
|
25
25
|
b.use ConnectvCenter
|
26
|
+
b.use InventoryCheck
|
26
27
|
b.use Call, IsCreated do |env, b2|
|
27
28
|
unless env[:result]
|
28
29
|
b2.use MessageNotCreated
|
@@ -30,7 +31,6 @@ module VagrantPlugins
|
|
30
31
|
end
|
31
32
|
b2.use action_halt
|
32
33
|
b2.use action_start
|
33
|
-
b2.use DisconnectvCenter
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -41,6 +41,7 @@ module VagrantPlugins
|
|
41
41
|
Vagrant::Action::Builder.new.tap do |b|
|
42
42
|
b.use ConfigValidate
|
43
43
|
b.use ConnectvCenter
|
44
|
+
b.use InventoryCheck
|
44
45
|
b.use Call, IsRunning do |env, b2|
|
45
46
|
# If the VM is running, then our work here is done, exit
|
46
47
|
if env[:result]
|
@@ -61,9 +62,16 @@ module VagrantPlugins
|
|
61
62
|
def self.action_halt
|
62
63
|
Vagrant::Action::Builder.new.tap do |b|
|
63
64
|
b.use ConnectvCenter
|
65
|
+
b.use InventoryCheck
|
66
|
+
|
67
|
+
# If the VM suspend, Resume first
|
64
68
|
b.use Call, IsPaused do |env, b2|
|
65
69
|
b2.use Resume if env[:result]
|
66
|
-
|
70
|
+
|
71
|
+
# Only halt when VM is running.
|
72
|
+
b2.use Call, IsRunning do |env2, b3|
|
73
|
+
b3.use PowerOff if env2[:result]
|
74
|
+
end
|
67
75
|
end
|
68
76
|
end
|
69
77
|
end
|
@@ -71,6 +79,7 @@ module VagrantPlugins
|
|
71
79
|
def self.action_suspend
|
72
80
|
Vagrant::Action::Builder.new.tap do |b|
|
73
81
|
b.use ConnectvCenter
|
82
|
+
b.use InventoryCheck
|
74
83
|
b.use Call, IsRunning do |env, b2|
|
75
84
|
# If the VM is stopped, can't suspend
|
76
85
|
if !env[:result]
|
@@ -85,6 +94,7 @@ module VagrantPlugins
|
|
85
94
|
def self.action_resume
|
86
95
|
Vagrant::Action::Builder.new.tap do |b|
|
87
96
|
b.use ConnectvCenter
|
97
|
+
b.use InventoryCheck
|
88
98
|
b.use Resume
|
89
99
|
end
|
90
100
|
end
|
@@ -95,6 +105,7 @@ module VagrantPlugins
|
|
95
105
|
if env[:result]
|
96
106
|
b2.use ConfigValidate
|
97
107
|
b2.use ConnectvCenter
|
108
|
+
b2.use InventoryCheck
|
98
109
|
b2.use Call, IsCreated do |env2, b3|
|
99
110
|
unless env2[:result]
|
100
111
|
b3.use MessageNotCreated
|
@@ -110,6 +121,7 @@ module VagrantPlugins
|
|
110
121
|
b2.use MessageWillNotDestroy
|
111
122
|
end
|
112
123
|
end
|
124
|
+
# b.use DisconnectvCenter
|
113
125
|
end
|
114
126
|
end
|
115
127
|
|
@@ -117,6 +129,7 @@ module VagrantPlugins
|
|
117
129
|
Vagrant::Action::Builder.new.tap do |b|
|
118
130
|
b.use ConfigValidate
|
119
131
|
b.use ConnectvCenter
|
132
|
+
b.use InventoryCheck
|
120
133
|
b.use Call, IsCreated do |env, b2|
|
121
134
|
unless env[:result]
|
122
135
|
b2.use MessageNotCreated
|
@@ -136,6 +149,7 @@ module VagrantPlugins
|
|
136
149
|
Vagrant::Action::Builder.new.tap do |b|
|
137
150
|
b.use ConfigValidate
|
138
151
|
b.use ConnectvCenter
|
152
|
+
b.use InventoryCheck
|
139
153
|
b.use ReadSSHInfo
|
140
154
|
end
|
141
155
|
end
|
@@ -147,6 +161,7 @@ module VagrantPlugins
|
|
147
161
|
Vagrant::Action::Builder.new.tap do |b|
|
148
162
|
b.use ConfigValidate
|
149
163
|
b.use ConnectvCenter
|
164
|
+
b.use InventoryCheck
|
150
165
|
b.use ReadState
|
151
166
|
end
|
152
167
|
end
|
@@ -155,6 +170,7 @@ module VagrantPlugins
|
|
155
170
|
Vagrant::Action::Builder.new.tap do |b|
|
156
171
|
b.use ConfigValidate
|
157
172
|
b.use ConnectvCenter
|
173
|
+
b.use InventoryCheck
|
158
174
|
b.use Call, IsCreated do |env, b2|
|
159
175
|
unless env[:result]
|
160
176
|
b2.use MessageNotCreated
|
@@ -169,6 +185,7 @@ module VagrantPlugins
|
|
169
185
|
Vagrant::Action::Builder.new.tap do |b|
|
170
186
|
b.use ConfigValidate
|
171
187
|
b.use ConnectvCenter
|
188
|
+
b.use InventoryCheck
|
172
189
|
b.use Call, IsCreated do |env, b2|
|
173
190
|
unless env[:result]
|
174
191
|
b2.use MessageNotCreated
|
@@ -182,10 +199,10 @@ module VagrantPlugins
|
|
182
199
|
def self.action_up
|
183
200
|
Vagrant::Action::Builder.new.tap do |b|
|
184
201
|
b.use ConfigValidate
|
185
|
-
b.use ConnectvCenter
|
186
202
|
b.use Call, IsCreated do |env, b2|
|
187
203
|
b2.use HandleBox unless env[:result]
|
188
204
|
end
|
205
|
+
b.use ConnectvCenter
|
189
206
|
b.use InventoryCheck
|
190
207
|
b.use Call, IsCreated do |env, b2|
|
191
208
|
b2.use BuildVM unless env[:result]
|
@@ -8,9 +8,16 @@ module VagrantPlugins
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
+
if env[:machine].state.id != :running
|
12
|
+
fail Errors::MachineNotRunning,
|
13
|
+
:machine_name => env[:machine].name
|
14
|
+
end
|
15
|
+
|
11
16
|
ssh_info = env[:machine].ssh_info
|
12
|
-
env[:ui].success(
|
13
|
-
|
17
|
+
env[:ui].success(
|
18
|
+
"External IP for #{env[:machine].name}: #{ssh_info[:host]}"
|
19
|
+
)
|
20
|
+
|
14
21
|
super
|
15
22
|
end
|
16
23
|
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
require 'etc'
|
3
|
-
|
4
1
|
module VagrantPlugins
|
5
2
|
module VCenter
|
6
3
|
module Action
|
@@ -15,45 +12,36 @@ module VagrantPlugins
|
|
15
12
|
# FIXME: we need to find a way to clean things up when a SIGINT get
|
16
13
|
# called... see env[:interrupted] in the vagrant code
|
17
14
|
|
18
|
-
|
15
|
+
cfg = env[:machine].provider_config
|
19
16
|
vm_name = env[:machine].name
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if env[:machine].box.name.to_s.include? '/'
|
26
|
-
box_file = env[:machine].box.name.rpartition('/').last.to_s
|
27
|
-
box_name = env[:machine].box.name.to_s.gsub(/\//, '-')
|
18
|
+
if env[:machine].box.name.include? '/'
|
19
|
+
# box_file = env[:machine].box.name.rpartition('/').last
|
20
|
+
box_name = env[:machine].box.name.gsub(/\//, '-')
|
28
21
|
else
|
29
|
-
box_file = env[:machine].box.name
|
22
|
+
box_file = env[:machine].box.name
|
30
23
|
box_name = box_file
|
31
24
|
end
|
32
25
|
|
33
|
-
if
|
26
|
+
if cfg.template_folder_name.nil?
|
34
27
|
box_to_search = box_name
|
35
28
|
else
|
36
|
-
box_to_search =
|
37
|
-
box_name
|
29
|
+
box_to_search = cfg.template_folder_name + '/' + box_name
|
38
30
|
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if config.resourcepool_name
|
45
|
-
rp = computer.resourcePool.resourcePool.find {
|
46
|
-
|f| f.name == config.resourcepool_name
|
32
|
+
if cfg.resourcepool_name
|
33
|
+
cfg.compute_rp = compute.resourcePool.resourcePool.find {
|
34
|
+
|f| f.name == cfg.resourcepool_name
|
47
35
|
}
|
48
36
|
else
|
49
|
-
|
37
|
+
cfg.compute_rp = cfg.compute.resourcePool
|
50
38
|
end
|
51
39
|
|
52
|
-
|
53
|
-
|
54
|
-
|
40
|
+
template = cfg.datacenter.find_vm(box_to_search) or
|
41
|
+
fail Errors::VMNotFound,
|
42
|
+
:vm_name => box_to_search
|
55
43
|
|
56
|
-
if
|
44
|
+
if cfg.linked_clones
|
57
45
|
@logger.debug('DOING LINKED CLONE!')
|
58
46
|
# The API for linked clones is quite strange. We can't create a
|
59
47
|
# linked straight from any VM. The disks of the VM for which we can
|
@@ -64,18 +52,20 @@ module VagrantPlugins
|
|
64
52
|
# Thus, this code first create a delta disk on top of the base disk
|
65
53
|
# for the to-be-cloned VM, if delta disks aren't used already.
|
66
54
|
disks = template.config.hardware.device.grep(
|
67
|
-
|
55
|
+
RbVmomi::VIM::VirtualDisk
|
56
|
+
)
|
57
|
+
|
68
58
|
disks.select { |x| x.backing.parent.nil? }.each do |disk|
|
69
59
|
spec = {
|
70
60
|
:deviceChange => [
|
71
61
|
{
|
72
|
-
:operation
|
73
|
-
:device
|
62
|
+
:operation => :remove,
|
63
|
+
:device => disk
|
74
64
|
},
|
75
65
|
{
|
76
|
-
:operation
|
77
|
-
:fileOperation
|
78
|
-
:device
|
66
|
+
:operation => :add,
|
67
|
+
:fileOperation => :create,
|
68
|
+
:device => disk.dup.tap do |x|
|
79
69
|
x.backing = x.backing.dup
|
80
70
|
x.backing.fileName = "[#{disk.backing.datastore.name}]"
|
81
71
|
x.backing.parent = disk.backing
|
@@ -87,49 +77,57 @@ module VagrantPlugins
|
|
87
77
|
end
|
88
78
|
|
89
79
|
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(
|
90
|
-
|
91
|
-
|
80
|
+
:diskMoveType => :moveChildMostDiskBacking,
|
81
|
+
:pool => cfg.compute_rp
|
82
|
+
)
|
92
83
|
else
|
93
84
|
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(
|
94
|
-
|
85
|
+
:pool => cfg.compute_rp
|
86
|
+
)
|
95
87
|
end
|
96
88
|
|
97
89
|
@logger.debug("Relocate Spec: #{relocate_spec.pretty_inspect}")
|
98
90
|
|
99
91
|
spec = RbVmomi::VIM.VirtualMachineCloneSpec(
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
92
|
+
:location => relocate_spec,
|
93
|
+
:powerOn => false,
|
94
|
+
:template => false
|
95
|
+
)
|
96
|
+
|
97
|
+
if cfg.vm_network_name || cfg.num_cpu || cfg.memory
|
105
98
|
config_spec = RbVmomi::VIM.VirtualMachineConfigSpec
|
106
|
-
config_spec.numCPUs =
|
107
|
-
config_spec.memoryMB =
|
108
|
-
|
109
|
-
if
|
110
|
-
# First we must find the specified network
|
111
|
-
network = dc.network.find { |f| f.name == config.vm_network_name } or
|
112
|
-
abort "Could not find network with name #{config.vm_network_name} to join vm to"
|
99
|
+
config_spec.numCPUs = cfg.num_cpu if cfg.num_cpu
|
100
|
+
config_spec.memoryMB = cfg.memory if cfg.memory
|
101
|
+
|
102
|
+
if cfg.vm_network_name
|
113
103
|
card = template.config.hardware.device.grep(
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
104
|
+
RbVmomi::VIM::VirtualEthernetCard
|
105
|
+
).first or abort 'could not find network card to customize'
|
106
|
+
|
107
|
+
if cfg.vm_network_type == 'DistributedVirtualSwitchPort'
|
108
|
+
switch_port =
|
109
|
+
RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
110
|
+
:switchUuid => cfg.network.config.distributedVirtualSwitch.uuid,
|
111
|
+
:portgroupKey => cfg.network.key
|
112
|
+
)
|
120
113
|
card.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
|
121
|
-
|
122
|
-
|
123
|
-
|
114
|
+
:port => switch_port
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(
|
119
|
+
:device => card,
|
120
|
+
:operation => 'edit'
|
121
|
+
)
|
124
122
|
config_spec.deviceChange = [dev_spec]
|
125
123
|
end
|
126
124
|
|
127
125
|
spec.config = config_spec
|
128
126
|
end
|
129
127
|
|
130
|
-
if
|
128
|
+
if cfg.enable_vm_customization
|
131
129
|
public_networks = env[:machine].config.vm.networks.select {
|
132
|
-
|
130
|
+
|n| n[0].eql? :public_network
|
133
131
|
}
|
134
132
|
|
135
133
|
network_spec = public_networks.first[1] unless public_networks.empty?
|
@@ -137,70 +135,74 @@ module VagrantPlugins
|
|
137
135
|
@logger.debug("This is our network #{public_networks.inspect}")
|
138
136
|
|
139
137
|
if network_spec
|
140
|
-
|
141
138
|
# Check for sanity and validation of network parameters.
|
142
|
-
|
143
|
-
|
144
|
-
if network_spec[:ip] && !network_spec[:netmask]
|
145
|
-
fail Errors::WrongNetworkSpec
|
146
|
-
end
|
147
|
-
|
148
|
-
# specify netmask but no ip
|
149
|
-
if !network_spec[:ip] && network_spec[:netmask]
|
139
|
+
if (network_spec[:ip] && !network_spec[:netmask]) ||
|
140
|
+
(!network_spec[:ip] && network_spec[:netmask])
|
150
141
|
fail Errors::WrongNetworkSpec
|
151
142
|
end
|
152
143
|
|
153
144
|
global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings(
|
154
|
-
|
155
|
-
|
145
|
+
:dnsServerList => network_spec[:dns_server_list],
|
146
|
+
:dnsSuffixList => network_spec[:dns_suffix_list]
|
147
|
+
)
|
156
148
|
|
157
149
|
# if no ip and no netmask, let's default to dhcp
|
158
150
|
if !network_spec[:ip] && !network_spec[:netmask]
|
159
151
|
adapter = RbVmomi::VIM.CustomizationIPSettings(
|
160
|
-
|
152
|
+
:ip => RbVmomi::VIM.CustomizationDhcpIpGenerator()
|
153
|
+
)
|
161
154
|
else
|
162
155
|
adapter = RbVmomi::VIM.CustomizationIPSettings(
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
156
|
+
:gateway => [network_spec[:gateway]],
|
157
|
+
:ip => RbVmomi::VIM.CustomizationFixedIp(
|
158
|
+
:ipAddress => network_spec[:ip]
|
159
|
+
),
|
160
|
+
:subnetMask => network_spec[:netmask]
|
161
|
+
)
|
167
162
|
end
|
168
163
|
|
169
|
-
nic_map = [
|
170
|
-
|
164
|
+
nic_map = [
|
165
|
+
RbVmomi::VIM.CustomizationAdapterMapping(:adapter => adapter)
|
166
|
+
]
|
171
167
|
end
|
172
168
|
|
173
|
-
if
|
169
|
+
if cfg.prep_type.downcase == 'linux'
|
174
170
|
prep = RbVmomi::VIM.CustomizationLinuxPrep(
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
171
|
+
:domain => env[:machine].name.to_s.sub(/^[^.]+\./, ''),
|
172
|
+
:hostName => RbVmomi::VIM.CustomizationFixedName(
|
173
|
+
:name => env[:machine].name.to_s.split('.')[0]
|
174
|
+
)
|
175
|
+
)
|
176
|
+
elsif cfg.prep_type.downcase == 'windows'
|
179
177
|
prep = RbVmomi::VIM.CustomizationSysprep(
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
:guiUnattended => RbVmomi::VIM.CustomizationGuiUnattended(
|
179
|
+
:autoLogon => false,
|
180
|
+
:autoLogonCount => 0,
|
181
|
+
:timeZone => 004
|
182
|
+
),
|
183
|
+
:identification => RbVmomi::VIM.CustomizationIdentification(),
|
184
|
+
:userData => RbVmomi::VIM.CustomizationUserData(
|
185
|
+
:computerName => RbVmomi::VIM.CustomizationFixedName(
|
186
|
+
:name => env[:machine].name.to_s.split('.')[0]
|
187
|
+
),
|
188
|
+
:fullName => 'Vagrant',
|
189
|
+
:orgName => 'Vagrant',
|
190
|
+
:productId => 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
|
191
|
+
)
|
193
192
|
)
|
194
|
-
else
|
195
|
-
fail
|
193
|
+
else
|
194
|
+
fail Errors::GuestCustomNotSupported,
|
195
|
+
:type => cfg.prep_type
|
196
196
|
end
|
197
197
|
|
198
198
|
if prep && network_spec
|
199
|
-
# If prep and network specification are present,
|
199
|
+
# If prep and network specification are present,
|
200
|
+
# -> Do a full config
|
200
201
|
cust_spec = RbVmomi::VIM.CustomizationSpec(
|
201
|
-
|
202
|
-
|
203
|
-
|
202
|
+
:globalIPSettings => global_ip_settings,
|
203
|
+
:identity => prep,
|
204
|
+
:nicSettingMap => nic_map
|
205
|
+
)
|
204
206
|
|
205
207
|
spec.customization = cust_spec
|
206
208
|
|
@@ -208,18 +210,22 @@ module VagrantPlugins
|
|
208
210
|
# If no network specifications, default to dhcp
|
209
211
|
global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings(
|
210
212
|
:dnsServerList => [],
|
211
|
-
:dnsSuffixList => []
|
213
|
+
:dnsSuffixList => []
|
214
|
+
)
|
212
215
|
|
213
216
|
adapter = RbVmomi::VIM.CustomizationIPSettings(
|
214
|
-
:ip => RbVmomi::VIM.CustomizationDhcpIpGenerator()
|
217
|
+
:ip => RbVmomi::VIM.CustomizationDhcpIpGenerator()
|
218
|
+
)
|
215
219
|
|
216
|
-
nic_map = [
|
217
|
-
|
220
|
+
nic_map = [
|
221
|
+
RbVmomi::VIM.CustomizationAdapterMapping(:adapter => adapter)
|
222
|
+
]
|
218
223
|
|
219
224
|
cust_spec = RbVmomi::VIM.CustomizationSpec(
|
220
|
-
|
221
|
-
|
222
|
-
|
225
|
+
:globalIPSettings => global_ip_settings,
|
226
|
+
:identity => prep,
|
227
|
+
:nicSettingMap => nic_map
|
228
|
+
)
|
223
229
|
|
224
230
|
spec.customization = cust_spec
|
225
231
|
end
|
@@ -227,10 +233,12 @@ module VagrantPlugins
|
|
227
233
|
@logger.debug("Spec: #{spec.pretty_inspect}")
|
228
234
|
end
|
229
235
|
|
230
|
-
@logger.debug("disable_auto_vm_name: #{
|
236
|
+
@logger.debug("disable_auto_vm_name: #{cfg.disable_auto_vm_name}")
|
231
237
|
|
232
|
-
|
233
|
-
|
238
|
+
# Not recommended in a vSphere environment where VM names might
|
239
|
+
# conflict a lot if used in the same vm folder namespace
|
240
|
+
if cfg.disable_auto_vm_name == true
|
241
|
+
vm_target = vm_name
|
234
242
|
else
|
235
243
|
vm_target = "Vagrant-#{Etc.getlogin}-" +
|
236
244
|
"#{vm_name}-#{Socket.gethostname.downcase}-" +
|
@@ -242,21 +250,24 @@ module VagrantPlugins
|
|
242
250
|
# FIXME: vm.parent brings us to the template folder, fix this with
|
243
251
|
# folder_path.
|
244
252
|
|
245
|
-
|
246
|
-
|
247
|
-
unless config.folder_name.nil?
|
253
|
+
vm_folder = cfg.vmfolder
|
254
|
+
unless cfg.folder_name.nil?
|
248
255
|
begin
|
249
256
|
# Better ask for forgiveness than permission ;-)
|
250
|
-
@logger.debug("Creating folder #{
|
251
|
-
vm_folder =
|
252
|
-
|
253
|
-
|
257
|
+
@logger.debug("Creating folder #{cfg.folder_name}.")
|
258
|
+
vm_folder = cfg.vmfolder.traverse(
|
259
|
+
cfg.folder_name,
|
260
|
+
RbVmomi::VIM::Folder,
|
261
|
+
create = true
|
262
|
+
)
|
254
263
|
# FIXME: we should trap the correct exception
|
255
264
|
rescue RbVmomi::Fault
|
256
265
|
# if somebody else created the folder already...
|
257
|
-
@logger.debug("Folder #{
|
258
|
-
vm_folder =
|
259
|
-
|
266
|
+
@logger.debug("Folder #{cfg.folder_name} already exists.")
|
267
|
+
vm_folder = cfg.vmfolder.traverse(
|
268
|
+
cfg.folder_name,
|
269
|
+
RbVmomi::VIM::Folder
|
270
|
+
)
|
260
271
|
end
|
261
272
|
end
|
262
273
|
@logger.debug("folder for VM: #{vm_folder}")
|
@@ -264,21 +275,23 @@ module VagrantPlugins
|
|
264
275
|
env[:ui].info('Creating VM...')
|
265
276
|
|
266
277
|
template.CloneVM_Task(
|
267
|
-
|
268
|
-
|
269
|
-
|
278
|
+
:folder => vm_folder,
|
279
|
+
:name => vm_target,
|
280
|
+
:spec => spec
|
281
|
+
).wait_for_completion
|
270
282
|
|
271
|
-
if
|
272
|
-
vm_to_search = vm_target
|
283
|
+
if cfg.folder_name.nil?
|
284
|
+
vm_to_search = vm_target.to_s
|
273
285
|
else
|
274
|
-
vm_to_search =
|
286
|
+
vm_to_search = cfg.folder_name + '/' + vm_target.to_s
|
275
287
|
end
|
276
288
|
|
277
289
|
@logger.debug("VM to search: #{vm_to_search}")
|
278
290
|
|
279
|
-
|
280
|
-
|
281
|
-
|
291
|
+
env[:machine].id = cfg.datacenter.find_vm(
|
292
|
+
vm_to_search
|
293
|
+
).config.uuid or fail Errors::VMNotFound,
|
294
|
+
:vm_name => vm_to_search
|
282
295
|
|
283
296
|
@app.call env
|
284
297
|
end
|