diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 19de0cd2c..70498bf56 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -107,9 +107,20 @@ module Vagrant # # @return [Object] def communicate - # For now, we always return SSH. In the future, we'll abstract - # this and allow plugins to define new methods of communication. + if !@communicator + # For now, we always return SSH. In the future, we'll abstract + # this and allow plugins to define new methods of communication. + Vagrant.plugin("1").registered.each do |plugin| + klass = plugin.communicator[:ssh] + if klass + # This plugin has the SSH communicator, use it. + @communicator = klass.new(self) + break + end + end + end + @communicator end # This sets the unique ID associated with this machine. This will diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index 1065168a5..a66ee3a33 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -14,8 +14,8 @@ module VagrantPlugins module CommunicatorSSH # This class provides communication with the VM via SSH. class Communicator < Vagrant.plugin("1", :communicator) - include Util::ANSIEscapeCodeRemover - include Util::Retryable + include Vagrant::Util::ANSIEscapeCodeRemover + include Vagrant::Util::Retryable def self.match?(machine) # All machines are currently expected to have SSH. diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 34adb75b5..eaf33ba2d 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -170,6 +170,17 @@ describe Vagrant::Machine do end end + describe "communicator" do + it "should always return the SSH communicator" do + instance.communicate.should be_kind_of(VagrantPlugins::CommunicatorSSH::Communicator) + end + + it "should memoize the result" do + obj = instance.communicate + instance.communicate.should eql(obj) + end + end + describe "setting the ID" do it "should not have an ID by default" do instance.id.should be_nil