Ensure all remote plugins handle client setup

This commit is contained in:
Chris Roberts 2022-02-18 16:34:54 -08:00 committed by Paul Hinze
parent 7e9dad2b3e
commit 0ad82cf04a
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 20 additions and 18 deletions

View File

@ -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?

View File

@ -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

View File

@ -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)