Merge pull request #312 from hashicorp/ruby-plugin-options
Bring plugin options back to Ruby for providers and synced folders
This commit is contained in:
commit
1d2e487924
2
go.mod
2
go.mod
@ -46,7 +46,7 @@ require (
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/hashicorp/hcl/v2 v2.11.1
|
||||
github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220713192312-658d9a5a0105
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220715171238-5d159ee78809
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
|
||||
github.com/imdario/mergo v0.3.11
|
||||
github.com/improbable-eng/grpc-web v0.13.0
|
||||
|
||||
7
go.sum
7
go.sum
@ -361,10 +361,8 @@ github.com/hashicorp/hcl/v2 v2.11.1 h1:yTyWcXcm9XB0TEkyU/JCRU6rYy4K+mgLtzn2wlrJb
|
||||
github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
|
||||
github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d h1:afuZ/KNbxwUgjEzq2NXO2bRKZgsIJQgFxgIRGETF0/A=
|
||||
github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d/go.mod h1:DCi2k47yuUDzf2qWAK8E1RVmWgz/lc0jZQeEnICTxmY=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220711233255-41e1736fda1a h1:+8DD39+jhZjexeamX3kYkWsq7IpLQevx90n0u93FI8s=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220711233255-41e1736fda1a/go.mod h1:VOmcNETEOMrBGGZW7YtWoRQOuiAA7273qLJfCGf2B/c=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220713192312-658d9a5a0105 h1:TacwCmXZieiHxela0hCvF0MWy4YM9xJsg5iGB9j+0n0=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220713192312-658d9a5a0105/go.mod h1:VOmcNETEOMrBGGZW7YtWoRQOuiAA7273qLJfCGf2B/c=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220715171238-5d159ee78809 h1:XRJINT3VeBoFTwGWGnK7JTrvF0Upd2Dkm5xj/yiN3dU=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220715171238-5d159ee78809/go.mod h1:VOmcNETEOMrBGGZW7YtWoRQOuiAA7273qLJfCGf2B/c=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
@ -655,7 +653,6 @@ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
|
||||
@ -436,8 +436,9 @@ func (m *Manager) ListPlugins(typeNames ...string) ([]*core.NamedPlugin, error)
|
||||
}
|
||||
for _, p := range list {
|
||||
i := &core.NamedPlugin{
|
||||
Type: t.String(),
|
||||
Name: p,
|
||||
Type: t.String(),
|
||||
Name: p,
|
||||
Options: m.optionsForPlugin(t, p),
|
||||
}
|
||||
result = append(result, i)
|
||||
}
|
||||
@ -728,3 +729,20 @@ func (m *Manager) loadParent(i *Instance) error {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -44,7 +44,6 @@ module Vagrant
|
||||
@state_mutex = Mutex.new
|
||||
# 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)
|
||||
|
||||
# Keep track of where our UUID should be placed
|
||||
@index_uuid_file = nil
|
||||
@ -154,7 +153,7 @@ module Vagrant
|
||||
end
|
||||
|
||||
def provider_options
|
||||
@provider_options
|
||||
@provider_options ||= Vagrant.plugin("2").manager.provider[provider_name].last
|
||||
end
|
||||
|
||||
def recover_machine(*_)
|
||||
|
||||
@ -148,13 +148,6 @@ module Vagrant
|
||||
self.class.core_client
|
||||
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.
|
||||
#
|
||||
# @return [Registry]
|
||||
@ -165,7 +158,12 @@ module Vagrant
|
||||
sf_class.plugin_name = plg[:name]
|
||||
sf_class.type = plg[:type]
|
||||
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
|
||||
@ -260,8 +258,7 @@ module Vagrant
|
||||
sf_class.plugin_name = plg[:name]
|
||||
sf_class.type = plg[:type]
|
||||
result.register(plg[:name].to_sym) do
|
||||
# TODO: Options hash should be what?
|
||||
[sf_class, {}]
|
||||
[sf_class, plg[:options]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -457,6 +457,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
optional :name, :string, 1
|
||||
optional :type, :string, 2
|
||||
optional :plugin, :message, 3, "google.protobuf.Any"
|
||||
optional :options, :message, 4, "google.protobuf.Any"
|
||||
end
|
||||
add_message "hashicorp.vagrant.sdk.CorePluginManager" do
|
||||
end
|
||||
|
||||
@ -12,7 +12,8 @@ module VagrantPlugins
|
||||
Vagrant::Util::HashWithIndifferentAccess.new(
|
||||
name: plg.name,
|
||||
type: plg.type,
|
||||
proto: plg.plugin
|
||||
proto: plg.plugin,
|
||||
options: _plugin_options_to_hash(plg.options),
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -27,6 +28,25 @@ module VagrantPlugins
|
||||
)
|
||||
mapper.map(resp.plugin, broker)
|
||||
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
|
||||
|
||||
@ -761,12 +761,7 @@ module VagrantPlugins
|
||||
@allow_fstab_modification = true if @allow_fstab_modification == UNSET_VALUE
|
||||
end
|
||||
|
||||
# HACK(phinze): We cannot honor box_optional in gogo yet so we are
|
||||
# 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
|
||||
if !box && !clone && !machine.provider_options[:box_optional]
|
||||
errors << I18n.t("vagrant.config.vm.box_missing")
|
||||
end
|
||||
|
||||
|
||||
@ -100,8 +100,6 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||
end
|
||||
|
||||
it "is not required if the provider says so" do
|
||||
# TODO: reenable this test once provider options are implemented
|
||||
pending "removal of temporary workaround"
|
||||
machine.provider_options[:box_optional] = true
|
||||
subject.box = nil
|
||||
subject.finalize!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user