Sha256: 8ab30672da6b19c4df8c5963c72cd3beb4963cb76ea2559387efda2428e898fb
Contents?: true
Size: 1.21 KB
Versions: 4
Compression:
Stored size: 1.21 KB
Contents
require "log4r" require "digest" module VagrantPlugins module VagrantVmwareDhcp module Action class SetMac def initialize(app, env) @app = app @env = env @logger = Log4r::Logger.new("vagrant::plugins::vagrant-vmware-dhcp::set_mac") end def call(env) @env = env if @env[:machine] if (@env[:machine].provider_name == :vmware_fusion or @env[:machine].provider_name == :vmware_workstation) set_mac_address(@env) end end @app.call(@env) end private def set_mac_address(env) machine = env[:machine] networks = machine.config.vm.networks.select { |network| network[0] == :private_network and network[1][:ip] and not network[1][:mac] } networks.each { |network| network[1][:mac] = mac_from_ip(network[1][:ip]) } @logger.info("Added MAC addresses for #{networks}") end def mac_from_ip(ip) sha = Digest::SHA256.hexdigest ip # VMWare doesn't like odd values for the first octet. mac = "AA" + sha.scan(/.{10}/)[0] mac end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems