Let #with_plugin load plugins by type

This commit is contained in:
Chris Roberts 2022-02-17 16:54:46 -08:00 committed by Paul Hinze
parent 2519b9b6ac
commit f88254eb23
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 15 additions and 24 deletions

View File

@ -19,8 +19,7 @@ module VagrantPlugins
end
def usable(req, ctx)
plugins = Vagrant.plugin("2").local_manager.providers
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :providers, broker: broker) do |plugin|
is_usable = plugin.usable?
SDK::Provider::UsableResp.new(
is_usable: is_usable,
@ -33,8 +32,7 @@ module VagrantPlugins
end
def installed(req, ctx)
plugins = Vagrant.plugin("2").local_manager.providers
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :providers, broker: broker) do |plugin|
is_installed = plugin.installed?
SDK::Provider::InstalledResp.new(
is_installed: is_installed,
@ -52,8 +50,7 @@ module VagrantPlugins
end
def action(req, ctx)
plugins = Vagrant.plugin("2").local_manager.providers
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :providers, broker: broker) do |plugin|
action_name = req.name.to_sym
machine, options = mapper.funcspec_map(
req.func_args,
@ -94,8 +91,7 @@ module VagrantPlugins
end
def machine_id_changed(req, ctx)
plugins = Vagrant.plugin("2").local_manager.providers
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :providers, broker: broker) do |plugin|
machine = mapper.funcspec_map(req, expect: [Vagrant::Machine])
provider = plugin.new(machine)
provider.machine_id_changed
@ -113,8 +109,7 @@ module VagrantPlugins
end
def ssh_info(req, ctx)
plugins = Vagrant.plugin("2").local_manager.providers
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :providers, broker: broker) do |plugin|
machine = mapper.funcspec_map(req, expect: [Vagrant::Machine])
provider = plugin.new(machine)
info = provider.ssh_info
@ -133,8 +128,7 @@ module VagrantPlugins
end
def state(req, ctx)
plugins = Vagrant.plugin("2").local_manager.providers
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :providers, broker: broker) do |plugin|
machine = mapper.funcspec_map(req, expect: [Vagrant::Machine])
provider = plugin.new(machine)
machine_state = provider.state

View File

@ -24,8 +24,7 @@ module VagrantPlugins
end
def usable(req, ctx)
plugins = Vagrant.plugin("2").local_manager.synced_folders
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :synced_folders, broker: broker) do |plugin|
machine = mapper.funcspec_map(
req, expect: [Vagrant::Machine]
)
@ -49,8 +48,7 @@ module VagrantPlugins
end
def prepare(req, ctx)
plugins = Vagrant.plugin("2").local_manager.synced_folders
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :synced_folders, broker: broker) do |plugin|
machine, folders, opts = mapper.funcspec_map(
req,
expect: [Vagrant::Machine, Type::Folders, Type::Options]
@ -75,8 +73,7 @@ module VagrantPlugins
end
def enable(req, ctx)
plugins = Vagrant.plugin("2").local_manager.synced_folders
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :synced_folders, broker: broker) do |plugin|
machine, folders, opts = mapper.funcspec_map(
req,
expect: [Vagrant::Machine, Type::Folders, Type::Options]
@ -101,8 +98,7 @@ module VagrantPlugins
end
def disable(req, ctx)
plugins = Vagrant.plugin("2").local_manager.synced_folders
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :synced_folders, broker: broker) do |plugin|
machine, folders, opts = mapper.funcspec_map(
req,
expect: [Vagrant::Machine, Type::Folders, Type::Options]
@ -126,8 +122,7 @@ module VagrantPlugins
end
def cleanup(req, ctx)
plugins = Vagrant.plugin("2").local_manager.synced_folders
with_plugin(ctx, plugins, broker: broker) do |plugin|
with_plugin(ctx, :synced_folders, broker: broker) do |plugin|
machine, opts = mapper.funcspec_map(
req,
expect: [Vagrant::Machine, Type::Options]

View File

@ -4,6 +4,9 @@ module VagrantPlugins
# Adds service info helper to be used with services
module ServiceInfo
def with_info(context, broker:, &block)
if broker.nil?
raise "NO BROKER FOR INFO"
end
if !context.metadata["plugin_name"]
raise KeyError,
"plugin name not defined (metadata content: #{context.metadata.inspect})"
@ -37,8 +40,7 @@ module VagrantPlugins
def with_plugin(context, plugins, broker:, &block)
with_info(context, broker: broker) do |info|
plugin_name = info.plugin_name
plugin = Array(plugins[plugin_name.to_s.to_sym]).first
plugin = Vagrant.plugin("2").local_manager.send(plugins)[info.plugin_name].to_a.first
if !plugin
raise NameError, "Failed to locate plugin named #{plugin_name}"
end