vagrant-parallels 0.2.1 → 0.2.2.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -13
  3. data/.travis.yml +1 -0
  4. data/README.md +43 -54
  5. data/config/i18n-tasks.yml.erb +1 -1
  6. data/debug.log +941 -0
  7. data/lib/vagrant-parallels/action.rb +0 -7
  8. data/lib/vagrant-parallels/action/check_accessible.rb +1 -1
  9. data/lib/vagrant-parallels/action/check_guest_tools.rb +10 -2
  10. data/lib/vagrant-parallels/action/clear_network_interfaces.rb +1 -1
  11. data/lib/vagrant-parallels/action/customize.rb +6 -4
  12. data/lib/vagrant-parallels/action/export.rb +56 -12
  13. data/lib/vagrant-parallels/action/import.rb +49 -30
  14. data/lib/vagrant-parallels/action/network.rb +137 -48
  15. data/lib/vagrant-parallels/action/package_config_files.rb +0 -12
  16. data/lib/vagrant-parallels/action/prepare_nfs_valid_ids.rb +1 -1
  17. data/lib/vagrant-parallels/action/set_name.rb +2 -2
  18. data/lib/vagrant-parallels/config.rb +11 -2
  19. data/lib/vagrant-parallels/driver/base.rb +281 -0
  20. data/lib/vagrant-parallels/driver/meta.rb +138 -0
  21. data/lib/vagrant-parallels/driver/{prl_ctl.rb → pd_8.rb} +116 -256
  22. data/lib/vagrant-parallels/driver/pd_9.rb +417 -0
  23. data/lib/vagrant-parallels/errors.rb +15 -7
  24. data/lib/vagrant-parallels/plugin.rb +7 -7
  25. data/lib/vagrant-parallels/provider.rb +33 -3
  26. data/lib/vagrant-parallels/version.rb +1 -1
  27. data/locales/en.yml +30 -16
  28. data/test/unit/base.rb +1 -5
  29. data/test/unit/config_test.rb +13 -2
  30. data/test/unit/driver/pd_8_test.rb +196 -0
  31. data/test/unit/driver/pd_9_test.rb +196 -0
  32. data/test/unit/locales/locales_test.rb +1 -1
  33. data/test/unit/support/shared/parallels_context.rb +2 -2
  34. data/test/unit/support/shared/pd_driver_examples.rb +243 -0
  35. data/test/unit/synced_folder_test.rb +37 -0
  36. data/vagrant-parallels.gemspec +5 -5
  37. metadata +39 -32
  38. data/lib/vagrant-parallels/action/match_mac_address.rb +0 -28
  39. data/lib/vagrant-parallels/action/register_template.rb +0 -24
  40. data/lib/vagrant-parallels/action/unregister_template.rb +0 -26
  41. data/test/support/isolated_environment.rb +0 -46
  42. data/test/support/tempdir.rb +0 -43
  43. data/test/unit/driver/prl_ctl_test.rb +0 -148
@@ -261,11 +261,8 @@ module VagrantPlugins
261
261
  # If the VM is NOT created yet, then do the setup steps
262
262
  if !env[:result]
263
263
  b2.use CheckAccessible
264
- b2.use RegisterTemplate
265
264
  b2.use Customize, "pre-import"
266
265
  b2.use Import
267
- b2.use UnregisterTemplate
268
- b2.use MatchMACAddress
269
266
  end
270
267
  end
271
268
  b.use action_start
@@ -288,7 +285,6 @@ module VagrantPlugins
288
285
  autoload :Import, File.expand_path("../action/import", __FILE__)
289
286
  autoload :IsSuspended, File.expand_path("../action/is_suspended", __FILE__)
290
287
  autoload :IsRunning, File.expand_path("../action/is_running", __FILE__)
291
- autoload :MatchMACAddress, File.expand_path("../action/match_mac_address", __FILE__)
292
288
  autoload :MessageAlreadyRunning, File.expand_path("../action/message_already_running", __FILE__)
293
289
  autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
294
290
  autoload :MessageNotRunning, File.expand_path("../action/message_not_running", __FILE__)
@@ -298,13 +294,10 @@ module VagrantPlugins
298
294
  autoload :PackageConfigFiles, File.expand_path("../action/package_config_files", __FILE__)
299
295
  autoload :PrepareNFSSettings, File.expand_path("../action/prepare_nfs_settings", __FILE__)
300
296
  autoload :PrepareNFSValidIds, File.expand_path("../action/prepare_nfs_valid_ids", __FILE__)
