Bring plugin options back to Ruby for providers and synced folders

This removes the need for the validation workaround for Docker, because
box_updated is once again available in that context.

We don't technically need the SyncedFolder priorities back on the Ruby
side, but wiring them through for symmetry.

Depends on https://github.com/hashicorp/vagrant-plugin-sdk/pull/183
This commit is contained in:
Paul Hinze 2022-07-11 17:07:22 -05:00
parent ae49b1f13f
commit 957d0d3779
No known key found for this signature in database
GPG Key ID: 70B94C31D170FB29
6 changed files with 51 additions and 21 deletions

View File

@ -436,8 +436,9 @@ func (m *Manager) ListPlugins(typeNames ...string) ([]*core.NamedPlugin, error)
} }
for _, p := range list { for _, p := range list {
i := &core.NamedPlugin{ i := &core.NamedPlugin{
Type: t.String(), Type: t.String(),
Name: p, Name: p,
Options: m.optionsForPlugin(t, p),
} }
result = append(result, i) result = append(result, i)
} }
@ -728,3 +729,20 @@ func (m *Manager) loadParent(i *Instance) error {
return nil return nil
} }
// optionsForPlugin fetches the options that were registered for a given
// plugin. the return type will be one of component.*Options. If the plugin is
// not found or has no options, returns nil.
func (m *Manager) optionsForPlugin(t component.Type, name string) interface{} {
for _, p := range m.Plugins {
if p.Name == name && p.HasType(t) {
return p.Options[t]
}
}
if m.parent != nil {
return m.parent.optionsForPlugin(t, name)
}
return nil
}

View File

@ -44,7 +44,6 @@ module Vagrant
@state_mutex = Mutex.new @state_mutex = Mutex.new
# TODO: get trigger config from go # TODO: get trigger config from go
@triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self, @ui) @triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self, @ui)
@provider_options = {} # @config.vm.get_provider_overrides(@provider_name)
# Keep track of where our UUID should be placed # Keep track of where our UUID should be placed
@index_uuid_file = nil @index_uuid_file = nil
@ -154,7 +153,7 @@ module Vagrant
end end
def provider_options def provider_options
@provider_options @provider_options ||= Vagrant.plugin("2").manager.provider[provider_name].last
end end
def recover_machine(*_) def recover_machine(*_)

View File

@ -148,13 +148,6 @@ module Vagrant
self.class.core_client self.class.core_client
end end
# Synced folder plugins are registered with an integer priority, but in
# remote mode this is all captured by InternalService#get_plugins and
# handled on the Go sidw. Within the remote manager we return a stub
# value to ensure that any callers get the same shape of return value
# from the registry and don't blow up.
SYNCED_FOLDERS_STUB_PRIORITY = 123
# This returns all synced folder implementations. # This returns all synced folder implementations.
# #
# @return [Registry] # @return [Registry]
@ -165,7 +158,12 @@ module Vagrant
sf_class.plugin_name = plg[:name] sf_class.plugin_name = plg[:name]
sf_class.type = plg[:type] sf_class.type = plg[:type]
result.register(plg[:name].to_sym) do result.register(plg[:name].to_sym) do
[sf_class, SYNCED_FOLDERS_STUB_PRIORITY] # The integer priority has already been captured on the Go side
# by InternalService#get_plugins. It's returned in the plugin
# options field, and we populate it into the same place for
# good measure, even though we expect that priority will be
# handled on the Go side now.
[sf_class, plg[:options]]
end end
end end
end end
@ -260,8 +258,7 @@ module Vagrant
sf_class.plugin_name = plg[:name] sf_class.plugin_name = plg[:name]
sf_class.type = plg[:type] sf_class.type = plg[:type]
result.register(plg[:name].to_sym) do result.register(plg[:name].to_sym) do
# TODO: Options hash should be what? [sf_class, plg[:options]]
[sf_class, {}]
end end
end end
end end

View File

@ -457,6 +457,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
optional :name, :string, 1 optional :name, :string, 1
optional :type, :string, 2 optional :type, :string, 2
optional :plugin, :message, 3, "google.protobuf.Any" optional :plugin, :message, 3, "google.protobuf.Any"
optional :options, :message, 4, "google.protobuf.Any"
end end
add_message "hashicorp.vagrant.sdk.CorePluginManager" do add_message "hashicorp.vagrant.sdk.CorePluginManager" do
end end

View File

@ -12,7 +12,8 @@ module VagrantPlugins
Vagrant::Util::HashWithIndifferentAccess.new( Vagrant::Util::HashWithIndifferentAccess.new(
name: plg.name, name: plg.name,
type: plg.type, type: plg.type,
proto: plg.plugin proto: plg.plugin,
options: _plugin_options_to_hash(plg.options),
) )
end end
end end
@ -27,6 +28,25 @@ module VagrantPlugins
) )
mapper.map(resp.plugin, broker) mapper.map(resp.plugin, broker)
end end
# Plugin options are an Any that contains one of the types defined in
# component.*Options in the SDK.
#
# On the Ruby side, plugin options are just a value that get stuffed in
# a tuple next to the plugin in the manager. Its type is context
# dependent so we need to unpack each kind of plugin options with its
# own logic.
def _plugin_options_to_hash(plg_opts)
opts = mapper.unany(plg_opts)
case opts
when Hashicorp::Vagrant::Sdk::PluginInfo::ProviderOptions
opts.to_h
when Hashicorp::Vagrant::Sdk::PluginInfo::SyncedFolderOptions
opts.priority
else
raise ArgumentError, "unexpected plugin options #{opts.inspect}"
end
end
end end
end end
end end

View File

@ -761,12 +761,7 @@ module VagrantPlugins
@allow_fstab_modification = true if @allow_fstab_modification == UNSET_VALUE @allow_fstab_modification = true if @allow_fstab_modification == UNSET_VALUE
end end
# HACK(phinze): We cannot honor box_optional in gogo yet so we are if !box && !clone && !machine.provider_options[:box_optional]
# temporarily hacking in a workaround which explicitly looks for docker
# instead of the option itself. Once plugin metadata is implemented
# this conditional should be reverted to the commented line below
# if !box && !clone && !machine.provider_options[:box_optional]
if !box && !clone && machine.provider_name != :docker
errors << I18n.t("vagrant.config.vm.box_missing") errors << I18n.t("vagrant.config.vm.box_missing")
end end