Class: VagrantPlugins::Utm::Action::MatchMACAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_utm/action/match_mac_address.rb

Overview

This action matches the MAC address of the virtual machine to the configured MAC address in the Vagrantfile. OR generates a new MAC address if none is set. This is useful to make sure that different virtual machines have different MAC addresses.

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ MatchMACAddress

Returns a new instance of MatchMACAddress.



15
16
17
# File 'lib/vagrant_utm/action/match_mac_address.rb', line 15

def initialize(app, _env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

rubocop:disable Metrics/AbcSize



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant_utm/action/match_mac_address.rb', line 19

def call(env) # rubocop:disable Metrics/AbcSize
  base_mac = env[:machine].config.vm.base_mac
  # If we have a base MAC address and not is empty (empty in some default Vagranfile)
  # then we use that to match
  if base_mac && !base_mac.empty?
    # Create the proc which we want to use to modify the virtual machine
    env[:ui].info I18n.t("vagrant.actions.vm.match_mac.matching")
    env[:machine].provider.driver.set_mac_address(env[:machine].config.vm.base_mac)
  else
    env[:ui].info I18n.t("vagrant.actions.vm.match_mac.generating")
    env[:machine].provider.driver.set_mac_address(nil)
  end

  @app.call(env)
end