301
- autoload :RegisterTemplate, File.expand_path("../action/register_template", __FILE__)
302
297
  autoload :Resume, File.expand_path("../action/resume", __FILE__)
303
298
  autoload :SetupPackageFiles, File.expand_path("../action/setup_package_files", __FILE__)
304
299
  autoload :SetName, File.expand_path("../action/set_name", __FILE__)
305
300
  autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
306
- autoload :UnregisterTemplate, File.expand_path("../action/unregister_template", __FILE__)
307
-
308
301
  end
309
302
  end
310
303
  end
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  # is a very bad situation and can only be fixed by the user. It
13
13
  # also prohibits us from actually doing anything with the virtual
14
14
  # machine, so we raise an error.
15
- raise Vagrant::Errors::VMInaccessible
15
+ raise VagrantPlugins::Parallels::Errors::VMInaccessible
16
16
  end
17
17
 
18
18
  @app.call(env)
@@ -4,9 +4,17 @@ module VagrantPlugins
4
4
  class CheckGuestTools
5
5
  def initialize(app, env)
6
6
  @app = app
7
+ @logger = Log4r::Logger.new("vagrant::plugins::parallels::check_guest_tools")
7
8
  end
8
9
 
9
10
  def call(env)
11
+ if !env[:machine].provider_config.check_guest_tools
12
+ @logger.info("Not checking guest tools because configuration")
13
+ return @app.call(env)
14
+ end
15
+
16
+ env[:ui].info(I18n.t("vagrant_parallels.parallels.checking_guest_tools"))
17
+
10
18
  tools_version = env[:machine].provider.driver.read_guest_tools_version
11
19
  if !tools_version
12
20
  env[:ui].warn I18n.t("vagrant_parallels.actions.vm.check_guest_tools.not_detected")
@@ -14,8 +22,8 @@ module VagrantPlugins
14
22
  pd_version = env[:machine].provider.driver.version
15
23
  unless pd_version.start_with? tools_version
16
24
  env[:ui].warn(I18n.t("vagrant_parallels.actions.vm.check_guest_tools.version_mismatch",
17
- tools_version: tools_version,
18
- parallels_version: pd_version))
25
+ :tools_version => tools_version,
26
+ :parallels_version => pd_version))
19
27
  end
20
28
  end
21
29
 
@@ -9,7 +9,7 @@ module VagrantPlugins
9
9
  def call(env)
10
10
  # Delete all disabled network adapters
11
11
  env[:ui].info I18n.t("vagrant.actions.vm.clear_network_interfaces.deleting")
12
- env[:machine].provider.driver.delete_adapters
12
+ env[:machine].provider.driver.delete_disabled_adapters
13
13
 
14
14
  @app.call(env)
15
15
  end
@@ -25,11 +25,13 @@ module VagrantPlugins
25
25
  arg.to_s
26
26
  end
27
27
 
28
- result = env[:machine].provider.driver.set_vm_settings(processed_command)
29
- if result.exit_code != 0
28
+ begin
29
+ env[:machine].provider.driver.execute_command(
30
+ processed_command + [retryable: true])
31
+ rescue VagrantPlugins::Parallels::Errors::PrlCtlError => e
30
32
  raise Vagrant::Errors::VMCustomizationFailed, {
31
- :command => processed_command.inspect,
32
- :error => result.stderr
33
+ :command => command,
34
+ :error => e.inspect
33
35
  }
34
36
  end
35
37
  end
@@ -2,50 +2,94 @@ module VagrantPlugins
2
2
  module Parallels
3
3
  module Action
4
4
  class Export
5
- include Util
6
-
7
5
  def initialize(app, env)
8
6
  @app = app
7
+ @logger = Log4r::Logger.new("vagrant::plugins::parallels::export")
9
8
  end
10
9
 
11
10
  def call(env)
12
11
  @env = env
12
+ if env[:machine].provider.state.id != :stopped
13
+ raise Vagrant::Errors::VMPowerOffToPackage
14
+ end
15
+
16
+ name = "#{env[:root_path].basename.to_s}_#{env[:machine].name}"
17
+ name.gsub!(/[^-a-z0-9_]/i, "")
18
+
19
+ # Check the name is not in use
20
+ if @env[:machine].provider.driver.read_vms.has_key?(@template_name)
21
+ @template_name << rand(100000).to_s
22
+ end
13
23
 
14
- raise Vagrant::Errors::VMPowerOffToPackage if \
15
- @env[:machine].provider.state.id != :stopped
16
24
 
