From 20ec85b021ff34af1539e369cd1e4d2fb0afa2b6 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 28 Jun 2022 15:44:27 -0500 Subject: [PATCH 1/4] Use remote provider --- lib/vagrant/machine/remote.rb | 3 ++- plugins/commands/serve/service/provider_service.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/machine/remote.rb b/lib/vagrant/machine/remote.rb index 225c96589..af41a883d 100644 --- a/lib/vagrant/machine/remote.rb +++ b/lib/vagrant/machine/remote.rb @@ -42,6 +42,7 @@ module Vagrant # TODO: get trigger config from go @triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self, @ui) @provider_options = {} # @config.vm.get_provider_overrides(@provider_name) + @provider = Vagrant.plugin("2").manager.providers[provider_name].first.new(self) # Keep track of where our UUID should be placed @index_uuid_file = nil @@ -137,7 +138,7 @@ module Vagrant def provider return @provider if @provider - @provider = Vagrant.plugin("2").local_manager.providers[provider_name].first.new(self) + @provider = Vagrant.plugin("2").manager.providers[provider_name].first.new(self) @provider end diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index c05d8c34f..b0a9fd174 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -110,7 +110,7 @@ module VagrantPlugins def state_spec(*_) funcspec( args: [ - SDK::Args::Target + SDK::Args::Target::Machine ], result: SDK::Args::Target::Machine::State, ) From 52d37217acdec6e39b8aa52bf201d57ca5627a44 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 28 Jun 2022 16:26:52 -0500 Subject: [PATCH 2/4] Use cache from CommandServe module --- lib/vagrant/plugin/remote/manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant/plugin/remote/manager.rb b/lib/vagrant/plugin/remote/manager.rb index 3a4887408..e0883fe3a 100644 --- a/lib/vagrant/plugin/remote/manager.rb +++ b/lib/vagrant/plugin/remote/manager.rb @@ -92,7 +92,7 @@ module Vagrant klass = get_local_plugin return super if klass.nil? @logger.debug("found local plugin class #{self.class.name} -> #{klass.name}") - c = VagrantPlugins::CommandServe::Service.cache + c = VagrantPlugins::CommandServe.cache key = c.key(klass, *@init[0]) if !c.registered?(key) @logger.debug("creating new local plugin instance of #{klass} with args: #{@init}") From 73801703e75ed415cc620af97fe75f75f84fd2c3 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 29 Jun 2022 10:38:39 -0500 Subject: [PATCH 3/4] Pass machine to provider capabilities --- lib/vagrant/plugin/remote/provider.rb | 2 +- plugins/commands/serve/service/provider_service.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/plugin/remote/provider.rb b/lib/vagrant/plugin/remote/provider.rb index 6eb8c7f85..5cb58e749 100644 --- a/lib/vagrant/plugin/remote/provider.rb +++ b/lib/vagrant/plugin/remote/provider.rb @@ -38,7 +38,7 @@ module Vagrant # @param [Symbol] cap_name Name of the capability def capability(cap_name, *args) @logger.debug("running remote provider capability #{cap_name} with args #{args}") - client.capability(cap_name, *args) + client.capability(cap_name, @machine, *args) end # Tests whether the given capability is possible. diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index b0a9fd174..9c59a7b3c 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -140,6 +140,16 @@ module VagrantPlugins machine.env.action_runner.run(callable, env) end + def capability_arguments(args) + target, direct = args + nargs = direct.args.dup + if !nargs.first.is_a?(Vagrant::Machine) + nargs.unshift(mapper.map(target, to: Vagrant::Machine)) + end + + nargs + end + def load_provider(klass, machine) key = cache.key(klass, machine) return cache.get(key) if cache.registered?(key) From f1af42a7fc70c7f298b36f57b63b26dcdfb70322 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 1 Jul 2022 11:31:21 -0500 Subject: [PATCH 4/4] Don't use hash with indifferent access when converting hash The HashWithIndifferentAccess will change all keys to strings when merged with another regular hash. This causes errors in cases where hashes are merged, for example in the action builder. Symbol/String type data is kept over the wire, so there is no need to make the mapped hash a HashWithIndifferentAccess. --- plugins/commands/serve/mappers/known_types.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/commands/serve/mappers/known_types.rb b/plugins/commands/serve/mappers/known_types.rb index ae94635f0..16ac9e619 100644 --- a/plugins/commands/serve/mappers/known_types.rb +++ b/plugins/commands/serve/mappers/known_types.rb @@ -171,7 +171,7 @@ module VagrantPlugins def converter(proto, mapper) begin - h = Hash.new.tap do |result| + Hash.new.tap do |result| proto.entries.each do |entry| # Convert our key and value to native types k = mapper.map(entry.key) @@ -183,7 +183,6 @@ module VagrantPlugins result[k] = v end end - Vagrant::Util::HashWithIndifferentAccess.new(h) rescue => err logger.error { "proto mapping to hash failed: #{err}" } raise