vagrant-parallels 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d138c790174855049184943ea5dada1b980eee3755f88f5e20059a2851fb2aa9
4
- data.tar.gz: 277e1c323a916c085f4b45fed9ede685b1587246ace3e703a89b33038b59147f
3
+ metadata.gz: f4af52807cb579f4b1f18957178a8230186a4c0305bef6777879a05f48a4e26b
4
+ data.tar.gz: 130d7a27229008dbb74188269acb846199fe8001f0cb6e7694a954dc10316ddc
5
5
  SHA512:
6
- metadata.gz: ee07c96b1a45d301d37b2c633e71ac176ca4859cf40d92cfd772d5549892a1edb64a74897270d9819f2ea0fe3f9a2a3916a447a65b60fd084100e06bcf86ef45
7
- data.tar.gz: b963b62e1d1b86e89eb7d78c088881a9ae399fb529928fdb030ba921cd0d32f9b660529e160b1bb8f229d077fcc2a71df4cb90518f4a067e7fe2269447ed96dd
6
+ metadata.gz: 61c6ff36e06913bdca908f225357c3f250b8f27c06659145c6f8285d4a836e673d2f4b8ebc9aed62929ca34de1564a73992e1e6b5e3b9754c4f8c42cfabf8649
7
+ data.tar.gz: 619bbae811769347eef8580f2ef1781e708eeb5a5c59a429d0a509ba09aa37ab1bc584837ca97e7ddad8550ec35c766a1a242a7187ecdf89b5b2990f799821a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 2.2.3 (July 14, 2021)
2
+ BUG FIXES:
3
+ - Fixed the compatibility with Vagrant 2.2.17
4
+ [[GH-399](https://github.com/Parallels/vagrant-parallels/pull/399)]
5
+
1
6
  ## 2.2.2 (June 23, 2021)
2
7
  BUG FIXES:
3
8
  - Fixed shared folder mount on the VM reboot
@@ -5,7 +5,7 @@ module VagrantPlugins
5
5
  include VagrantPlugins::Parallels::Util::CompileForwardedPorts
6
6
  @@lock = Mutex.new
7
7
 
8
- def initialize(app, env)
8
+ def initialize(app, _env)
9
9
  @app = app
10
10
  end
11
11
 
@@ -22,17 +22,15 @@ module VagrantPlugins
22
22
  return @app.call(env) if env[:forwarded_ports].empty?
23
23
 
24
24
  # Acquire both of class- and process-level locks so that we don't
25
- # forward ports simultaneousely with someone else.
25
+ # forward ports simultaneously with someone else.
26
26
  @@lock.synchronize do
27
- begin
28
- env[:machine].env.lock('forward_ports') do
29
- env[:ui].output(I18n.t('vagrant.actions.vm.forward_ports.forwarding'))
30
- forward_ports
31
- end
32
- rescue Errors::EnvironmentLockedError
33
- sleep 1
34
- retry
27
+ env[:machine].env.lock('forward_ports') do
28
+ env[:ui].output(I18n.t('vagrant.actions.vm.forward_ports.forwarding'))
29
+ forward_ports
35
30
  end
31
+ rescue Vagrant::Errors::EnvironmentLockedError
32
+ sleep 1
33
+ retry
36
34
  end
37
35
 
38
36
  @app.call(env)
@@ -46,7 +44,9 @@ module VagrantPlugins
46
44
  @env[:forwarded_ports].each do |fp|
47
45
  message_attributes = {
48
46
  guest_port: fp.guest_port,
49
- host_port: fp.host_port
47
+ guest_ip: fp.guest_ip,
48
+ host_port: fp.host_port,
49
+ host_ip: fp.host_ip
50
50
  }
51
51
 
52
52
  # Assuming the only reason to establish port forwarding is
@@ -54,7 +54,7 @@ module VagrantPlugins
54
54
  # bridged networking don't require port-forwarding and establishing
55
55
  # forwarded ports on these attachment types has uncertain behaviour.
56
56
  @env[:ui].detail(I18n.t('vagrant_parallels.actions.vm.forward_ports.forwarding_entry',
57
- message_attributes))
57
+ **message_attributes))
58
58
 
59
59
  # In Parallels Desktop the scope port forwarding rules is global,
60
60
  # so we have to keep their names unique.
@@ -69,14 +69,16 @@ module VagrantPlugins
69
69
 
70
70
  # Add the options to the ports array to send to the driver later
71
71
  ports << {
72
- guestport: fp.guest_port,
73
- hostport: fp.host_port,
74
- name: unique_id,
75
- protocol: fp.protocol
72
+ guest_port: fp.guest_port,
73
+ guest_ip: fp.guest_ip,
74
+ host_port: fp.host_port,
75
+ host_ip: fp.host_ip,
76
+ name: unique_id,
77
+ protocol: fp.protocol
76
78
  }
77
79
  end
78
80
 
79
- if !ports.empty?
81
+ unless ports.empty?
80
82
  # We only need to forward ports if there are any to forward
81
83
  @env[:machine].provider.driver.forward_ports(ports)
82
84
  end
@@ -16,7 +16,7 @@ module VagrantPlugins
16
16
  include Vagrant::Util::ScopedHashOverride
17
17
  @@lock = Mutex.new
18
18
 
