add simple host aliases implementation and configuration options validation
This commit is contained in:
parent
655612b9f6
commit
0d7ecf5f4a
|
@ -3,16 +3,45 @@ module VagrantPlugins
|
||||||
class Config < Vagrant.plugin('2', :config)
|
class Config < Vagrant.plugin('2', :config)
|
||||||
attr_accessor :auto_update
|
attr_accessor :auto_update
|
||||||
attr_accessor :ignore_private_ip
|
attr_accessor :ignore_private_ip
|
||||||
|
attr_accessor :aliases
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@auto_update = UNSET_VALUE
|
@auto_update = UNSET_VALUE
|
||||||
@ignore_private_ip = UNSET_VALUE
|
@ignore_private_ip = UNSET_VALUE
|
||||||
|
@aliases = Array.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
@auto_update = true if @auto_update == UNSET_VALUE
|
@auto_update = true if @auto_update == UNSET_VALUE
|
||||||
@ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
|
@ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate(machine)
|
||||||
|
errors = Array.new
|
||||||
|
|
||||||
|
# check if auto_update option is defined in Vagrantfile
|
||||||
|
# and check if is either true or false accordingly
|
||||||
|
if (machine.config.hostmanager.auto_update &&
|
||||||
|
![TrueClass, FalseClass].include?(auto_update.class))
|
||||||
|
errors << "A value for hostmanager.auto_update can be true or false."
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if ignore_private_ip option is defined in Vagrantfile
|
||||||
|
# and check if is either true or false accordingly
|
||||||
|
if (machine.config.hostmanager.ignore_private_ip &&
|
||||||
|
![TrueClass, FalseClass].include?(ignore_private_ip.class))
|
||||||
|
errors << "A value for hostmanager.ignore_private_ip can be true or false."
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if aliases option is defined in Vagrantfile
|
||||||
|
# and check if is an Array accordingly
|
||||||
|
if (machine.config.hostmanager.aliases &&
|
||||||
|
!machine.config.hostmanager.aliases.kind_of?(Array))
|
||||||
|
errors << "A value for hostmanager.aliases must be an Array."
|
||||||
|
end
|
||||||
|
|
||||||
|
{ "HostManager configuration" => errors }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,8 +31,9 @@ module VagrantPlugins
|
||||||
machines << machine = env.machine(name, provider)
|
machines << machine = env.machine(name, provider)
|
||||||
host = machine.config.vm.hostname || name
|
host = machine.config.vm.hostname || name
|
||||||
ip = get_ip_address.call(machine)
|
ip = get_ip_address.call(machine)
|
||||||
@logger.info "Adding /etc/hosts entry: #{ip} #{host}"
|
host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
|
||||||
file << "#{ip}\t#{host}\n"
|
@logger.info "Adding /etc/hosts entry: #{ip} #{host} #{host_aliases}"
|
||||||
|
file << "#{ip}\t#{host}\s#{host_aliases}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue