diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 3c17b4e00..f4bc65639 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -97,7 +97,7 @@ module Vagrant # @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) + def initialize(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, vagrantfile, base=false, client=nil) @logger = Log4r::Logger.new("vagrant::machine") @logger.info("Initializing machine: #{name}") @logger.info(" - Provider: #{provider_cls}") diff --git a/lib/vagrant/machine/remote.rb b/lib/vagrant/machine/remote.rb index 35285da66..83c5ed1ba 100644 --- a/lib/vagrant/machine/remote.rb +++ b/lib/vagrant/machine/remote.rb @@ -26,46 +26,51 @@ module Vagrant # @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) + def initialize(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, vagrantfile, base=false, client=nil) @logger = Log4r::Logger.new("vagrant::machine") - @client = env.get_target(name) - @env = env - @ui = Vagrant::UI::Prefixed.new(@env.ui, name) + @logger.debug("building machine (remote) with client #{client}") + if !client.nil? + @client = client + else + @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 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 = @client.data_dir - @vagrantfile = vagrantfile - @guest = Guest.new( - self, - Vagrant.plugin("2").manager.guests, - Vagrant.plugin("2").manager.guest_capabilities) - @name = name - @ui_mutex = Mutex.new - @state_mutex = Mutex.new - @triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self, @ui) + #TODO: get box from @client.get_box() + @box = box + @config = config + @data_dir = @client.data_dir + @vagrantfile = vagrantfile + @guest = Guest.new( + self, + Vagrant.plugin("2").manager.guests, + Vagrant.plugin("2").manager.guest_capabilities) + @name = name + @ui_mutex = Mutex.new + @state_mutex = Mutex.new + @triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self, @ui) - # Keep track of where our UUID should be placed - @index_uuid_file = nil - @index_uuid_file = @data_dir.join("index_uuid") if @data_dir + # Keep track of where our UUID should be placed + @index_uuid_file = nil + @index_uuid_file = @data_dir.join("index_uuid") if @data_dir - # If the ID is the special not created ID, then set our ID to - # nil so that we destroy all our data. - # if state.id == MachineState::NOT_CREATED_ID - # self.id = nil - # end + # If the ID is the special not created ID, then set our ID to + # nil so that we destroy all our data. + # if state.id == MachineState::NOT_CREATED_ID + # self.id = nil + # end - # Output a bunch of information about this machine in - # machine-readable format in case someone is listening. - @ui.machine("metadata", "provider", provider_name) + # Output a bunch of information about this machine in + # machine-readable format in case someone is listening. + @ui.machine("metadata", "provider", provider_name) + end end # @return [Box] diff --git a/plugins/commands/serve/service/guest_service.rb b/plugins/commands/serve/service/guest_service.rb index c4ff6951a..24ed33723 100644 --- a/plugins/commands/serve/service/guest_service.rb +++ b/plugins/commands/serve/service/guest_service.rb @@ -6,7 +6,7 @@ module VagrantPlugins class GuestService < Hashicorp::Vagrant::Sdk::GuestService::Service prepend Util::HasBroker prepend Util::ExceptionLogger - LOGGER = Log4r::Logger.new("vagrant::command::serve::command") + LOGGER = Log4r::Logger.new("vagrant::command::serve::guest") def detect_spec(*_) SDK::FuncSpec.new( @@ -34,8 +34,8 @@ module VagrantPlugins }&.value&.value target = Client::Target.load(raw_target, broker: broker) machine_client = target.to_machine - # TODO: this machine should be a Remote::Machine - machine = machine_client + machine = Vagrant::Machine.new( + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, base=false, client=machine_client) plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first if !plugin @@ -48,11 +48,10 @@ module VagrantPlugins rescue => err LOGGER.debug("error detecting guest plugin!") LOGGER.error(err) - LOGGER.debug("#{err.class}: #{err}\n#{err.backtrace.join("\n")}") detected = false end - LOGGER.debug("detected? #{detected}") + LOGGER.debug("detected #{detected} for guest #{plugin_name}") SDK::Platform::DetectResp.new( detected: detected, ) @@ -72,7 +71,7 @@ module VagrantPlugins def parents(req, ctx) ServiceInfo.with_info(ctx) do |info| plugin_name = info.plugin_name - plugin = Vagrant.plugin("2").manager.guest[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 raise "Failed to locate guest plugin for: #{plugin_name.inspect}" end