From 078a0917096a8469cd20d7cbd719f5f552bf8483 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 21 Jan 2021 13:39:41 -0600 Subject: [PATCH] Start replacing machine variables with calls to core service --- lib/vagrant/machine.rb | 24 ++++++++++++++----- .../serve/service/provider_service.rb | 3 ++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 9cae5c0bb..0c3f25fe5 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -20,6 +20,15 @@ module Vagrant @client = Hashicorp::Vagrant::Sdk::MachineService::Stub.new(server_endpoint, :this_channel_is_insecure) end + def get_name(id) + machine_ref = Hashicorp::Vagrant::Sdk::Ref::Machine.new(resource_id: id) + req = Hashicorp::Vagrant::Sdk::Machine::GetNameRequest.new( + machine: machine_ref + ) + resp_machine = @client.get_name(req) + resp_machine.name + end + # Get a machine by id # # @param [String] machine id @@ -55,11 +64,11 @@ module Vagrant ) Machine.new( - m, "virtualbox", provider_cls, + "virtualbox", provider_cls, {}, provider_options, {}, Pathname.new("/Users/sophia/.vagrant.d/data"), box, env, nil, - base=false, client=@client, machine_id=id + base=false, client=self, machine_id=id ) end end @@ -100,7 +109,7 @@ module Vagrant # Name of the machine. This is assigned by the Vagrantfile. # # @return [Symbol] - attr_reader :name + # attr_reader :name # The provider backing this machine. # @@ -152,14 +161,14 @@ 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, client=nil, machine_id=nil) + def initialize(provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, vagrantfile, base=false, client=nil, machine_id=nil) @logger = Log4r::Logger.new("vagrant::machine") - @logger.info("Initializing machine: #{name}") @logger.info(" - Provider: #{provider_cls}") @logger.info(" - Box: #{box}") @logger.info(" - Data dir: #{data_dir}") @client = client + @machine_id = machine_id @box = box @config = config @data_dir = data_dir @@ -169,7 +178,6 @@ module Vagrant self, Vagrant.plugin("2").manager.guests, Vagrant.plugin("2").manager.guest_capabilities) - @name = name @provider_config = provider_config @provider_name = provider_name @provider_options = provider_options @@ -224,6 +232,10 @@ module Vagrant @ui.machine("metadata", "provider", provider_name) end + def name + @client.get_name(@machine_id) + end + # This calls an action on the provider. The provider may or may not # actually implement the action. # diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index 6b09defbb..c5ac6b66f 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -59,7 +59,8 @@ module VagrantPlugins mclient = Vagrant::MachineClient.new(machine_arg.serverAddr) machine = mclient.get_machine(machine_arg.resource_id, ui_client) - LOG.debug("got machine: " + machine.name) + LOG.debug("got machine: ") + LOG.debug(machine.name) LOG.debug("using provider: " + machine.provider_name) machine end