vaguerent/plugins/commands/serve/service/provider_service.rb

84 lines
2.4 KiB
Ruby

require 'vagrant/machine'
require 'vagrant/batch_action'
require 'vagrant/ui'
require_relative '../client/terminal_client'
require_relative "exception_logger"
module VagrantPlugins
module CommandServe
module Service
class ProviderService < Hashicorp::Vagrant::Sdk::ProviderService::Service
prepend VagrantPlugins::CommandServe::Service::ExceptionLogger
[:usable, :installed, :init, :action_up].each do |method|
VagrantPlugins::CommandServe::Service::ExceptionLogger.log_exception method
end
def usable(req, _unused_call)
nil
end
def usable_spec(req, _unused_call)
nil
end
def installed(req, _unused_call)
nil
end
def installed_spec(req, _unused_call)
nil
end
def init(req, _unused_call)
nil
end
def init_spec(req, _unused_call)
nil
end
def action_up(req, _unused_call)
machine = machine_arg_to_machine(req)
machine.ui.warn("hello from vagrant")
Hashicorp::Vagrant::Sdk::Provider::ActionResp.new(success: true)
end
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)
mclient = Vagrant::MachineClient.new(machine_arg.serverAddr)
machine = mclient.get_machine(machine_arg.resource_id, ui_client)
machine
end
def action_up_spec(req, _unused_call)
args = [
Hashicorp::Vagrant::Sdk::FuncSpec::Value.new(
type: "hashicorp.vagrant.sdk.Args.TerminalUI",
name: ""
),
Hashicorp::Vagrant::Sdk::FuncSpec::Value.new(
type: "hashicorp.vagrant.sdk.Args.Machine",
name: ""
),
]
result = [
Hashicorp::Vagrant::Sdk::FuncSpec::Value.new(
type: "hashicorp.vagrant.sdk.Provider.ActionResp",
name: ""
),
]
Hashicorp::Vagrant::Sdk::FuncSpec.new(
args: args,
result: result
)
end
end
end
end
end