Save point: load target from project

This commit is contained in:
sophia 2021-07-06 12:06:21 -05:00 committed by Paul Hinze
parent b7ce9a8601
commit 340c2d7b19
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
6 changed files with 56 additions and 17 deletions

View File

@ -12,6 +12,20 @@ module Vagrant
super
@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.
#
# @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 [Machine]
def machine(name, provider, refresh=false)
return @client.target(name)
end
end
end
end

View File

@ -13,7 +13,7 @@ module Vagrant
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 = VagrantPlugins::CommandServe::Client::Machine.new(name: name)
@client = VagrantPlugins::CommandServe::Client::Machine.new(env: env)
@env = env
@ui = Vagrant::UI::Prefixed.new(@env.ui, name)
@provider_name = provider_name

View File

@ -7,6 +7,7 @@ module VagrantPlugins
ServiceInfo = Service::ServiceInfo
autoload :Machine, Vagrant.source_root.join("plugins/commands/serve/client/machine").to_s
autoload :Project, Vagrant.source_root.join("plugins/commands/serve/client/project").to_s
autoload :Terminal, Vagrant.source_root.join("plugins/commands/serve/client/terminal").to_s
end
end

View File

@ -18,7 +18,6 @@ module VagrantPlugins
self.new(conn.to_s)
end
def ref
SDK::Ref::Machine.new(resource_id: resource_id)
end

View File

@ -6,15 +6,32 @@ module VagrantPlugins
attr_reader :client
def initialize(conn)
@logger = Log4r::Logger.new("vagrant::command::serve::client::project")
@client = SDK::ProjectService::Stub.new(conn, :this_channel_is_insecure)
end
def self.load(raw_project)
m = SDK::Args::Project.decode(raw_project)
conn = Broker.instance.dial(m.stream_id)
def self.load(raw_project, broker:)
p = SDK::Args::Project.decode(raw_project)
conn = broker.dial(p.stream_id)
self.new(conn.to_s)
end
# Returns a machine client for the given name
def target(name)
@logger.debug("searching for target #{name}")
req = SDK::Project::TargetRequest.new(name: name)
raw_target = @client.target(req)
@logger.debug("got target #{raw_target}")
conn = broker.dial(t.stream_id)
target_service = SDK::TargetService::Stub.new(conn.to_s, :this_channel_is_insecure)
@logger.debug("specializing target")
machine = target_service.specialize(Google::Protobuf::Any.new)
m = SDK::Args::Target::Machine.decode(machine.value)
conn = broker.dial(m.stream_id)
return Machine.new(conn)
end
end
end
end

View File

@ -87,23 +87,31 @@ module VagrantPlugins
LOG.debug("machine name: #{machine_service.name(Google::Protobuf::Empty.new).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)
arguments = SDK::Command::Arguments.decode(raw_args)
ui_client = Client::Terminal.load(raw_terminal, broker: broker)
ui = Vagrant::UI::RemoteUI.new(ui_client)
env = Vagrant::Environment.new(
{ui: ui, client: env_client}
)
ui = Vagrant::UI::RemoteUI.new(ui_client)
env = Vagrant::Environment.new(ui: ui)
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
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}"
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)
result = 1