From 6e4a2ae96761c930a3c0997a9e7b076b803888f0 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Mon, 6 May 2013 08:29:25 +0200 Subject: [PATCH] Abstract the get_machines part. Prepare for include offline. --- lib/vagrant-hostmanager/hosts_file.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-hostmanager/hosts_file.rb b/lib/vagrant-hostmanager/hosts_file.rb index d45d770..1a175d1 100644 --- a/lib/vagrant-hostmanager/hosts_file.rb +++ b/lib/vagrant-hostmanager/hosts_file.rb @@ -24,9 +24,7 @@ module VagrantPlugins path = env.tmp_path.join('hosts') File.open(path, 'w') do |file| file << "127.0.0.1\tlocalhost\slocalhost.localdomain\n" - - # add a hosts entry for each active machine matching the provider - env.active_machines.each do |name, p| + get_machines(env, provider).each do |name, p| if provider == p machines << machine = env.machine(name, provider) host = machine.config.vm.hostname || name @@ -57,6 +55,14 @@ module VagrantPlugins machine.communicate.sudo("mv /tmp/hosts /etc/hosts") end end + + private + # Returns an array with the same structure as env.active_machines: + # [ [:machine, :virtualbox], [:foo, :virtualbox] ] + def get_machines(env, provider) + env.active_machines + end + end end end