From e86dc5958a2168add21516a7b8a3538ca00f8d78 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 6 Jul 2021 16:39:00 -0500 Subject: [PATCH] Clean up debugging cruft --- lib/vagrant/environment/remote.rb | 16 +---- lib/vagrant/machine/remote.rb | 22 ++++++- plugins/commands/serve/client/machine.rb | 19 +++--- plugins/commands/serve/client/project.rb | 1 + .../commands/serve/service/command_service.rb | 59 +++++-------------- plugins/providers/virtualbox/provider.rb | 2 +- 6 files changed, 47 insertions(+), 72 deletions(-) diff --git a/lib/vagrant/environment/remote.rb b/lib/vagrant/environment/remote.rb index 0532ae848..b4c53e059 100644 --- a/lib/vagrant/environment/remote.rb +++ b/lib/vagrant/environment/remote.rb @@ -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) diff --git a/lib/vagrant/machine/remote.rb b/lib/vagrant/machine/remote.rb index b2feedcb1..4e3f33bc4 100644 --- a/lib/vagrant/machine/remote.rb +++ b/lib/vagrant/machine/remote.rb @@ -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) diff --git a/plugins/commands/serve/client/machine.rb b/plugins/commands/serve/client/machine.rb index efbb54815..fc1099caa 100644 --- a/plugins/commands/serve/client/machine.rb +++ b/plugins/commands/serve/client/machine.rb @@ -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 diff --git a/plugins/commands/serve/client/project.rb b/plugins/commands/serve/client/project.rb index 3ee519c65..8761c9df5 100644 --- a/plugins/commands/serve/client/project.rb +++ b/plugins/commands/serve/client/project.rb @@ -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) diff --git a/plugins/commands/serve/service/command_service.rb b/plugins/commands/serve/service/command_service.rb index 8e04b3c85..e527dd453 100644 --- a/plugins/commands/serve/service/command_service.rb +++ b/plugins/commands/serve/service/command_service.rb @@ -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) diff --git a/plugins/providers/virtualbox/provider.rb b/plugins/providers/virtualbox/provider.rb index b65d6f797..f7a86c920 100644 --- a/plugins/providers/virtualbox/provider.rb +++ b/plugins/providers/virtualbox/provider.rb @@ -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.