From ae6639d30134baa491302b304bd166dd96d6a74a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 20 Jan 2021 09:42:23 -0800 Subject: [PATCH] Clean up plugin loading and compact registration --- plugins/commands/serve/command.rb | 35 +++++++------------ .../commands/serve/service/command_service.rb | 9 ----- .../commands/serve/service/plugin_service.rb | 6 +--- .../serve/service/provider_service.rb | 7 ++-- 4 files changed, 15 insertions(+), 42 deletions(-) diff --git a/plugins/commands/serve/command.rb b/plugins/commands/serve/command.rb index 4f75ae271..316b61264 100644 --- a/plugins/commands/serve/command.rb +++ b/plugins/commands/serve/command.rb @@ -1,10 +1,7 @@ -# NOTE: Update the load path so the proto files can properly require dependencies -$LOAD_PATH << File.expand_path("../service/proto/gen", __FILE__) - -require_relative './service/proto/gen/ruby-server_pb' -require_relative './service/proto/gen/ruby-server_services_pb' -require_relative './service/proto/gen/plugin_pb' -require_relative './service/proto/gen/plugin_services_pb' +require 'vagrant/proto/gen/ruby-server_pb' +require 'vagrant/proto/gen/ruby-server_services_pb' +require 'vagrant/proto/gen/plugin/plugin_pb' +require 'vagrant/proto/gen/plugin/plugin_services_pb' require_relative "./service/plugin_service" require_relative "./service/provider_service" @@ -53,23 +50,15 @@ module VagrantPlugins s = GRPC::RpcServer.new # Listen on port 10001 on all interfaces. Update for production use. s.add_http2_port("[::]:#{port}", :this_port_is_insecure) - - s.handle(VagrantPlugins::CommandServe::Serve::PluginService.new) - s.handle(VagrantPlugins::CommandServe::Serve::ProviderService.new) - s.handle(Service::InternalService.new) - s.handle(Service::HostService.new) - s.handle(Service::CommandService.new) - health_checker = Grpc::Health::Checker.new - health_checker.add_status( - Service::InternalService, - Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING) - health_checker.add_status( - Service::HostService, - Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING) - health_checker.add_status( - Service::CommandService, - Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING) + + [Service::PluginService, Service::ProviderService, Service::InternalService, + Service::HostService, Service::CommandService].each do |service_klass| + s.handle(service_klass.new) + health_checker.add_status(service_klass, + Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING) + end + s.handle(health_checker) STDOUT.puts "1|1|tcp|127.0.0.1:#{port}|grpc" diff --git a/plugins/commands/serve/service/command_service.rb b/plugins/commands/serve/service/command_service.rb index cd12cfd0c..fd05b126e 100644 --- a/plugins/commands/serve/service/command_service.rb +++ b/plugins/commands/serve/service/command_service.rb @@ -20,15 +20,6 @@ module VagrantPlugins def synopsis_spec(*args) return Hashicorp::Vagrant::Sdk::FuncSpec.new - Hashicorp::Vagrant::Sdk::FuncSpec.new( - name: "synopsis", - result: [ - Hashicorp::Vagrant::Sdk::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Command.SynopsisResp", - name: "" - ) - ] - ) end def synopsis(*args) diff --git a/plugins/commands/serve/service/plugin_service.rb b/plugins/commands/serve/service/plugin_service.rb index 87d9c35a6..c0f674244 100644 --- a/plugins/commands/serve/service/plugin_service.rb +++ b/plugins/commands/serve/service/plugin_service.rb @@ -1,12 +1,8 @@ require "vagrant/plugin/v2/plugin" - -require 'vagrant/proto/gen/ruby-server_pb' -require 'vagrant/proto/gen/ruby-server_services_pb' - module VagrantPlugins module CommandServe - module Serve + module Service class PluginService < Hashicorp::Vagrant::RubyVagrant::Service def get_plugins(req, _unused_call) plugins = [] diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index be42e2f72..342f72e8e 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -1,13 +1,10 @@ - -require 'vagrant/proto/gen/plugin/plugin_pb' -require 'vagrant/proto/gen/plugin/plugin_services_pb' require 'vagrant/machine' require 'vagrant/batch_action' require 'logger' module VagrantPlugins module CommandServe - module Serve + module Service class ProviderService < Hashicorp::Vagrant::Sdk::ProviderService::Service LOG = Logger.new('/tmp/vagrant-ruby.txt') @@ -52,7 +49,7 @@ module VagrantPlugins 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) - + mclient = Vagrant::MachineClient.new(machine_arg.serverAddr) machine = mclient.get_machine(machine_arg.resource_id) LOG.debug("got machine: " + machine.name)