17
- export
18
- compact
25
+ @template_name = gen_template_name
26
+ @template_uuid = export
27
+ compact_template
28
+ unregister_template
19
29
 
20
30
  @app.call(env)
21
31
  end
22
32
 
23
- def export
24
- temp_vm_name = generate_name(@env[:root_path], '_export')
33
+ def recover(env)
34
+ @env = env
35
+ unregister_template
36
+ end
37
+
38
+ private
39
+
40
+ def gen_template_name
41
+ # Use configured name if it is specified, or generate the new one
42
+ name = @env[:machine].provider_config.name
43
+ if !name
44
+ name = "#{@env[:root_path].basename.to_s}_#{@env[:machine].name}"
45
+ name.gsub!(/[^-a-z0-9_]/i, "")
46
+ end
47
+ tpl_name = "#{name}_box"
25
48
 
49
+ # Ensure that the name is not in use
50
+ if @env[:machine].provider.driver.read_vms.has_key?(tpl_name)
51
+ tpl_name << "_#{rand(1000)}"
52
+ end
53
+
54
+ tpl_name
55
+ end
56
+
57
+ def export
26
58
  @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
27
- @temp_vm_uuid = @env[:machine].provider.driver.export(@env["export.temp_dir"], temp_vm_name) do |progress|
59
+ tpl_uuid = @env[:machine].provider.driver.export(@env["export.temp_dir"], @template_name) do |progress|
28
60
  @env[:ui].clear_line
29
61
  @env[:ui].report_progress(progress, 100, false)
62
+
63
+ # # If we got interrupted, then the import could have been interrupted.
64
+ # Just rise an exception and then 'recover' will be called to cleanup.
65
+ raise Vagrant::Errors::VagrantInterrupt if @env[:interrupted]
30
66
  end
31
67
 
32
68
  # Clear the line a final time so the next data can appear
33
69
  # alone on the line.
34
70
  @env[:ui].clear_line
71
+
72
+ tpl_uuid
35
73
  end
36
74
 
37
- def compact
75
+ def compact_template
38
76
  @env[:ui].info I18n.t("vagrant_parallels.actions.vm.export.compacting")
39
- @env[:machine].provider.driver.compact(@temp_vm_uuid) do |progress|
77
+ @env[:machine].provider.driver.compact(@template_uuid) do |progress|
40
78
  @env[:ui].clear_line
41
79
  @env[:ui].report_progress(progress, 100, false)
42
80
  end
43
- @env[:machine].provider.driver.unregister(@temp_vm_uuid)
44
81
 
45
82
  # Clear the line a final time so the next data can appear
46
83
  # alone on the line.
47
84
  @env[:ui].clear_line
48
85
  end
86
+
87
+ def unregister_template
88
+ if @env[:machine].provider.driver.registered?(@template_uuid)
89
+ @logger.info("Unregister the box template: '#{@template_uuid}'")
90
+ @env[:machine].provider.driver.unregister(@template_uuid)
91
+ end
92
+ end
49
93
  end
50
94
  end
51
95
  end
@@ -2,41 +2,17 @@ module VagrantPlugins
2
2
  module Parallels
3
3
  module Action
4
4
  class Import
5
-
6
- include Util
7
-
8
5
  def initialize(app, env)
9
6
  @app = app
7
+ @logger = Log4r::Logger.new("vagrant::plugins::parallels::import")
10
8
  end
11
9
 
12
- #TODO: Clean up registered VM on interupt
13
10
  def call(env)
14
- env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
15
- :name => env[:machine].box.name)
16
-
17
- vm_name = generate_name(env[:root_path])
18
-
19
- # Verify the name is not taken
20
- if env[:machine].provider.driver.read_all_names.has_key?(vm_name)
21
- raise Vagrant::Errors::VMNameExists, :name => vm_name
22
- end
23
-
24
- # Import the virtual machine
25
- template_path = File.realpath(Pathname.glob(env[:machine].box.directory.join('*.pvm')).first)
26
- template_uuid = env[:machine].provider.driver.read_all_paths[template_path]
27
-
28
- env[:machine].id = env[:machine].provider.driver.import(template_uuid, vm_name) do |progress|
29
- env[:ui].clear_line
30
- env[:ui].report_progress(progress, 100, false)
31
- end
32
-
33
- # Clear the line one last time since the progress meter doesn't disappear
34
- # immediately.
35
- env[:ui].clear_line
36
-
37
- # If we got interrupted, then the import could have been
38
- # interrupted and its not a big deal. Just return out.
39
- return if env[:interrupted]
11
+ @env = env
12
+ @template_path = File.realpath(Pathname.glob(env[:machine].box.directory.join('*.pvm')).first)
13
+ @template_uuid = register_template
14
+ import
15
+ unregister_template
40
16
 
