From 809e4044a0ac08110badc494b4c82b819ca03266 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 24 Jan 2022 10:19:17 -0600 Subject: [PATCH] Add provider remote plugin module --- lib/vagrant/plugin/remote.rb | 1 + lib/vagrant/plugin/remote/communicator.rb | 2 +- lib/vagrant/plugin/remote/manager.rb | 26 +++++----- lib/vagrant/plugin/remote/provider.rb | 63 +++++++++++++++++++++++ lib/vagrant/shared_helpers.rb | 1 + 5 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 lib/vagrant/plugin/remote/provider.rb diff --git a/lib/vagrant/plugin/remote.rb b/lib/vagrant/plugin/remote.rb index 254cd6d39..d485e4d04 100644 --- a/lib/vagrant/plugin/remote.rb +++ b/lib/vagrant/plugin/remote.rb @@ -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 diff --git a/lib/vagrant/plugin/remote/communicator.rb b/lib/vagrant/plugin/remote/communicator.rb index 17d0e57b5..af1f1f107 100644 --- a/lib/vagrant/plugin/remote/communicator.rb +++ b/lib/vagrant/plugin/remote/communicator.rb @@ -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 diff --git a/lib/vagrant/plugin/remote/manager.rb b/lib/vagrant/plugin/remote/manager.rb index 2f91a9204..f7005f955 100644 --- a/lib/vagrant/plugin/remote/manager.rb +++ b/lib/vagrant/plugin/remote/manager.rb @@ -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? diff --git a/lib/vagrant/plugin/remote/provider.rb b/lib/vagrant/plugin/remote/provider.rb new file mode 100644 index 000000000..cd041a5f6 --- /dev/null +++ b/lib/vagrant/plugin/remote/provider.rb @@ -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 diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index f698ea496..f368c510e 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -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