Pass ui to machine
This commit is contained in:
parent
12627a78a3
commit
fd74318bf5
@ -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}.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user