41
17
  # Flag as erroneous and return if import failed
42
18
  raise Vagrant::Errors::VMImportFailure if !env[:machine].id
@@ -46,8 +22,13 @@ module VagrantPlugins
46
22
  end
47
23
 
48
24
  def recover(env)
25
+ @env = env
26
+ # We should to unregister template
27
+ unregister_template
28
+
49
29
  if env[:machine].provider.state.id != :not_created
50
30
  return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
31
+ return if env["vagrant_parallels.error"].is_a?(VagrantPlugins::Parallels::Errors::VagrantParallelsError)
51
32
 
52
33
  # If we're not supposed to destroy on error then just return
53
34
  return if !env[:destroy_on_error]
@@ -61,6 +42,44 @@ module VagrantPlugins
61
42
  env[:action_runner].run(Action.action_destroy, destroy_env)
62
43
  end
63
44
  end
45
+
46
+ protected
47
+
48
+ def register_template
49
+ if !@env[:machine].provider.driver.read_vms_paths.has_key?(@template_path)
50
+ @logger.info("Register the box template: '#{@template_path}'")
51
+ @env[:machine].provider.driver.register(@template_path)
52
+ end
53
+
54
+ # Return the uuid of registered template
55
+ @env[:machine].provider.driver.read_vms_paths[@template_path]
56
+ end
57
+
58
+ def import
59
+ @env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
60
+ :name => @env[:machine].box.name)
61
+
62
+ # Import the virtual machine
63
+ @env[:machine].id = @env[:machine].provider.driver.import(@template_uuid) do |progress|
64
+ @env[:ui].clear_line
65
+ @env[:ui].report_progress(progress, 100, false)
66
+
67
+ # # If we got interrupted, then the import could have been interrupted.
68
+ # Just rise an exception and then 'recover' will be called to cleanup.
69
+ raise Vagrant::Errors::VagrantInterrupt if @env[:interrupted]
70
+ end
71
+
72
+ # Clear the line one last time since the progress meter doesn't disappear
73
+ # immediately.
74
+ @env[:ui].clear_line
75
+ end
76
+
77
+ def unregister_template
78
+ if @env[:machine].provider.driver.registered?(@template_uuid)
79
+ @logger.info("Unregister the box template: '#{@template_uuid}'")
80
+ @env[:machine].provider.driver.unregister(@template_uuid)
81
+ end
82
+ end
64
83
  end
65
84
  end
66
85
  end
@@ -24,11 +24,15 @@ module VagrantPlugins
24
24
 
25
25
  def call(env)
26
26
  @env = env
27
+
27
28
  # Get the list of network adapters from the configuration
28
29
  network_adapters_config = env[:machine].provider_config.network_adapters.dup
29
30
 
31
+ # Get maximum number of network adapters
32
+ max_adapters = env[:machine].provider.driver.max_network_adapters
33
+
30
34
  # Assign the adapter slot for each high-level network
31
- available_slots = Set.new(0..7)
35
+ available_slots = Set.new(0...max_adapters)
32
36
  network_adapters_config.each do |slot, _data|
33
37
  available_slots.delete(slot)
34
38
  end
@@ -56,10 +60,10 @@ module VagrantPlugins
56
60
  data = nil
57
61
  if type == :private_network
58
62
  # private_network = hostonly
59
- data = [:hostonly, options]
63
+ data = [:hostonly, options]
60
64
  elsif type == :public_network
61
65
  # public_network = bridged
62
- data = [:bridged, options]
66
+ data = [:bridged, options]
63
67
  end
64
68
 
65
69
  # Store it!
@@ -69,6 +73,7 @@ module VagrantPlugins
69
73
 
70
74
  @logger.info("Determining adapters and compiling network configuration...")
71
75
  adapters = []
76
+ networks = []
72
77
  network_adapters_config.each do |slot, data|
73
78
  type = data[0]
74
79
  options = data[1]
@@ -84,29 +89,53 @@ module VagrantPlugins
84
89
  adapter = send("#{type}_adapter", config)
85
90
  adapters << adapter
86
91
  @logger.debug("Adapter configuration: #{adapter.inspect}")
