Sha256: 2348b7bc88ea34cb2dbb69e4d1c7cf4c419a4d7b737089b93dcb9fa2d687c4c4
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
module VagrantHosts::Addresses private def all_hosts(config) all_hosts = [] all_hosts += local_hosts(@machine) if config.autoconfigure all_hosts += vagrant_hosts(@env) end all_hosts += config.hosts all_hosts end # Builds an array containing hostname and aliases for a given machine. def hostnames_for_machine(machine) # Cast any Symbols to Strings machine_name = machine.name.to_s hostname = machine.config.vm.hostname || machine_name hostnames = [hostname] # If the hostname is a fqdn, add the first component as an alias. hostnames << hostname.split('.').first if hostname.index('.') # Also add the machine name as an alias. hostnames << machine_name unless hostnames.include? machine_name hostnames end def local_hosts(machine) [ ['127.0.0.1', ['localhost']], ['127.0.1.1', hostnames_for_machine(machine)], ] end def vagrant_hosts(env) hosts = [] all_machines(env).each do |m| m.config.vm.networks.each do |(net_type, opts)| next unless net_type == :private_network addr = opts[:ip] hosts << [addr, hostnames_for_machine(m)] end end hosts end # @return [Array<Vagrant::Machine>] def all_machines(env) env.active_machines.map do |vm_id| begin env.machine(*vm_id) rescue Vagrant::Errors::MachineNotFound nil end end.compact end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vagrant-hosts-2.1.5 | lib/vagrant-hosts/addresses.rb |