Add provider remote plugin module

This commit is contained in:
sophia 2022-01-24 10:19:17 -06:00 committed by Paul Hinze
parent c48e43a12a
commit 809e4044a0
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
5 changed files with 79 additions and 14 deletions

View File

@ -6,6 +6,7 @@ module Vagrant
autoload :Communicator, "vagrant/plugin/remote/communicator"
autoload :Manager, "vagrant/plugin/remote/manager"
autoload :Plugin, "vagrant/plugin/remote/plugin"
autoload :Provider, "vagrant/plugin/remote/provider"
autoload :Push, "vagrant/plugin/remote/push"
autoload :SyncedFolder, "vagrant/plugin/remote/synced_folder"
end

View File

@ -15,7 +15,7 @@ module Vagrant
def initialize(machine)
@logger = Log4r::Logger.new("vagrant::remote::communicator")
@logger.debug("initializing communicator with remote baackend")
@logger.debug("initializing communicator with remote backend")
@machine = machine
@client = machine.client.communicate
end

View File

@ -163,20 +163,20 @@ module Vagrant
end
end
# def providers
# return real_manager.synced_folders if plugin_manager.nil?
def providers
return real_manager.synced_folders if plugin_manager.nil?
# Registry.new.tap do |result|
# plugin_manager.list_plugins(:provider).each do |plg|
# sf_class = Class.new(V2::Provider, &WRAPPER_CLASS)
# sf_class.plugin_name = plg[:name]
# sf_class.type = plg[:type]
# result.register(plg[:name].to_sym) do
# proc{sf_class}
# end
# end
# end
# end
Registry.new.tap do |result|
plugin_manager.list_plugins(:provider).each do |plg|
sf_class = Class.new(V2::Provider, &WRAPPER_CLASS)
sf_class.plugin_name = plg[:name]
sf_class.type = plg[:type]
result.register(plg[:name].to_sym) do
proc{sf_class}
end
end
end
end
# def provisioners
# return real_manager.synced_folders if plugin_manager.nil?

View File

@ -0,0 +1,63 @@
module Vagrant
module Plugin
module Remote
class Provider
# This module enables Provider for server mode
module Remote
# Add an attribute accesor for the client
# when applied to the Provider class
def self.prepended(klass)
klass.class_eval do
attr_accessor :client
end
end
def self.usable?(raise_error=false)
client.usable?
end
def self.installed?
client.installed?
end
def initialize(machine, **opts)
@logger = Log4r::Logger.new("vagrant::remote::provider")
@logger.debug("initializing provider with remote backend")
@machine = machine
if opts[:client].nil?
raise ArgumentError,
"Remote client is required for `#{self.class.name}`"
end
@client = opts[:client]
super(machine)
end
def action(name)
client.action(name)
end
def machine_id_changed
client.machine_id_changed
end
def ssh_info
client.ssh_info
end
def state
client.state
end
def initialize_capabilities!(*args, **opts)
# no-op
end
def to_proto
client.proto
end
end
end
end
end
end

View File

@ -269,6 +269,7 @@ module Vagrant
->{ Vagrant::MachineIndex::Entry.extend(Vagrant::MachineIndex::Entry::Remote::ClassMethods) },
->{ Vagrant::Plugin::V2::SyncedFolder.prepend(Vagrant::Plugin::Remote::SyncedFolder::Remote) },
->{ Vagrant::Plugin::V2::Communicator.prepend(Vagrant::Plugin::Remote::Communicator::Remote) },
->{ Vagrant::Plugin::V2::Provider.prepend(Vagrant::Plugin::Remote::Provider::Remote) },
->{ Vagrant::Plugin::V2::Push.prepend(Vagrant::Plugin::Remote::Push::Remote) },
->{ Vagrant::Action::Builtin::MixinSyncedFolders.prepend(Vagrant::Action::Builtin::Remote::MixinSyncedFolders) },
].freeze