From fd74318bf5db1e2f9be1c6bca4c6b35454b5387a Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 21 Jan 2021 10:11:21 -0600 Subject: [PATCH] Pass ui to machine --- lib/vagrant/environment.rb | 8 +++- lib/vagrant/machine.rb | 48 ++++++++++++++++++- lib/vagrant/ui.rb | 17 ------- .../serve/service/provider_service.rb | 11 +++-- 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index c8f1f676d..34d500a11 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -80,6 +80,7 @@ module Vagrant home_path: nil, local_data_path: nil, ui_class: nil, + ui_opts: nil, vagrantfile_name: nil, }.merge(opts || {}) @@ -106,8 +107,13 @@ module Vagrant @cwd = opts[:cwd] @home_path = opts[:home_path] @vagrantfile_name = opts[:vagrantfile_name] - @ui = opts[:ui_class].new @ui_class = opts[:ui_class] + @ui = opts[:ui_class].new + # if opts[:ui_opts].nil? + # @ui = opts[:ui_class].new + # else + # @ui = opts[:ui_class].new(**opts[:ui_opts]) + # end # This is the batch lock, that enforces that only one {BatchAction} # runs at a time from {#batch}. diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 53ed08ebf..6985ecdcb 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -24,7 +24,27 @@ module Vagrant # # @param [String] machine id # @return [Machine] - def get_machine(id) + # def get_machine(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) + # m = resp_machine.name + + # provider_plugin = Vagrant.plugin("2").manager.providers[:virtualbox] + # provider_cls = provider_plugin[0] + # provider_options = provider_plugin[1] + + # Machine.new( + # m, "virtualbox", provider_cls, + # {}, provider_options, {}, + # "", "", {}, nil, + # base=false, client=@client + # ) + # end + + def get_machine(id, ui_client=nil) machine_ref = Hashicorp::Vagrant::Sdk::Ref::Machine.new(resource_id: id) req = Hashicorp::Vagrant::Sdk::Machine::GetNameRequest.new( machine: machine_ref @@ -36,10 +56,34 @@ module Vagrant provider_cls = provider_plugin[0] provider_options = provider_plugin[1] + box_req = Hashicorp::Vagrant::Sdk::Machine::BoxRequest.new( + machine: machine_ref + ) + resp_box = @client.box(box_req) + box = Vagrant::Box.new( + resp_box.box.name, resp_box.box.provider.to_sym, + resp_box.box.version, Pathname.new(resp_box.box.directory), + ) + + if ui_client.nil? + ui_opts = nil + else + ui_opts = [ui_client] + end + + env = Vagrant::Environment.new( + cwd: "/Users/sophia/project/vagrant-agogo", + home_path: "/Users/sophia/.vagrant.d", + ui_class: Vagrant::UI::RemoteUI, + ui_opts: ui_opts, + vagrantfile_name: "Vagrantfile", + ) + Machine.new( m, "virtualbox", provider_cls, {}, provider_options, {}, - "", "", {}, nil, + Pathname.new("/Users/sophia/.vagrant.d/data"), + box, env, nil, base=false, client=@client ) end diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 5710a15f6..7994dc4cc 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -259,23 +259,6 @@ module Vagrant end end - class RemoteUI < Interface - def initialize(client) - @client = client - end - - def ask(message, opts=nil) - end - - [:detail, :warn, :error, :info, :output, :success].each do |method| - define_method(method) do |message, *args, **opts| - # machine("ui", method.to_s, message, *args, **opts) - @client.output([message]) - end - end - end - - class NonInteractive < Basic def initialize super diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index cc632f51f..33d38ff3a 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -37,10 +37,10 @@ module VagrantPlugins def action_up(req, _unused_call) LOG.debug("Coming up") machine = machine_arg_to_machine(req) - raw_terminal_arg = req.args[1].value.value - ui_client = VagrantPlugins::CommandServe::Client::TerminalClient.terminal_arg_to_terminal_ui(raw_terminal_arg) - ui = Vagrant::UI::RemoteUI.new(ui_client) - ui.warn("hello from vagrant") + # raw_terminal_arg = req.args[1].value.value + # ui_client = VagrantPlugins::CommandServe::Client::TerminalClient.terminal_arg_to_terminal_ui(raw_terminal_arg) + # ui = Vagrant::UI::RemoteUI.new(ui_client) + machine.ui.warn("hello from vagrant") # ba = Vagrant::BatchAction.new # LOG.debug("registering action") @@ -53,6 +53,9 @@ module VagrantPlugins def machine_arg_to_machine(req) raw_machine_arg = req.args[0].value.value + # raw_terminal_arg = req.args[1].value.value + # ui_client = VagrantPlugins::CommandServe::Client::TerminalClient.terminal_arg_to_terminal_ui(raw_terminal_arg) + machine_arg = Hashicorp::Vagrant::Sdk::Args::Machine.decode(raw_machine_arg) LOG.debug("machine id: " + machine_arg.resource_id) LOG.debug("server addr: " + machine_arg.serverAddr)