Update module usage within service implementations

This commit is contained in:
Chris Roberts 2021-10-01 11:16:42 -07:00 committed by Paul Hinze
parent 0401f9cad4
commit fd18051b0d
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
5 changed files with 27 additions and 21 deletions

View File

@ -4,20 +4,21 @@ module VagrantPlugins
module CommandServe module CommandServe
module Service module Service
class CommandService < SDK::CommandService::Service class CommandService < SDK::CommandService::Service
include Util::ServiceInfo
prepend Util::HasMapper prepend Util::HasMapper
prepend Util::HasBroker prepend Util::HasBroker
prepend Util::HasLogger
prepend Util::ExceptionLogger prepend Util::ExceptionLogger
LOGGER = Log4r::Logger.new("vagrant::command::serve::command")
def command_info_spec(*args) def command_info_spec(*args)
SDK::FuncSpec.new SDK::FuncSpec.new
end end
def command_info(req, ctx) def command_info(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
command_info = collect_command_info(info.plugin_name, []) command_info = collect_command_info(info.plugin_name, [])
LOGGER.info("command info, #{command_info}") logger.info("command info, #{command_info}")
SDK::Command::CommandInfoResp.new( SDK::Command::CommandInfoResp.new(
command_info: command_info, command_info: command_info,
) )
@ -51,7 +52,7 @@ module VagrantPlugins
end end
def execute(req, ctx) def execute(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
plugin_name = info.plugin_name plugin_name = info.plugin_name
ui_client, env_client, arguments = mapper.funcspec_map(req.spec) ui_client, env_client, arguments = mapper.funcspec_map(req.spec)
@ -84,7 +85,7 @@ module VagrantPlugins
protected protected
def collect_command_info(plugin_name, subcommand_names) def collect_command_info(plugin_name, subcommand_names)
LOGGER.info("collecting command information for #{plugin_name} #{subcommand_names}") logger.info("collecting command information for #{plugin_name} #{subcommand_names}")
options = command_options_for(plugin_name, subcommand_names) options = command_options_for(plugin_name, subcommand_names)
if options.nil? if options.nil?
hlp_msg = "" hlp_msg = ""
@ -130,17 +131,17 @@ module VagrantPlugins
end end
def get_subcommands(plugin_name, subcommand_names) def get_subcommands(plugin_name, subcommand_names)
LOGGER.info("collecting subcommands for #{plugin_name} #{subcommand_names}") logger.info("collecting subcommands for #{plugin_name} #{subcommand_names}")
subcommands = [] subcommands = []
cmds = subcommands_for(plugin_name, subcommand_names) cmds = subcommands_for(plugin_name, subcommand_names)
if !cmds.nil? if !cmds.nil?
LOGGER.info("found subcommands #{cmds.keys}") logger.info("found subcommands #{cmds.keys}")
cmds.keys.each do |subcmd| cmds.keys.each do |subcmd|
subnms = subcommand_names.dup subnms = subcommand_names.dup
subcommands << collect_command_info(plugin_name, subnms.append(subcmd.to_s)) subcommands << collect_command_info(plugin_name, subnms.append(subcmd.to_s))
end end
else else
LOGGER.info("no subcommands found") logger.info("no subcommands found")
end end
return subcommands return subcommands
end end

View File

@ -6,11 +6,12 @@ module VagrantPlugins
class GuestService < Hashicorp::Vagrant::Sdk::GuestService::Service class GuestService < Hashicorp::Vagrant::Sdk::GuestService::Service
include CapabilityPlatformService include CapabilityPlatformService
include Util::ServiceInfo
prepend Util::HasMapper prepend Util::HasMapper
prepend Util::HasBroker prepend Util::HasBroker
prepend Util::HasLogger
prepend Util::ExceptionLogger prepend Util::ExceptionLogger
LOGGER = Log4r::Logger.new("vagrant::command::serve::guest")
def initialize(*args, **opts, &block) def initialize(*args, **opts, &block)
caps = Vagrant.plugin("2").manager.guest_capabilities caps = Vagrant.plugin("2").manager.guest_capabilities
@ -44,7 +45,7 @@ module VagrantPlugins
end end
def detect(req, ctx) def detect(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
plugin_name = info.plugin_name plugin_name = info.plugin_name
target = mapper.funcspec_map(req) target = mapper.funcspec_map(req)
project = target.project project = target.project
@ -52,17 +53,17 @@ module VagrantPlugins
machine = env.machine(target.name.to_sym, target.provider_name.to_sym) machine = env.machine(target.name.to_sym, target.provider_name.to_sym)
plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first
if !plugin if !plugin
LOGGER.debug("Failed to locate guest plugin for: #{plugin_name}") logger.debug("Failed to locate guest plugin for: #{plugin_name}")
raise "Failed to locate guest plugin for: #{plugin_name.inspect}" raise "Failed to locate guest plugin for: #{plugin_name.inspect}"
end end
guest = plugin.new guest = plugin.new
begin begin
detected = guest.detect?(machine) detected = guest.detect?(machine)
rescue => err rescue => err
LOGGER.debug("error encountered detecting guest: #{err.class} - #{err}") logger.debug("error encountered detecting guest: #{err.class} - #{err}")
detected = false detected = false
end end
LOGGER.debug("detected #{detected} for guest #{plugin_name}") logger.debug("detected #{detected} for guest #{plugin_name}")
SDK::Platform::DetectResp.new( SDK::Platform::DetectResp.new(
detected: detected, detected: detected,
) )
@ -80,7 +81,7 @@ module VagrantPlugins
end end
def parents(req, ctx) def parents(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
plugin_name = info.plugin_name plugin_name = info.plugin_name
plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first
if !plugin if !plugin

View File

@ -6,9 +6,11 @@ module VagrantPlugins
class HostService < Hashicorp::Vagrant::Sdk::HostService::Service class HostService < Hashicorp::Vagrant::Sdk::HostService::Service
include CapabilityPlatformService include CapabilityPlatformService
include Util::ServiceInfo
prepend Util::HasMapper prepend Util::HasMapper
prepend Util::HasBroker prepend Util::HasBroker
prepend Util::HasLogger
prepend Util::ExceptionLogger prepend Util::ExceptionLogger
LOGGER = Log4r::Logger.new("vagrant::command::serve::host") LOGGER = Log4r::Logger.new("vagrant::command::serve::host")
@ -43,7 +45,7 @@ module VagrantPlugins
end end
def detect(req, ctx) def detect(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
plugin_name = info.plugin_name plugin_name = info.plugin_name
statebag = mapper.funcspec_map(req) statebag = mapper.funcspec_map(req)
plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first
@ -54,10 +56,10 @@ module VagrantPlugins
begin begin
detected = host.detect?(statebag) detected = host.detect?(statebag)
rescue => err rescue => err
LOGGER.debug("error encountered detecting host: #{err.class} - #{err}") logger.debug("error encountered detecting host: #{err.class} - #{err}")
detected = false detected = false
end end
LOGGER.debug("detected #{detected} for host #{plugin_name}") logger.debug("detected #{detected} for host #{plugin_name}")
SDK::Platform::DetectResp.new( SDK::Platform::DetectResp.new(
detected: detected, detected: detected,
) )
@ -75,7 +77,7 @@ module VagrantPlugins
end end
def parents(req, ctx) def parents(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
plugin_name = info.plugin_name plugin_name = info.plugin_name
plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first
if !plugin if !plugin

View File

@ -11,10 +11,9 @@ module VagrantPlugins
module Service module Service
class InternalService < Hashicorp::Vagrant::RubyVagrant::Service class InternalService < Hashicorp::Vagrant::RubyVagrant::Service
prepend Util::HasBroker prepend Util::HasBroker
prepend Util::HasLogger
prepend Util::ExceptionLogger prepend Util::ExceptionLogger
LOG = Log4r::Logger.new("vagrant::command::serve::service::internal")
def get_plugins(req, _unused_call) def get_plugins(req, _unused_call)
plugins = [] plugins = []
plugin_manager = Vagrant::Plugin::V2::Plugin.manager plugin_manager = Vagrant::Plugin::V2::Plugin.manager

View File

@ -6,8 +6,11 @@ module VagrantPlugins
module CommandServe module CommandServe
module Service module Service
class ProviderService < SDK::ProviderService::Service class ProviderService < SDK::ProviderService::Service
include Util::ServiceInfo
prepend Util::HasMapper prepend Util::HasMapper
prepend Util::HasBroker prepend Util::HasBroker
prepend Util::HasLogger
prepend Util::ExceptionLogger prepend Util::ExceptionLogger
def usable(req, _unused_call) def usable(req, _unused_call)
@ -35,7 +38,7 @@ module VagrantPlugins
end end
def action_up(req, ctx) def action_up(req, ctx)
ServiceInfo.with_info(ctx) do |info| with_info(ctx) do |info|
plugin_name = info.plugin_name plugin_name = info.plugin_name
ui, machine = mapper.funcspec_map(req.spec) ui, machine = mapper.funcspec_map(req.spec)