Module: VagrantPlugins::MultiHostManager::HostsFile
- Included in:
- Action::UpdateAll, Action::UpdateGuest, Action::UpdateHost, Command, Provisioner
- Defined in:
- lib/vagrant-multihostmanager/hosts_file.rb
Defined Under Namespace
Modules: WindowsSupport
Instance Method Summary collapse
Instance Method Details
#update_guest(machine) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant-multihostmanager/hosts_file.rb', line 6 def update_guest(machine) return unless machine.communicate.ready? if (machine.communicate.test("uname -s | grep SunOS")) realhostfile = '/etc/inet/hosts' move_cmd = 'mv' elsif (machine.communicate.test("test -d $Env:SystemRoot")) realhostfile = "#{ENV['WINDIR']}\\System32\\drivers\\etc\\hosts" move_cmd = 'mv -force' else realhostfile = '/etc/hosts' move_cmd = 'mv' end # download and modify file with Vagrant-managed entries file = @global_env.tmp_path.join("hosts.#{machine.name}") machine.communicate.download(realhostfile, file) update_file(file) # upload modified file and remove temporary file machine.communicate.upload(file, '/tmp/hosts') machine.communicate.sudo("#{move_cmd} /tmp/hosts #{realhostfile}") # i have no idea if this is a windows competibility issue or not, but sometimes it dosen't work on my machine begin FileUtils.rm(file) rescue Exception => e end end |
#update_host ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vagrant-multihostmanager/hosts_file.rb', line 34 def update_host # copy and modify hosts file on host with Vagrant-managed entries file = @global_env.tmp_path.join('hosts.local') if WindowsSupport.windows? # lazily include windows Module class << self include WindowsSupport unless include? WindowsSupport end hosts_location = "#{ENV['WINDIR']}\\System32\\drivers\\etc\\hosts" copy_proc = Proc.new { windows_copy_file(file, hosts_location) } else hosts_location = '/etc/hosts' copy_proc = Proc.new { `sudo cp #{file} #{hosts_location}` } end FileUtils.cp(hosts_location, file) update_file(file) copy_proc.call end |