Accept network interface MAC addresses without colon delimiters

Commonly found in other Vagrant providers, a MAC address format without
colon delimiters is now accepted for better cross-compatibility of
Vagrantfiles.
This commit is contained in:
Dominic Cleal
2017-05-16 14:20:44 +01:00
parent 7b968c7a72
commit 404c428036
2 changed files with 16 additions and 3 deletions

View File

@@ -674,8 +674,14 @@ module VagrantPlugins
end
machine.config.vm.networks.each do |_type, opts|
if opts[:mac] && opts[:mac].downcase! && !(opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/)
errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' format"
if opts[:mac]
opts[:mac].downcase!
if opts[:mac] =~ /\A([0-9a-f]{12})\z/
opts[:mac] = opts[:mac].scan(/../).join(':')
end
unless opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/
errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' or 'xxxxxxxxxxxx' format"
end
end
end