diff --git a/lib/vagrant/plugin/remote/communicator.rb b/lib/vagrant/plugin/remote/communicator.rb index d8b280e26..120fcd825 100644 --- a/lib/vagrant/plugin/remote/communicator.rb +++ b/lib/vagrant/plugin/remote/communicator.rb @@ -6,11 +6,15 @@ module Vagrant # when applied to the Communicator class attr_accessor :client - def initialize(machine) + def initialize(machine, **kwargs) @logger = Log4r::Logger.new("vagrant::remote::communicator") @logger.debug("initializing communicator with remote backend") @machine = machine - @client = machine.client.communicate + @client = kwargs.fetch(:client, machine.client.communicate) + if @client.nil? + raise ArgumentError, + "Remote client is required for `#{self.class.name}`" + end end def ready? diff --git a/lib/vagrant/plugin/remote/guest.rb b/lib/vagrant/plugin/remote/guest.rb index 6492d17d1..0afc5fcc6 100644 --- a/lib/vagrant/plugin/remote/guest.rb +++ b/lib/vagrant/plugin/remote/guest.rb @@ -1,23 +1,22 @@ module Vagrant module Plugin module Remote - class Guest - # This module enables Guest for server mode - module Remote + class Guest < V2::Guest + attr_accessor :client - # Add an attribute accesor for the client - # when applied to the Guest class - def self.prepended(klass) - klass.class_eval do - attr_accessor :client - end + def initialize(*_, **kwargs) + @client = kwargs.delete(:client) + if @client.nil? + raise ArgumentError, + "Remote client is required for `#{self.class.name}`" end + super + end - # @return [Boolean] - def detect?(machine) - client = machine.client.guest - client.detect(machine) - end + # @return [Boolean] + def detect?(machine) + client = machine.client.guest + client.detect(machine) end end end diff --git a/lib/vagrant/plugin/remote/provider.rb b/lib/vagrant/plugin/remote/provider.rb index 48c91f266..d889e6aa8 100644 --- a/lib/vagrant/plugin/remote/provider.rb +++ b/lib/vagrant/plugin/remote/provider.rb @@ -24,8 +24,7 @@ module Vagrant raise ArgumentError, "Remote client is required for `#{self.class.name}`" end - @client = opts[:client] - super(machine) + @client = opts.delete(:client) end def action(name)