19
- def initialize(app, env)
19
+ def initialize(app, _env)
20
20
  @app = app
21
21
  @logger = Log4r::Logger.new('vagrant_parallels::action::network')
22
22
  end
@@ -44,20 +44,20 @@ module VagrantPlugins
44
44
 
45
45
  # Figure out the slot that this adapter will go into
46
46
  slot = options[:adapter]
47
- if !slot
48
- if available_slots.empty?
49
- raise VagrantPlugins::Parallels::Errors::ParallelsNoRoomForHighLevelNetwork
50
- end
47
+ unless slot
48
+ raise VagrantPlugins::Parallels::Errors::ParallelsNoRoomForHighLevelNetwork if available_slots.empty?
51
49
 
52
50
  slot = available_slots.shift
53
51
  end
54
52
 
55
53
  # Configure it
56
54
  data = nil
57
- if type == :private_network
55
+ #noinspection RubyCaseWithoutElseBlockInspection
56
+ case type
57
+ when :private_network
58
58
  # private_network = hostonly
59
59
  data = [:hostonly, options]
60
- elsif type == :public_network
60
+ when :public_network
61
61
  # public_network = bridged
62
62
  data = [:bridged, options]
63
63
  end
@@ -103,16 +103,15 @@ module VagrantPlugins
103
103
  networks << network
104
104
  end
105
105
 
106
- if !adapters.empty?
106
+ unless adapters.empty?
107
107
  # Enable the adapters
108
108
  @logger.info('Enabling adapters...')
109
109
  env[:ui].output(I18n.t('vagrant.actions.vm.network.preparing'))
110
110
  adapters.each do |adapter|
