Support include_offline boxes.
If include_offline is enabled, we loop over all available boxes picking those with the correct provider. If a box has no private ip set or is offline, it is skipped (a warning is shown). The lambda that gets the ip will return nil for the boxes.
This commit is contained in:
parent
0b3e60cb5d
commit
00b8e75a7d
|
@ -17,7 +17,7 @@ module VagrantPlugins
|
|||
next if ip
|
||||
end
|
||||
end
|
||||
ip || machine.ssh_info[:host]
|
||||
ip || (machine.ssh_info ? machine.ssh_info[:host] : nil)
|
||||
end
|
||||
|
||||
# create the temporary hosts file
|
||||
|
@ -29,17 +29,22 @@ module VagrantPlugins
|
|||
machines << machine = env.machine(name, provider)
|
||||
host = machine.config.vm.hostname || name
|
||||
ip = get_ip_address.call(machine)
|
||||
host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
|
||||
machine.env.ui.info I18n.t('vagrant_hostmanager.action.add_host', {
|
||||
:ip => ip,
|
||||
:host => host,
|
||||
:aliases => host_aliases,
|
||||
})
|
||||
file << "#{ip}\t#{host}\s#{host_aliases}\n"
|
||||
if ip
|
||||
host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
|
||||
machine.env.ui.info I18n.t('vagrant_hostmanager.action.add_host', {
|
||||
:ip => ip,
|
||||
:host => host,
|
||||
:aliases => host_aliases,
|
||||
})
|
||||
file << "#{ip}\t#{host}\s#{host_aliases}\n"
|
||||
else
|
||||
machine.env.ui.warn I18n.t('vagrant_hostmanager.action.host_no_ip', {
|
||||
:name => name,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
machines
|
||||
end
|
||||
|
||||
|
@ -57,10 +62,26 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
private
|
||||
# Either use the active machines, or loop over all available machines and
|
||||
# get those with the same provider (aka, ignore boxes that throw MachineNotFound errors).
|
||||
#
|
||||
# Returns an array with the same structure as env.active_machines:
|
||||
# [ [:machine, :virtualbox], [:foo, :virtualbox] ]
|
||||
def get_machines(env, provider)
|
||||
env.active_machines
|
||||
if env.config_global.hostmanager.include_offline?
|
||||
machines = []
|
||||
env.machine_names.each do |name|
|
||||
begin
|
||||
m = env.machine(name, provider)
|
||||
machines << [name, provider]
|
||||
rescue Vagrant::Errors::MachineNotFound => ex
|
||||
# ignore this box.
|
||||
end
|
||||
end
|
||||
machines
|
||||
else
|
||||
env.active_machines
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ en:
|
|||
vagrant_hostmanager:
|
||||
action:
|
||||
add_host: "Adding /etc/hosts entry: %{ip} %{host} %{aliases}"
|
||||
host_no_ip: "Could not determine ip for machine '%{name}': no private ip configured or machine not up."
|
||||
update: "[%{name}] Updating /etc/hosts file"
|
||||
config:
|
||||
not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
|
||||
|
|
Loading…
Reference in New Issue