92
+
93
+ # Get the network configuration
94
+ network = send("#{type}_network_config", config)
95
+ network[:auto_config] = config[:auto_config]
96
+ networks << network
87
97
  end
88
98
 
89
99
  if !adapters.empty?
90
100
  # Enable the adapters
91
101
  @logger.info("Enabling adapters...")
92
- env[:ui].info I18n.t("vagrant.actions.vm.network.preparing")
102
+ env[:ui].info(I18n.t("vagrant.actions.vm.network.preparing"))
103
+ adapters.each do |adapter|
104
+ env[:ui].info(I18n.t(
105
+ "vagrant_parallels.parallels.network_adapter",
106
+ adapter: adapter[:adapter].to_s,
107
+ type: adapter[:type].to_s,
108
+ extra: "",
109
+ ))
110
+ end
111
+
93
112
  env[:machine].provider.driver.enable_adapters(adapters)
94
113
  end
95
114
 
96
115
  # Continue the middleware chain.
97
116
  @app.call(env)
98
117
 
99
- end
118
+ # If we have networks to configure, then we configure it now, since
119
+ # that requires the machine to be up and running.
120
+ if !adapters.empty? && !networks.empty?
121
+ assign_interface_numbers(networks, adapters)
100
122
 
101
- def bridged_config(options)
102
- if options[:type] and options[:type].to_sym == :dhcp
103
- options[:dhcp] = true
123
+ # Only configure the networks the user requested us to configure
124
+ networks_to_configure = networks.select { |n| n[:auto_config] }
125
+ if !networks_to_configure.empty?
126
+ env[:ui].info I18n.t("vagrant.actions.vm.network.configuring")
127
+ env[:machine].guest.capability(:configure_networks, networks_to_configure)
128
+ end
104
129
  end
130
+ end
105
131
 
132
+ def bridged_config(options)
106
133
  return {
107
- :bridge => nil,
108
- :mac => nil,
109
- :nic_type => "e1000",
134
+ :auto_config => true,
135
+ :bridge => nil,
136
+ :mac => nil,
137
+ :nic_type => nil,
138
+ :use_dhcp_assigned_default_route => false
110
139
  }.merge(options || {})
111
140
  end
112
141
 
@@ -175,24 +204,40 @@ module VagrantPlugins
175
204
 
176
205
  # Given the choice we can now define the adapter we're using
177
206
  return {
178
- :adapter => config[:adapter],
179
- :type => :bridged,
180
- :bridge => chosen_bridge[:name],
181
- :bound_to => chosen_bridge[:bound_to],
182
- :mac_address => config[:mac],
183
- :dhcp => config[:dhcp],
184
- :ip => config[:ip],
185
- :netmask => config[:netmask],
186
- :nic_type => config[:nic_type]
207
+ :adapter => config[:adapter],
208
+ :type => :bridged,
209
+ :bridge => chosen_bridge[:name],
210
+ :bound_to => chosen_bridge[:bound_to],
211
+ :mac_address => config[:mac],
212
+ :nic_type => config[:nic_type]
213
+ }
214
+ end
215
+
216
+ def bridged_network_config(config)
217
+ if config[:ip]
218
+ options = {
219
+ :auto_config => true,
220
+ :mac => nil,
221
+ :netmask => "255.255.255.0",
222
+ :type => :static
223
+ }.merge(config)
224
+ options[:type] = options[:type].to_sym
225
+ return options
226
+ end
227
+
228
+ return {
229
+ :type => :dhcp,
230
+ :use_dhcp_assigned_default_route => config[:use_dhcp_assigned_default_route]
187
231
  }
188
232
  end
189
233
 
190
234
  def hostonly_config(options)
191
235
  options = {
192
- :mac => nil,
193
- :nic_type => "e1000",
194
- :netmask => "255.255.255.0",
195
- :type => :static
236
+ :auto_config => true,
237
+ :mac => nil,
238
+ :nic_type => nil,
239
+ :netmask => "255.255.255.0",
240
+ :type => :static
196
241
  }.merge(options)
197
242
 
198
243
  # Make sure the type is a symbol
@@ -229,14 +274,14 @@ module VagrantPlugins
229
274
  dhcp_options = {}
230
275
  if options[:type] == :dhcp
231
276
  # Calculate the DHCP server IP, which is the network address
232
- # with the final octet + 2. So "172.28.0.0" turns into "172.28.0.2"
277
+ # with the final octet + 1. So "172.28.0.0" turns into "172.28.0.1"
233
278
  dhcp_ip = ip_parts.dup
234
- dhcp_ip[3] += 2
279
+ dhcp_ip[3] += 1
235
280
  dhcp_options[:dhcp_ip] ||= dhcp_ip.join(".")
236
281
 
237
282
  # Calculate the lower and upper bound for the DHCP server
238
283
  dhcp_lower = ip_parts.dup
239
- dhcp_lower[3] += 3
284
+ dhcp_lower[3] += 2
240
285
  dhcp_options[:dhcp_lower] ||= dhcp_lower.join(".")
241
286
 
242
287
  dhcp_upper = ip_parts.dup
@@ -245,12 +290,13 @@ module VagrantPlugins
245
290
  end
246
291
 
247
292
  return {
248
- :adapter_ip => options[:adapter_ip],
249
- :ip => options[:ip],
250
- :mac => options[:mac],
251
- :netmask => options[:netmask],
252
- :nic_type => options[:nic_type],
253
- :type => options[:type],
293
+ :adapter_ip => options[:adapter_ip],
294
+ :auto_config => options[:auto_config],
295
+ :ip => options[:ip],
296
+ :mac => options[:mac],
297
+ :netmask => options[:netmask],
298
+ :nic_type => options[:nic_type],
299
+ :type => options[:type]
254
300
  }.merge(dhcp_options)
255
301
  end
256
302
 
@@ -273,35 +319,78 @@ module VagrantPlugins
273
319
  end
274
320
 
275
321
  return {
276
- :adapter => config[:adapter],
277
- :hostonly => interface[:name],
278
- :bound_to => interface[:bound_to],
279
- :mac => config[:mac],
280
- :nic_type => config[:nic_type],
281
- :type => :hostonly,
282
- :dhcp => interface[:dhcp],
283
- :ip => config[:ip],
284
- :netmask => config[:netmask],
322
+ :adapter => config[:adapter],
323
+ :hostonly => interface[:name],
324
+ :bound_to => interface[:bound_to],
325
+ :mac => config[:mac],
326
+ :nic_type => config[:nic_type],
327
+ :type => :hostonly
285
328
  }
286
329
  end
287
330
 
331
+ def hostonly_network_config(config)
332
+ return {
333
+ :type => config[:type],
334
+ :adapter_ip => config[:adapter_ip],
335
+ :ip => config[:ip],
336
+ :netmask => config[:netmask]
337
+ }
338
+ end
339
+
340
+
288
341
  def shared_config(options)
289
- return {}
342
+ return {
343
+ :auto_config => false
344
+ }
290
345
  end
291
346
 
292
347
  def shared_adapter(config)
293
348
  return {
294
- :adapter => config[:adapter],
295
- :shared => "Shared",
296
- :type => :shared,
297
- :dhcp => true,
298
- :nic_type => "e1000"
349
+ :adapter => config[:adapter],
350
+ :type => :shared
299
351
  }
300
352
  end
301
353
 
354
+ def shared_network_config(config)
355
+ return {}
356
+ end
357
+
302
358
  #-----------------------------------------------------------------
303
359
  # Misc. helpers
304
360
  #-----------------------------------------------------------------
361
+ # Assigns the actual interface number of a network based on the
362
+ # enabled NICs on the virtual machine.
363
+ #
364
+ # This interface number is used by the guest to configure the
365
+ # NIC on the guest VM.
366
+ #
367
+ # The networks are modified in place by adding an ":interface"
368
+ # field to each.
369
+ def assign_interface_numbers(networks, adapters)
370
+ current = 0
371
+ adapter_to_interface = {}
372
+
373
+ # Make a first pass to assign interface numbers by adapter location
374
+ vm_adapters = @env[:machine].provider.driver.read_network_interfaces
375
+ vm_adapters.sort.each do |number, adapter|
376
+ if adapter[:type] != :none
377
+ # Not used, so assign the interface number and increment
378
+ adapter_to_interface[number] = current
379
+ current += 1
380
+ end
381
+ end
382
+
383
+ # Make a pass through the adapters to assign the :interface
384
+ # key to each network configuration.
385
+ adapters.each_index do |i|
386
+ adapter = adapters[i]
387
+ network = networks[i]
388
+
389
+ # Figure out the interface number by simple lookup
390
+ network[:interface] = adapter_to_interface[adapter[:adapter]]
391
+ end
392
+ end
393
+
305
394
  # This determines the next free network name
306
395
  def next_network_name
307
396
  # Get the list of numbers