111
- env[:ui].detail(I18n.t(
112
- 'vagrant_parallels.parallels.network_adapter',
113
- adapter: adapter[:adapter].to_s,
114
- type: adapter[:type].to_s,
115
- extra: '',
111
+ env[:ui].detail(I18n.t('vagrant_parallels.parallels.network_adapter',
112
+ adapter: adapter[:adapter].to_s,
113
+ type: adapter[:type].to_s,
114
+ extra: '',
116
115
  ))
117
116
  end
118
117
 
@@ -124,12 +123,12 @@ module VagrantPlugins
124
123
 
125
124
  # If we have networks to configure, then we configure it now, since
126
125
  # that requires the machine to be up and running.
127
- if !adapters.empty? && !networks.empty?
126
+ unless adapters.empty? && networks.empty?
128
127
  assign_interface_numbers(networks, adapters)
129
128
 
130
129
  # Only configure the networks the user requested us to configure
131
130
  networks_to_configure = networks.select { |n| n[:auto_config] }
132
- if !networks_to_configure.empty?
131
+ unless networks_to_configure.empty?
133
132
  env[:ui].info I18n.t('vagrant.actions.vm.network.configuring')
134
133
  env[:machine].guest.capability(:configure_networks, networks_to_configure)
135
134
  end
@@ -138,10 +137,10 @@ module VagrantPlugins
138
137
 
139
138
  def bridged_config(options)
140
139
  {
141
- auto_config: true,
142
- bridge: nil,
143
- mac: nil,
144
- nic_type: nil,
140
+ auto_config: true,
141
+ bridge: nil,
142
+ mac: nil,
143
+ nic_type: nil,
145
144
  use_dhcp_assigned_default_route: false
146
145
  }.merge(options || {})
147
146
  end
@@ -162,17 +161,17 @@ module VagrantPlugins
162
161
  Array(config[:bridge]).each do |bridge|
163
162
  bridge = bridge.downcase if bridge.respond_to?(:downcase)
164
163
  bridgedifs.each do |interface|
165
- if bridge === interface[:name].downcase
166
- @logger.debug('Specific bridge found as configured in the Vagrantfile. Using it.')
167
- chosen_bridge = interface[:name]
168
- break
169
- end
164
+ next unless bridge === interface[:name].downcase
165
+
166
+ @logger.debug('Specific bridge found as configured in the Vagrantfile. Using it.')
167
+ chosen_bridge = interface[:name]
168
+ break
170
169
  end
171
170
  break if chosen_bridge
172
171
  end
173
172
 
174
173
  # If one wasn't found, then we notify the user here.
175
- if !chosen_bridge
174
+ unless chosen_bridge
176
175
  @env[:ui].info I18n.t(
177
176
  'vagrant.actions.vm.bridged_networking.specific_not_found',
178
177
  bridge: config[:bridge])
@@ -183,7 +182,7 @@ module VagrantPlugins
183
182
  # specified in the Vagrantfile, or the bridge specified in the Vagrantfile
184
183
  # wasn't found), then we fall back to the normal means of searching for a
185
184
  # bridged network.
186
- if !chosen_bridge
185
+ unless chosen_bridge
187
186
  if bridgedifs.length == 1
188
187
  # One bridgable interface? Just use it.
189
188
  chosen_bridge = bridgedifs[0][:name]
@@ -197,15 +196,14 @@ module VagrantPlugins
197
196
  interface = bridgedifs[index]
198
197
  @env[:ui].info("#{index + 1}) #{interface[:name]}", prefix: false)
199
198
  end
200
- @env[:ui].info(I18n.t(
201
- 'vagrant.actions.vm.bridged_networking.choice_help')+"\n")
199
+ @env[:ui].info("#{I18n.t('vagrant.actions.vm.bridged_networking.choice_help')}\n")
202
200
 
203
201
  # The range of valid choices
204
202
  valid = Range.new(1, bridgedifs.length)
205
203
 
206
204
  # The choice that the user has chosen as the bridging interface
207
205
  choice = nil
208
- while !valid.include?(choice)
206
+ until valid.include?(choice)
209
207
  choice = @env[:ui].ask(
210
208
  'Which interface should the network bridge to? Enter a number: ')
211
209
  choice = choice.to_i
@@ -219,11 +217,11 @@ module VagrantPlugins
219
217
 
220
218
  # Given the choice we can now define the adapter we're using
221
219
  {
222
- adapter: config[:adapter],
223
- type: :bridged,
224
- bridge: chosen_bridge,
220
+ adapter: config[:adapter],
221
+ type: :bridged,
222
+ bridge: chosen_bridge,
225
223
  mac_address: config[:mac],
226
- nic_type: config[:nic_type]
224
+ nic_type: config[:nic_type]
227
225
  }
228
226
  end
229
227
 
@@ -231,16 +229,16 @@ module VagrantPlugins
231
229
  if config[:ip]
232
230
  options = {
233
231
  auto_config: true,
234
- mac: nil,
235
- netmask: '255.255.255.0',
236
- type: :static
232
+ mac: nil,
233
+ netmask: '255.255.255.0',
234
+ type: :static
237
235
  }.merge(config)
238
236
  options[:type] = options[:type].to_sym
239
237
  return options
240
238
  end
241
239
 
242
240
  {
243
- type: :dhcp,
241
+ type: :dhcp,
244
242
  use_dhcp_assigned_default_route: config[:use_dhcp_assigned_default_route]
245
243
  }
246
244
  end
@@ -248,10 +246,10 @@ module VagrantPlugins
248
246
  def hostonly_config(options)
249
247
  options = {
250
248
  auto_config: true,
251
- mac: nil,
252
- name: nil,
253
- nic_type: nil,
254
- type: :static
249
+ mac: nil,
250
+ name: nil,
251
+ nic_type: nil,
252
+ type: :static
255
253
  }.merge(options)
256
254
 
257
255
  # Make sure the type is a symbol
@@ -290,13 +288,14 @@ module VagrantPlugins
290
288
  # network interface.
291
289
  @env[:machine].provider.driver.read_bridged_interfaces.each do |interface|
292
290
  next if interface[:status] == 'Down'
291
+
293
292
  that_netaddr = IPAddr.new("#{interface[:ip]}/#{interface[:netmask]}")
294
- if netaddr.include? that_netaddr
295
- raise VagrantPlugins::Parallels::Errors::NetworkCollision,
296
- hostonly_netaddr: netaddr,
297
- bridge_netaddr: that_netaddr,
298
- bridge_interface: interface[:name]
299
- end
293
+ next unless netaddr.include? that_netaddr
294
+
295
+ raise VagrantPlugins::Parallels::Errors::NetworkCollision,
296
+ hostonly_netaddr: netaddr,
297
+ bridge_netaddr: that_netaddr,
298
+ bridge_interface: interface[:name]
300
299
  end
301
300
  end
302
301
 
@@ -319,14 +318,14 @@ module VagrantPlugins
319
318
  end
320
319
 
321
320
  {
322
- adapter_ip: options[:adapter_ip],
321
+ adapter_ip: options[:adapter_ip],
323
322
  auto_config: options[:auto_config],
324
- ip: options[:ip],
325
- mac: options[:mac],
326
- name: options[:name],
327
- netmask: options[:netmask],
328
- nic_type: options[:nic_type],
329
- type: options[:type]
323
+ ip: options[:ip],
324
+ mac: options[:mac],
325
+ name: options[:name],
326
+ netmask: options[:netmask],
327
+ nic_type: options[:nic_type],
328
+ type: options[:type]
330
329
  }.merge(dhcp_options)
331
330
  end
332
331
 
@@ -334,7 +333,7 @@ module VagrantPlugins
334
333
  @logger.info("Searching for matching hostonly network: #{config[:ip]}")
335
334
  interface = hostonly_find_matching_network(config)
336
335
 
337
- if !interface
336
+ unless interface
338
337
  @logger.info('Network not found. Creating if we can.')
339
338
 
340
339
  # Create a new network
@@ -343,25 +342,25 @@ module VagrantPlugins
343
342
  end
344
343
 
345
344
  {
346
- adapter: config[:adapter],
347
- hostonly: interface[:name],
345
+ adapter: config[:adapter],
346
+ hostonly: interface[:name],
348
347
  mac_address: config[:mac],
349
- nic_type: config[:nic_type],
350
- type: :hostonly
348
+ nic_type: config[:nic_type],
349
+ type: :hostonly
351
350
  }
352
351
  end
353
352
 
354
353
  def hostonly_network_config(config)
355
354
  {
356
- type: config[:type],
355
+ type: config[:type],
357
356
  adapter_ip: config[:adapter_ip],
358
- ip: config[:ip],
359
- netmask: config[:netmask]
357
+ ip: config[:ip],
358
+ netmask: config[:netmask]
360
359
  }
361
360
  end
362
361
 
363
362
 
364
- def shared_config(options)
363
+ def shared_config(_options)
365
364
  {
366
365
  auto_config: false
367
366
  }
@@ -370,11 +369,11 @@ module VagrantPlugins
370
369
  def shared_adapter(config)
371
370
  {
372
371
  adapter: config[:adapter],
373
- type: :shared
372
+ type: :shared
374
373
  }
375
374
  end
376
375
 
377
- def shared_network_config(config)
376
+ def shared_network_config(_config)
378
377
  {}
379
378
  end
380
379
 
@@ -396,11 +395,11 @@ module VagrantPlugins
396
395
  # Make a first pass to assign interface numbers by adapter location
397
396
  vm_adapters = @env[:machine].provider.driver.read_network_interfaces
398
397
  vm_adapters.sort.each do |number, adapter|
399
- if adapter[:type] != :none
400
- # Not used, so assign the interface number and increment
401
- adapter_to_interface[number] = current
402
- current += 1
403
- end
398
+ next unless adapter[:type] != :none
399
+
400
+ # Not used, so assign the interface number and increment
401
+ adapter_to_interface[number] = current
402
+ current += 1
404
403
  end
405
404
 
406
405
  # Make a pass through the adapters to assign the :interface
@@ -419,9 +418,7 @@ module VagrantPlugins
419
418
  # Get the list of numbers
420
419
  net_nums = []
421
420
  @env[:machine].provider.driver.read_virtual_networks.each do |net|
422
- if net['Network ID'] =~ /^vagrant-vnet(\d+)$/
423
- net_nums << $1.to_i
424
- end
421
+ net_nums << $1.to_i if net['Network ID'] =~ /^vagrant-vnet(\d+)$/
425
422
  end
426
423
 
427
424
  if net_nums.empty?
@@ -440,12 +437,12 @@ module VagrantPlugins
440
437
  options = {
441
438
  network_id: config[:name] || next_network_id,
442
439
  adapter_ip: config[:adapter_ip],
443
- netmask: config[:netmask],
440
+ netmask: config[:netmask],
444
441
  }
445
442
 
446
443
  if config[:type] == :dhcp
447
444
  options[:dhcp] = {
448
- ip: config[:dhcp_ip],
445
+ ip: config[:dhcp_ip],
449
446
  lower: config[:dhcp_lower],
450
447
  upper: config[:dhcp_upper]
451
448
  }
@@ -27,11 +27,11 @@ module VagrantPlugins
27
27
  # This flag is used to keep track of interrupted state (SIGINT)
28
28
  @interrupted = false
29
29
 
30
- @prlctl_path = util_path('prlctl')
30
+ @prlctl_path = util_path('prlctl')
31
31
  @prlsrvctl_path = util_path('prlsrvctl')
32
32
  @prldisktool_path = util_path('prl_disk_tool')
33
33
 
34
- if !@prlctl_path
34
+ unless @prlctl_path
35
35
  # This means that Parallels Desktop was not found, so we raise this
36
36
  # error here.
37
37
  raise VagrantPlugins::Parallels::Errors::ParallelsNotDetected
@@ -60,9 +60,7 @@ module VagrantPlugins
60
60
  args.concat(["--nat-#{r[:protocol]}-del", r[:name]])
61
61
  end
62
62
 
63
- if !args.empty?
64
- execute_prlsrvctl('net', 'set', read_shared_network_id, *args)
65
- end
63
+ execute_prlsrvctl('net', 'set', read_shared_network_id, *args) unless args.empty?
66
64
  end
67
65
 
68
66
  # Clears the shared folders that have been set on the virtual machine.
@@ -78,7 +76,7 @@ module VagrantPlugins
78
76
  # @param [String] src_name Name or UUID of the source VM or template.
79
77
  # @param [<String => String>] options Options to clone virtual machine.
80
78
  # @return [String] UUID of the new VM.
81
- def clone_vm(src_name, options={})
79
+ def clone_vm(src_name, options = {})
82
80
  dst_name = "vagrant_temp_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}"
83
81
 
84
82
  args = ['clone', src_name, '--name', dst_name]
@@ -146,10 +144,10 @@ module VagrantPlugins
146
144
 
147
145
  # Return the details
148
146
  {
149
- name: options[:network_id],
150
- ip: options[:adapter_ip],
147
+ name: options[:network_id],
148
+ ip: options[:adapter_ip],
151
149
  netmask: options[:netmask],
152
- dhcp: options[:dhcp]
150
+ dhcp: options[:dhcp]
153
151
  }
154
152
  end
155
153
 
@@ -160,9 +158,7 @@ module VagrantPlugins
160
158
  # @return [String] ID of the created snapshot.
161
159
  def create_snapshot(uuid, snapshot_name)
162
160
  stdout = execute_prlctl('snapshot', uuid, '--name', snapshot_name)
163
- if stdout =~ /\{([\w-]+)\}/
164
- return Regexp.last_match(1)
165
- end
161
+ return Regexp.last_match(1) if stdout =~ /{([\w-]+)}/
166
162
 
167
163
  raise Errors::SnapshotIdNotDetected, stdout: stdout
168
164
  end
@@ -222,7 +218,7 @@ module VagrantPlugins
222
218
  # ['create-vm', 'add-vm', 'remove-vm', 'clone-vm']
223
219
  def disable_password_restrictions(acts)
224
220
  server_info = json { execute_prlsrvctl('info', '--json') }
225
- server_info.fetch('Require password to',[]).each do |act|
221
+ server_info.fetch('Require password to', []).each do |act|
226
222
  execute_prlsrvctl('set', '--require-pwd', "#{act}:off") if acts.include? act
227
223
  end
228
224
  end
@@ -251,34 +247,29 @@ module VagrantPlugins
251
247
 
252
248
  # Disable all previously existing adapters (except shared 'vnet0')
253
249
  existing_adapters.each do |adapter|
254
- if adapter != 'vnet0'
255
- execute_prlctl('set', @uuid, '--device-set', adapter, '--disable')
256
- end
250
+ execute_prlctl('set', @uuid, '--device-set', adapter, '--disable') if adapter != 'vnet0'
257
251
  end
258
252
 
259
253
  adapters.each do |adapter|
260
254
  args = []
261
255
  if existing_adapters.include? "net#{adapter[:adapter]}"
262
- args.concat(['--device-set',"net#{adapter[:adapter]}", '--enable'])
256
+ args.concat(['--device-set', "net#{adapter[:adapter]}", '--enable'])
263
257
  else
264
- args.concat(['--device-add', 'net'])
258
+ args.concat(%w[--device-add net])
265
259
  end
266
260
 
267
- if adapter[:type] == :hostonly
261
+ case adapter[:type]
262
+ when :hostonly
268
263
  args.concat(['--type', 'host', '--iface', adapter[:hostonly]])
269
- elsif adapter[:type] == :bridged
264
+ when :bridged
270
265
  args.concat(['--type', 'bridged', '--iface', adapter[:bridge]])
271
- elsif adapter[:type] == :shared
272
- args.concat(['--type', 'shared'])
266
+ when :shared
267
+ args.concat(%w[--type shared])
273
268
  end
274
269
 
275
- if adapter[:mac_address]
276
- args.concat(['--mac', adapter[:mac_address]])
277
- end
270
+ args.concat(['--mac', adapter[:mac_address]]) if adapter[:mac_address]
278
271
 
279
- if adapter[:nic_type]
280
- args.concat(['--adapter-type', adapter[:nic_type].to_s])
281
- end
272
+ args.concat(['--adapter-type', adapter[:nic_type].to_s]) if adapter[:nic_type]
282
273
 
283
274
  execute_prlctl('set', @uuid, *args)
284
275
  end
@@ -308,9 +299,9 @@ module VagrantPlugins
308
299
  protocol = options[:protocol] || 'tcp'
309
300
  pf_builder = [
310
301
  options[:name],
311
- options[:hostport],
302
+ options[:host_port],
312
303
  @uuid,
313
- options[:guestport]
304
+ options[:guest_port]
314
305
  ]
315
306
 
316
307
  args.concat(["--nat-#{protocol}-add", pf_builder.join(',')])
@@ -329,7 +320,7 @@ module VagrantPlugins
329
320
  snap_config = File.join(settings.fetch('Home'), 'Snapshots.xml')
330
321
 
331
322
  # There are no snapshots, exit
332
- return {} if !File.exist?(snap_config)
323
+ return {} unless File.exist?(snap_config)
333
324
 
334
325
  xml = Nokogiri::XML(File.read(snap_config))
335
326
  snapshots = {}
@@ -349,7 +340,7 @@ module VagrantPlugins
349
340
  end
350
341
 
351
342
  # Halts the virtual machine (pulls the plug).
352
- def halt(force=false)
343
+ def halt(force = false)
353
344
  args = ['stop', @uuid]
354
345
  args << '--kill' if force
355
346
  execute_prlctl(*args)
@@ -370,22 +361,18 @@ module VagrantPlugins
370
361
  info = {}
371
362
  ifconfig = execute('ifconfig', iface)
372
363
  # Assign default values
373
- info[:name] = iface
374
- info[:ip] = '0.0.0.0'
364
+ info[:name] = iface
365
+ info[:ip] = '0.0.0.0'
375
366
  info[:netmask] = '0.0.0.0'
376
- info[:status] = 'Down'
367
+ info[:status] = 'Down'
377
368
 
378
- if ifconfig =~ /(?<=inet\s)(\S*)/
379
- info[:ip] = $1.to_s
380
- end
369
+ info[:ip] = $1.to_s if ifconfig =~ /(?<=inet\s)(\S*)/
381
370
  if ifconfig =~ /(?<=netmask\s)(\S*)/
382
371
  # Netmask will be converted from hex to dec:
383
372
  # '0xffffff00' -> '255.255.255.0'
384
- info[:netmask] = $1.hex.to_s(16).scan(/../).each.map{|octet| octet.hex}.join('.')
385
- end
386
- if ifconfig =~ /\W(UP)\W/ and ifconfig !~ /(?<=status:\s)inactive$/
387
- info[:status] = 'Up'
373
+ info[:netmask] = $1.hex.to_s(16).scan(/../).each.map { |octet| octet.hex }.join('.')
388
374
  end
375
+ info[:status] = 'Up' if ifconfig =~ /\W(UP)\W/ and ifconfig !~ /(?<=status:\s)inactive$/
389
376
 
390
377
  bridged_ifaces << info
391
378
  end
@@ -406,7 +393,7 @@ module VagrantPlugins
406
393
  # @param [Boolean] global If true, returns all the rules on the host.
407
394
  # Otherwise only rules related to the context VM will be returned.
408
395
  # @return [Array<Symbol => String>]
409
- def read_forwarded_ports(global=false)
396
+ def read_forwarded_ports(global = false)
410
397
  all_rules = read_shared_interface[:nat]
411
398
 
412
399
  if global
@@ -426,21 +413,21 @@ module VagrantPlugins
426
413
  leases = {}
427
414
  begin
428
415
  File.open(leases_file).grep(/#{mac_addr}/) do |line|
429
- _, ip, exp, dur, _, _ = line.split /([\d.]*)="(\d*),(\d*),(\w*),(\w*)".*/
416
+ _, ip, exp, dur, = line.split /([\d.]*)="(\d*),(\d*),(\w*),(\w*)".*/
430
417
  leases[ip] = exp.to_i - dur.to_i
431
418
  end
432
419
  rescue Errno::EACCES
433
- raise Errors::DhcpLeasesNotAccessible, :leases_file => leases_file.to_s
420
+ raise Errors::DhcpLeasesNotAccessible, leases_file: leases_file.to_s
434
421
  rescue Errno::ENOENT
435
422
  # File does not exist
436
423
  # Perhaps, it is the fist start of Parallels Desktop
437
- return nil
424
+ return ''
438
425
  end
439
426
 
440
- return nil if leases.empty?
427
+ return '' if leases.empty?
441
428
 
442
429
  # Get the most resent lease and return an associated IP
443
- leases.sort_by { |_ip, lease_time| lease_time }.last.first
430
+ leases.max_by { |_ip, lease_time| lease_time }.first
444
431
  end
445
432
 
446
433
  # Returns path to the Parallels Tools ISO file.
@@ -449,21 +436,19 @@ module VagrantPlugins
449
436
  # @return [String] Path to the ISO.
450
437
  def read_guest_tools_iso_path(guest_os)
451
438
  guest_os = guest_os.to_sym
452
- iso_name ={
439
+ iso_name = {
453
440
  linux: 'prl-tools-lin.iso',
454
441
  darwin: 'prl-tools-mac.iso',
455
442
  windows: 'PTIAgent.exe'
456
443
  }
457
- return nil if !iso_name[guest_os]
444
+ return nil unless iso_name[guest_os]
458
445
 
459
- bundle_id = 'com.parallels.desktop.console'
446
+ bundle_id = 'com.parallels.desktop.console'
460
447
  bundle_path = execute('mdfind', "kMDItemCFBundleIdentifier == #{bundle_id}")
461
448
  iso_path = File.expand_path("./Contents/Resources/Tools/#{iso_name[guest_os]}",
462
449
  bundle_path.split("\n")[0])
463
450
 
464
- if !File.exist?(iso_path)
465
- raise Errors::ParallelsToolsIsoNotFound, :iso_path => iso_path
466
- end
451
+ raise Errors::ParallelsToolsIsoNotFound, iso_path: iso_path unless File.exist?(iso_path)
467
452
 
468
453
  iso_path
469
454
  end
@@ -478,7 +463,7 @@ module VagrantPlugins
478
463
  # @return [Symbol]
479
464
  def read_guest_tools_state
480
465
  state = read_settings.fetch('GuestTools', {}).fetch('state', nil)
481
- state = 'not_installed' if !state
466
+ state ||= 'not_installed'
482
467
  state.to_sym
483
468
  end
484
469
 
@@ -512,18 +497,18 @@ module VagrantPlugins
512
497
  end
513
498
 
514
499
  iface = {
515
- name: net_info['Network ID'],
500
+ name: net_info['Network ID'],
516
501
  status: 'Down'
517
502
  }
518
503
 
519
504
  adapter = net_info['Parallels adapter']
520
505
  if adapter
521
- iface[:ip] = adapter['IPv4 address']
522
- iface[:netmask] = adapter['IPv4 subnet mask']
523
- iface[:status] = 'Up'
506
+ iface[:ip] = adapter['IPv4 address']
507
+ iface[:netmask] = adapter['IPv4 subnet mask']
508
+ iface[:status] = 'Up'
524
509
 
525
510
  if adapter['IPv6 address'] && adapter['IPv6 subnet mask']
526
- iface[:ipv6] = adapter['IPv6 address']
511
+ iface[:ipv6] = adapter['IPv6 address']
527
512
  iface[:ipv6_prefix] = adapter['IPv6 subnet mask']
528
513
  end
529
514
  end
@@ -542,9 +527,7 @@ module VagrantPlugins
542
527
  name.start_with?('net') && params['type'] == 'shared'
543
528
  end
544
529
 
545
- if shared_ifaces.empty?
546
- raise Errors::SharedInterfaceNotFound
547
- end
530
+ raise Errors::SharedInterfaceNotFound if shared_ifaces.empty?
548
531
 
549
532
  shared_ifaces.values.first.fetch('mac', nil)
550
533
  end
@@ -570,14 +553,15 @@ module VagrantPlugins
570
553
  adapter = name.match(/^net(\d+)$/)[1].to_i
571
554
  nics[adapter] ||= {}
572
555
 
573
- if params['type'] == 'shared'
556
+ case params['type']
557
+ when 'shared'
574
558
  nics[adapter][:type] = :shared
575
- elsif params['type'] == 'host'
559
+ when 'host'
576
560
  nics[adapter][:type] = :hostonly
577
- nics[adapter][:hostonly] = params.fetch('iface','')
578
- elsif params['type'] == 'bridged'
561
+ nics[adapter][:hostonly] = params.fetch('iface', '')
562
+ when 'bridged'
579
563
  nics[adapter][:type] = :bridged
580
- nics[adapter][:bridge] = params.fetch('iface','')
564
+ nics[adapter][:bridge] = params.fetch('iface', '')
581
565
  end
582
566
  end
583
567
  nics
@@ -586,8 +570,8 @@ module VagrantPlugins
586
570
  # Returns virtual machine settings
587
571
  #
588
572
  # @return [<String => String, Hash>]
589
- def read_settings(uuid=@uuid)
590
- vm = json { execute_prlctl('list', uuid, '--info', '--no-header', '--json') }
573
+ def read_settings(uuid = @uuid)
574
+ vm = json { execute_prlctl('list', uuid, '--info', '--no-header', '--json') }
591
575
  vm.last
592
576
  end
593
577
 
@@ -609,20 +593,20 @@ module VagrantPlugins
609
593
  end
610
594
 
611
595
  iface = {
612
- nat: [],
596
+ nat: [],
613
597
  status: 'Down'
614
598
  }
615
599
  adapter = net_info['Parallels adapter']
616
600
 
617
601
  if adapter
618
- iface[:ip] = adapter['IPv4 address']
619
- iface[:netmask] = adapter['IPv4 subnet mask']
620
- iface[:status] = 'Up'
602
+ iface[:ip] = adapter['IPv4 address']
603
+ iface[:netmask] = adapter['IPv4 subnet mask']
604
+ iface[:status] = 'Up'
621
605
  end
622
606
 
623
607
  if net_info.key?('DHCPv4 server')
624
608
  iface[:dhcp] = {
625
- ip: net_info['DHCPv4 server']['Server address'],
609
+ ip: net_info['DHCPv4 server']['Server address'],
626
610
  lower: net_info['DHCPv4 server']['IP scope start address'],
627
611
  upper: net_info['DHCPv4 server']['IP scope end address']
628
612
  }
@@ -631,10 +615,10 @@ module VagrantPlugins
631
615
  net_info['NAT server'].each do |group, rules|
632
616
  rules.each do |name, params|
633
617
  iface[:nat] << {
634
- name: name,
635
- protocol: group == 'TCP rules' ? 'tcp' : 'udp',
636
- guest: params['destination IP/VM id'],
637
- hostport: params['source port'],
618
+ name: name,
619
+ protocol: group == 'TCP rules' ? 'tcp' : 'udp',
620
+ guest: params['destination IP/VM id'],
621
+ hostport: params['source port'],
638
622
  guestport: params['destination port']
639
623
  }
640
624
  end
@@ -650,7 +634,7 @@ module VagrantPlugins
650
634
  def read_shared_folders
651
635
  shf_info = read_settings.fetch('Host Shared Folders', {})
652
636
  list = {}
653
- shf_info.delete_if { |k,v| k == 'enabled' }.each do |id, data|
637
+ shf_info.delete_if { |k, _v| k == 'enabled' }.each do |id, data|
654
638
  list[id] = data.fetch('path')
655
639
  end
656
640
 
@@ -686,11 +670,9 @@ module VagrantPlugins
686
670
  # @param [String] option Name of option (See all: `prlctl list -L`)
687
671
  # @param [String] uuid Virtual machine UUID
688
672
  # @return [String]
689
- def read_vm_option(option, uuid=@uuid)
690
- out = execute_prlctl('list', uuid,'--no-header', '-o', option).strip
691
- if out.empty?
692
- raise Errors::ParallelsVMOptionNotFound, vm_option: option
693
- end
673
+ def read_vm_option(option, uuid = @uuid)
674
+ out = execute_prlctl('list', uuid, '--no-header', '-o', option).strip
675
+ raise Errors::ParallelsVMOptionNotFound, vm_option: option if out.empty?
694
676
 
695
677
  out
696
678
  end
@@ -699,7 +681,7 @@ module VagrantPlugins
699
681
  #
700
682
  # @return [<String => String>]
701
683
  def read_vms
702
- args = %w(list --all --no-header --json -o name,uuid)
684
+ args = %w[list --all --no-header --json -o name,uuid]
703
685
  vms_arr = json { execute_prlctl(*args) }
704
686
  templates_arr = json { execute_prlctl(*args, '--template') }
705
687
 
@@ -711,7 +693,7 @@ module VagrantPlugins
711
693
  #
712
694
  # @return [Array <String => String>]
713
695
  def read_vms_info
714
- args = %w(list --all --info --no-header --json)
696
+ args = %w[list --all --info --no-header --json]
715
697
  vms_arr = json { execute_prlctl(*args) }
716
698
  templates_arr = json { execute_prlctl(*args, '--template') }
717
699
 
@@ -722,7 +704,7 @@ module VagrantPlugins
722
704
  #
723
705
  # @param [String] pvm_file Path to the machine image (*.pvm)
724
706
  # @param [Array<String>] opts List of options for "prlctl register"
725
- def register(pvm_file, opts=[])
707
+ def register(pvm_file, opts = [])
726
708
  execute_prlctl('register', pvm_file, *opts)
727
709
  end
728
710
 
@@ -823,7 +805,7 @@ module VagrantPlugins
823
805
 
824
806
  # Sometimes this happens. In this case, retry.
825
807
  # If we don't see this text, the VM really doesn't exist.
826
- return false if !result.stderr.include?('Login failed:')
808
+ return false unless result.stderr.include?('Login failed:')
827
809
 
828
810
  # Sleep a bit though to give Parallels Desktop time to fix itself
829
811
  sleep 2
@@ -861,8 +843,8 @@ module VagrantPlugins
861
843
  # If there was an error running command, show the error and the
862
844
  # output.
863
845
  raise VagrantPlugins::Parallels::Errors::ExecutionError,
864
- :command => command.inspect,
865
- :stderr => r.stderr
846
+ command: command.inspect,
847
+ stderr: r.stderr
866
848
  end
867
849
  end
868
850
  r.stdout
@@ -877,12 +859,10 @@ module VagrantPlugins
877
859
  JSON.parse(data)
878
860
  rescue JSON::JSONError
879
861
  # We retried already, raise the issue and be done
880
- if raise_error
881
- raise VagrantPlugins::Parallels::Errors::JSONParseError, data: data
882
- end
862
+ raise VagrantPlugins::Parallels::Errors::JSONParseError, data: data if raise_error
883
863
 
884
864
  # Remove garbage before/after json string[GH-204]
885
- data = data[/(\{.*\}|\[.*\])/m]
865
+ data = data[/({.*}|\[.*\])/m]
886
866
 
887
867
  # Remove all control characters unsupported by JSON [GH-219]
888
868
  data.tr!("\u0000-\u001f", '')
@@ -903,7 +883,7 @@ module VagrantPlugins
903
883
  end
904
884
 
905
885
  # Append in the options for subprocess
906
- command << {notify: [:stdout, :stderr]}
886
+ command << { notify: [:stdout, :stderr] }
907
887
 
908
888
  Vagrant::Util::Busy.busy(int_callback) do
909
889
  Vagrant::Util::Subprocess.execute(*command, &block)
@@ -29,14 +29,26 @@ module VagrantPlugins
29
29
  # @return [Integer]
30
30
  attr_reader :host_port
31
31
 
32
- def initialize(id, host_port, guest_port, options)
32
+ # The ip of the guest to be used for the port.
33
+ #
34
+ # @return [String]
35
+ attr_reader :guest_ip
36
+
37
+ # The ip of the host used to access the port.
38
+ #
39
+ # @return [String]
40
+ attr_reader :host_ip
41
+
42
+ def initialize(id, host_port, guest_port, host_ip, guest_ip, **options)
33
43
  @id = id
34
44
  @guest_port = guest_port
45
+ @guest_ip = guest_ip
35
46
  @host_port = host_port
47
+ @host_ip = host_ip
36
48
 
37
49
  options ||= {}
38
50
  @auto_correct = false
39
- @auto_correct = options[:auto_correct] if options.has_key?(:auto_correct)
51
+ @auto_correct = options[:auto_correct] if options.key?(:auto_correct)
40
52
  @protocol = options[:protocol] || 'tcp'
41
53
  end
42
54
 
@@ -12,23 +12,25 @@ module VagrantPlugins
12
12
  mappings = {}
13
13
 
14
14
  config.vm.networks.each do |type, options|
15
- if type == :forwarded_port
16
- guest_port = options[:guest]
17
- host_port = options[:host]
18
- protocol = options[:protocol] || 'tcp'
19
- options = scoped_hash_override(options, :parallels)
20
- id = options[:id]
21
-
22
- # If the forwarded port was marked as disabled, ignore.
23
- next if options[:disabled]
24
-
25
- # Temporary disable automatically pre-configured forwarded ports
26
- # for SSH, since it is working not so well [GH-146]
27
- next if id == 'ssh'
28
-
29
- mappings[host_port.to_s + protocol.to_s] =
30
- Model::ForwardedPort.new(id, host_port, guest_port, options)
31
- end
15
+ next unless type == :forwarded_port
16
+
17
+ guest_port = options[:guest]
18
+ guest_ip = options[:guest_ip]
19
+ host_port = options[:host]
20
+ host_ip = options[:host_ip]
21
+ protocol = options[:protocol] || 'tcp'
22
+ options = scoped_hash_override(options, :parallels)
23
+ id = options[:id]
24
+
25
+ # If the forwarded port was marked as disabled, ignore.
26
+ next if options[:disabled]
27
+
28
+ # Temporary disable automatically pre-configured forwarded ports
29
+ # for SSH, since it is working not so well [GH-146]
30
+ next if id == 'ssh'
31
+
32
+ mappings[host_port.to_s + protocol.to_s] =
33
+ Model::ForwardedPort.new(id, host_port, guest_port, host_ip, guest_ip, **options)
32
34
  end
33
35
 
34
36
  mappings.values
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Parallels
3
- VERSION = '2.2.2'
3
+ VERSION = '2.2.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-parallels
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Zholobov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-06-23 00:00:00.000000000 Z
12
+ date: 2021-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri