Clean up debugging cruft

This commit is contained in:
sophia 2021-07-06 16:39:00 -05:00 committed by Paul Hinze
parent 5ecb1cdc26
commit e86dc5958a
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
6 changed files with 47 additions and 72 deletions

View File

@ -13,21 +13,9 @@ module Vagrant
@client = opts[:client]
end
# This returns a machine with the proper provider for this environment.
# The machine named by `name` must be in this environment.
# Gets a target (machine) by name
#
# @param [Symbol] name Name of the machine (as configured in the
# Vagrantfile).
# @param [Symbol] provider The provider that this machine should be
# backed by.
# @param [Boolean] refresh If true, then if there is a cached version
# it is reloaded.
# @return [Vagrant::Remote::Machine]
# def machine(name, provider, refresh=false)
# return Machine.new(
# name, provider.to_s, nil, nil, nil, {}, nil, nil, self, nil, false)
# end
# @param [String] machine name
# return [VagrantPlugins::CommandServe::Client::Machine]
def get_target(name)
return @client.target(name)

View File

@ -11,26 +11,44 @@ module Vagrant
end
end
# Initialize a new machine.
#
# @param [String] name Name of the virtual machine.
# @param [Class] provider The provider backing this machine. This is
# currently expected to be a V1 `provider` plugin.
# @param [Object] provider_config The provider-specific configuration for
# this machine.
# @param [Hash] provider_options The provider-specific options from the
# plugin definition.
# @param [Object] config The configuration for this machine.
# @param [Pathname] data_dir The directory where machine-specific data
# can be stored. This directory is ensured to exist.
# @param [Box] box The box that is backing this virtual machine.
# @param [Environment] env The environment that this machine is a
# part of.
def initialize(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, vagrantfile, base=false)
@logger = Log4r::Logger.new("vagrant::machine")
@client = env.get_target(name)
@env = env
@ui = Vagrant::UI::Prefixed.new(@env.ui, name)
# TODO: Get provider info from client
@provider_name = provider_name
@provider = provider_cls.new(self)
@provider._initialize(provider_name, self)
@provider_options = provider_options
@provider_config = provider_config
#TODO: get box from @client.get_box()
@box = box
@config = config
@data_dir = data_dir
@data_dir = @client.get_data_dir()
@vagrantfile = vagrantfile
@guest = Guest.new(
self,
Vagrant.plugin("2").manager.guests,
Vagrant.plugin("2").manager.guest_capabilities)
@name = name
@provider_config = provider_config
@ui_mutex = Mutex.new
@state_mutex = Mutex.new
@triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self, @ui)

View File

@ -65,7 +65,7 @@ module VagrantPlugins
def get_data_dir
req = Google::Protobuf::Empty.new
@client.datadir(req).data_dir
Pathname.new(@client.data_dir(req).data_dir)
end
# TODO: local data path comes from the project
@ -100,18 +100,13 @@ module VagrantPlugins
end
def get_state
# req = Google::Protobuf::Empty.new
# resp = @client.get_state(req)
# @logger.debug("Got state #{resp}")
# Vagrant::MachineState.new(
# resp.state.id.to_sym,
# resp.state.short_description,
# resp.state.long_description
# )
req = Google::Protobuf::Empty.new
resp = @client.get_state(req)
@logger.debug("Got state #{resp}")
Vagrant::MachineState.new(
:UNKNOWN,
"all good",
"you know, all good"
resp.state.id.to_sym,
resp.state.short_description,
resp.state.long_description
)
end

View File

@ -18,6 +18,7 @@ module VagrantPlugins
end
# Returns a machine client for the given name
# return [VagrantPlugins::CommandServe::Client::Machine]
def target(name)
@logger.debug("searching for target #{name}")
req = SDK::Project::TargetRequest.new(name: name)

View File

@ -65,52 +65,25 @@ module VagrantPlugins
raw_project = req.spec.args.detect { |a|
a.type == "hashicorp.vagrant.sdk.Args.Project"
}&.value&.value
raw_target = req.spec.args.detect { |a|
a.type == "hashicorp.vagrant.sdk.Args.Target"
}&.value&.value
# If a target is specified, specialize into a machine
if !raw_target.nil?
t = SDK::Args::Target.decode(raw_target)
LOG.debug("got a target: #{t}")
conn = broker.dial(t.stream_id)
target_service = SDK::TargetService::Stub.new(conn.to_s, :this_channel_is_insecure)
LOG.debug("got target #{target_service.name(Google::Protobuf::Empty.new).name}")
LOG.debug("specializing target #{target_service}")
machine = target_service.specialize(Google::Protobuf::Any.new)
LOG.debug("target specialized to #{machine.value}")
m = SDK::Args::Target::Machine.decode(machine.value)
LOG.debug("got a machine: #{m}")
conn = broker.dial(m.stream_id)
LOG.debug("connecting to target machine service on #{conn}")
machine_service = SDK::TargetMachineService::Stub.new(conn.to_s, :this_channel_is_insecure)
LOG.debug("machine name: #{machine_service.name(Google::Protobuf::Empty.new).name}")
arguments = SDK::Command::Arguments.decode(raw_args)
ui_client = Client::Terminal.load(raw_terminal, broker: broker)
env_client = Client::Project.load(raw_project, broker: broker)
ui = Vagrant::UI::RemoteUI.new(ui_client)
env = Vagrant::Environment.new(
{ui: ui, client: env_client}
)
plugin = Vagrant::Plugin::V2::Plugin.manager.commands[plugin_name.to_sym].to_a.first
if !plugin
raise "Failed to locate command plugin for: #{plugin_name}"
end
begin
arguments = SDK::Command::Arguments.decode(raw_args)
ui_client = Client::Terminal.load(raw_terminal, broker: broker)
env_client = Client::Project.load(raw_project, broker: broker)
ui = Vagrant::UI::RemoteUI.new(ui_client)
env = Vagrant::Environment.new(
{ui: ui, client: env_client}
)
plugin = Vagrant::Plugin::V2::Plugin.manager.commands[plugin_name.to_sym].to_a.first
if !plugin
raise "Failed to locate command plugin for: #{plugin_name}"
end
cmd_klass = plugin.call
cmd_args = req.command_args.to_a[1..] + arguments.args.to_a
cmd = cmd_klass.new(cmd_args, env)
result = cmd.execute
rescue => err
LOG.error(err)
LOG.debug("#{err.class}: #{err}\n#{err.backtrace.join("\n")}")
raise
end
cmd_klass = plugin.call
cmd_args = req.command_args.to_a[1..] + arguments.args.to_a
cmd = cmd_klass.new(cmd_args, env)
result = cmd.execute
LOGGER.debug(result)
if !result.is_a?(Integer)

View File

@ -55,7 +55,7 @@ module VagrantPlugins
begin
@logger.debug("Instantiating the driver for machine ID: #{@machine.id.inspect}")
@driver = Driver::Meta.new(uuid=id)
@driver = Driver::Meta.new(id)
rescue Driver::Meta::VMNotFound
# The virtual machine doesn't exist, so we probably have a stale
# ID. Just clear the id out of the machine and reload it.