From ced8f947f82b414128c8e71dc787f88d0957a0f6 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 29 Jun 2022 16:11:30 -0700 Subject: [PATCH 1/6] Modify ordering of attributes --- internal/plugin/plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index 28cb380d4..bdb8b6d28 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -47,8 +47,8 @@ type Plugin struct { Location string // Location of the plugin (generally path to binary) Mappers []*argmapper.Func // Plugin specific mappers Name string // Name of the plugin - Types []component.Type // Component types supported by this plugin Options map[component.Type]interface{} // Options for supported components + Types []component.Type // Component types supported by this plugin cleaner cleanup.Cleanup // Cleanup tasks to perform on closing logger hclog.Logger From ffa10b4d85250149b3dea19ea8dd091eac8127f0 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 29 Jun 2022 16:11:53 -0700 Subject: [PATCH 2/6] Return integer value from serve command --- plugins/commands/serve/command.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/commands/serve/command.rb b/plugins/commands/serve/command.rb index 5cdb9941c..cae0e817f 100644 --- a/plugins/commands/serve/command.rb +++ b/plugins/commands/serve/command.rb @@ -128,6 +128,7 @@ module VagrantPlugins STDOUT.flush logger.info("Vagrant GRPC service is now running addr=#{bind_addr.inspect} port=#{port.inspect}") s.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT', 'SIGINT']) + 1 ensure logger.info("Vagrant GRPC service is shutting down") end From 29a5c1b855174f914b08016cd8569991fecdc595 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 29 Jun 2022 16:12:36 -0700 Subject: [PATCH 3/6] Add rpc for getting commands --- internal/server/proto/ruby_vagrant/ruby-server.proto | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/server/proto/ruby_vagrant/ruby-server.proto b/internal/server/proto/ruby_vagrant/ruby-server.proto index 0171b3300..4209f5064 100644 --- a/internal/server/proto/ruby_vagrant/ruby-server.proto +++ b/internal/server/proto/ruby_vagrant/ruby-server.proto @@ -14,6 +14,7 @@ import "plugin.proto"; service RubyVagrant { // Gets available ruby plugins rpc GetPlugins(google.protobuf.Empty) returns (GetPluginsResponse); + rpc GetCommands(google.protobuf.Empty) returns (GetCommandsResponse); rpc ParseVagrantfile(ParseVagrantfileRequest) returns (ParseVagrantfileResponse); rpc ParseVagrantfileProc(ParseVagrantfileProcRequest) returns (ParseVagrantfileResponse); rpc ParseVagrantfileSubvm(ParseVagrantfileSubvmRequest) returns (ParseVagrantfileResponse); @@ -86,3 +87,7 @@ message ParseVagrantfileProviderRequest { sdk.Config.RawRubyValue subvm = 1; string provider = 2; } + +message GetCommandsResponse { + repeated sdk.Command.CommandInfo commands = 1; +} From 067e6aeed139073674207407315efb8e5f9ae9df Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 29 Jun 2022 16:13:36 -0700 Subject: [PATCH 4/6] Add get commands implementation to client and server --- internal/serverclient/ruby_client.go | 13 +++++++++++++ plugins/commands/serve/service/internal_service.rb | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/internal/serverclient/ruby_client.go b/internal/serverclient/ruby_client.go index 3ff864607..a8ca6580d 100644 --- a/internal/serverclient/ruby_client.go +++ b/internal/serverclient/ruby_client.go @@ -121,3 +121,16 @@ func (r *RubyVagrantClient) ParseVagrantfileProvider(provider string, subvm *vag return resp.Data, nil } + +func (r *RubyVagrantClient) GetCommands() ([]*vagrant_plugin_sdk.Command_CommandInfo, error) { + resp, err := r.client.GetCommands( + context.Background(), + &emptypb.Empty{}, + ) + + if err != nil { + return nil, err + } + + return resp.Commands, nil +} diff --git a/plugins/commands/serve/service/internal_service.rb b/plugins/commands/serve/service/internal_service.rb index c8f0fbfd3..1b1fc248f 100644 --- a/plugins/commands/serve/service/internal_service.rb +++ b/plugins/commands/serve/service/internal_service.rb @@ -69,6 +69,16 @@ module VagrantPlugins parse_item_to_proto(config.vm.get_provider_overrides(provider)) end + def get_commands(req, _) + s = CommandService.new(broker: :stub) + infos = Vagrant.plugin("2").local_manager.commands.keys.map do |n| + s.send(:collect_command_info, n.to_s, []) + end + Hashicorp::Vagrant::GetCommandsResponse.new( + commands: infos, + ) + end + def parse_item(item) loader = Vagrant::Config::Loader.new( Vagrant::Config::VERSIONS, From e1d7962ee85810683bc3ddf733e6a0a2265358b2 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 29 Jun 2022 16:14:01 -0700 Subject: [PATCH 5/6] Generated proto updates for get commands --- .../proto/ruby_vagrant/ruby-server.pb.go | 209 ++++++++++++------ .../proto/ruby_vagrant/ruby-server_grpc.pb.go | 36 +++ .../proto/ruby_vagrant/ruby-server_pb.rb | 4 + .../ruby_vagrant/ruby-server_services_pb.rb | 1 + 4 files changed, 183 insertions(+), 67 deletions(-) diff --git a/internal/server/proto/ruby_vagrant/ruby-server.pb.go b/internal/server/proto/ruby_vagrant/ruby-server.pb.go index 882509c80..9b3b1ed2e 100644 --- a/internal/server/proto/ruby_vagrant/ruby-server.pb.go +++ b/internal/server/proto/ruby_vagrant/ruby-server.pb.go @@ -470,6 +470,53 @@ func (x *ParseVagrantfileProviderRequest) GetProvider() string { return "" } +type GetCommandsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Commands []*vagrant_plugin_sdk.Command_CommandInfo `protobuf:"bytes,1,rep,name=commands,proto3" json:"commands,omitempty"` +} + +func (x *GetCommandsResponse) Reset() { + *x = GetCommandsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_ruby_vagrant_ruby_server_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetCommandsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetCommandsResponse) ProtoMessage() {} + +func (x *GetCommandsResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_ruby_vagrant_ruby_server_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetCommandsResponse.ProtoReflect.Descriptor instead. +func (*GetCommandsResponse) Descriptor() ([]byte, []int) { + return file_proto_ruby_vagrant_ruby_server_proto_rawDescGZIP(), []int{7} +} + +func (x *GetCommandsResponse) GetCommands() []*vagrant_plugin_sdk.Command_CommandInfo { + if x != nil { + return x.Commands + } + return nil +} + var File_proto_ruby_vagrant_ruby_server_proto protoreflect.FileDescriptor var file_proto_ruby_vagrant_ruby_server_proto_rawDesc = []byte{ @@ -537,47 +584,58 @@ var file_proto_ruby_vagrant_ruby_server_proto_rawDesc = []byte{ 0x64, 0x6b, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x52, 0x61, 0x77, 0x52, 0x75, 0x62, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x05, 0x73, 0x75, 0x62, 0x76, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x32, 0xb0, 0x04, 0x0a, 0x0b, 0x52, 0x75, - 0x62, 0x79, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x12, 0x4b, 0x0a, 0x0a, 0x47, 0x65, 0x74, - 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, - 0x25, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, - 0x61, 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, - 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x2a, 0x2e, 0x68, 0x61, 0x73, - 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, - 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, - 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, - 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x73, 0x0a, 0x14, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, - 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x63, 0x12, 0x2e, 0x2e, 0x68, 0x61, - 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, - 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, - 0x50, 0x72, 0x6f, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, - 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, - 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x75, 0x0a, 0x15, 0x50, 0x61, 0x72, 0x73, - 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, - 0x6d, 0x12, 0x2f, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, - 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, - 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, - 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, - 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x7b, 0x0a, 0x18, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, - 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x32, 0x2e, 0x68, 0x61, - 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, - 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, - 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, + 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x22, 0x5d, 0x0a, 0x13, 0x47, 0x65, 0x74, + 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x46, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, + 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x73, 0x64, 0x6b, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x08, + 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x32, 0xff, 0x04, 0x0a, 0x0b, 0x52, 0x75, 0x62, + 0x79, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x12, 0x4b, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, + 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x25, + 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, + 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x26, 0x2e, 0x68, + 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, + 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, + 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x2a, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, + 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, + 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, + 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, + 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x73, 0x0a, 0x14, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x63, 0x12, 0x2e, 0x2e, 0x68, 0x61, 0x73, 0x68, + 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, + 0x6f, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, + 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x75, 0x0a, 0x15, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, + 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, 0x6d, 0x12, + 0x2f, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, - 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x41, 0x5a, 0x3f, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, - 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2f, 0x72, 0x75, 0x62, 0x79, 0x5f, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, + 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7b, 0x0a, + 0x18, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, + 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x32, 0x2e, 0x68, 0x61, 0x73, 0x68, + 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, + 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, + 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, + 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, + 0x72, 0x70, 0x2f, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x72, 0x75, 0x62, 0x79, 0x5f, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -593,7 +651,7 @@ func file_proto_ruby_vagrant_ruby_server_proto_rawDescGZIP() []byte { } var file_proto_ruby_vagrant_ruby_server_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_proto_ruby_vagrant_ruby_server_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_proto_ruby_vagrant_ruby_server_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_proto_ruby_vagrant_ruby_server_proto_goTypes = []interface{}{ (Plugin_Type)(0), // 0: hashicorp.vagrant.Plugin.Type (*GetPluginsResponse)(nil), // 1: hashicorp.vagrant.GetPluginsResponse @@ -603,35 +661,40 @@ var file_proto_ruby_vagrant_ruby_server_proto_goTypes = []interface{}{ (*ParseVagrantfileResponse)(nil), // 5: hashicorp.vagrant.ParseVagrantfileResponse (*ParseVagrantfileSubvmRequest)(nil), // 6: hashicorp.vagrant.ParseVagrantfileSubvmRequest (*ParseVagrantfileProviderRequest)(nil), // 7: hashicorp.vagrant.ParseVagrantfileProviderRequest - (*anypb.Any)(nil), // 8: google.protobuf.Any - (*vagrant_plugin_sdk.Args_ProcRef)(nil), // 9: hashicorp.vagrant.sdk.Args.ProcRef - (*vagrant_plugin_sdk.Args_Hash)(nil), // 10: hashicorp.vagrant.sdk.Args.Hash - (*vagrant_plugin_sdk.Config_RawRubyValue)(nil), // 11: hashicorp.vagrant.sdk.Config.RawRubyValue - (*emptypb.Empty)(nil), // 12: google.protobuf.Empty + (*GetCommandsResponse)(nil), // 8: hashicorp.vagrant.GetCommandsResponse + (*anypb.Any)(nil), // 9: google.protobuf.Any + (*vagrant_plugin_sdk.Args_ProcRef)(nil), // 10: hashicorp.vagrant.sdk.Args.ProcRef + (*vagrant_plugin_sdk.Args_Hash)(nil), // 11: hashicorp.vagrant.sdk.Args.Hash + (*vagrant_plugin_sdk.Config_RawRubyValue)(nil), // 12: hashicorp.vagrant.sdk.Config.RawRubyValue + (*vagrant_plugin_sdk.Command_CommandInfo)(nil), // 13: hashicorp.vagrant.sdk.Command.CommandInfo + (*emptypb.Empty)(nil), // 14: google.protobuf.Empty } var file_proto_ruby_vagrant_ruby_server_proto_depIdxs = []int32{ 2, // 0: hashicorp.vagrant.GetPluginsResponse.plugins:type_name -> hashicorp.vagrant.Plugin 0, // 1: hashicorp.vagrant.Plugin.type:type_name -> hashicorp.vagrant.Plugin.Type - 8, // 2: hashicorp.vagrant.Plugin.options:type_name -> google.protobuf.Any - 9, // 3: hashicorp.vagrant.ParseVagrantfileProcRequest.proc:type_name -> hashicorp.vagrant.sdk.Args.ProcRef - 10, // 4: hashicorp.vagrant.ParseVagrantfileResponse.data:type_name -> hashicorp.vagrant.sdk.Args.Hash - 11, // 5: hashicorp.vagrant.ParseVagrantfileSubvmRequest.subvm:type_name -> hashicorp.vagrant.sdk.Config.RawRubyValue - 11, // 6: hashicorp.vagrant.ParseVagrantfileProviderRequest.subvm:type_name -> hashicorp.vagrant.sdk.Config.RawRubyValue - 12, // 7: hashicorp.vagrant.RubyVagrant.GetPlugins:input_type -> google.protobuf.Empty - 3, // 8: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:input_type -> hashicorp.vagrant.ParseVagrantfileRequest - 4, // 9: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:input_type -> hashicorp.vagrant.ParseVagrantfileProcRequest - 6, // 10: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:input_type -> hashicorp.vagrant.ParseVagrantfileSubvmRequest - 7, // 11: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:input_type -> hashicorp.vagrant.ParseVagrantfileProviderRequest - 1, // 12: hashicorp.vagrant.RubyVagrant.GetPlugins:output_type -> hashicorp.vagrant.GetPluginsResponse - 5, // 13: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 5, // 14: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 5, // 15: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 5, // 16: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 12, // [12:17] is the sub-list for method output_type - 7, // [7:12] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 9, // 2: hashicorp.vagrant.Plugin.options:type_name -> google.protobuf.Any + 10, // 3: hashicorp.vagrant.ParseVagrantfileProcRequest.proc:type_name -> hashicorp.vagrant.sdk.Args.ProcRef + 11, // 4: hashicorp.vagrant.ParseVagrantfileResponse.data:type_name -> hashicorp.vagrant.sdk.Args.Hash + 12, // 5: hashicorp.vagrant.ParseVagrantfileSubvmRequest.subvm:type_name -> hashicorp.vagrant.sdk.Config.RawRubyValue + 12, // 6: hashicorp.vagrant.ParseVagrantfileProviderRequest.subvm:type_name -> hashicorp.vagrant.sdk.Config.RawRubyValue + 13, // 7: hashicorp.vagrant.GetCommandsResponse.commands:type_name -> hashicorp.vagrant.sdk.Command.CommandInfo + 14, // 8: hashicorp.vagrant.RubyVagrant.GetPlugins:input_type -> google.protobuf.Empty + 14, // 9: hashicorp.vagrant.RubyVagrant.GetCommands:input_type -> google.protobuf.Empty + 3, // 10: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:input_type -> hashicorp.vagrant.ParseVagrantfileRequest + 4, // 11: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:input_type -> hashicorp.vagrant.ParseVagrantfileProcRequest + 6, // 12: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:input_type -> hashicorp.vagrant.ParseVagrantfileSubvmRequest + 7, // 13: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:input_type -> hashicorp.vagrant.ParseVagrantfileProviderRequest + 1, // 14: hashicorp.vagrant.RubyVagrant.GetPlugins:output_type -> hashicorp.vagrant.GetPluginsResponse + 8, // 15: hashicorp.vagrant.RubyVagrant.GetCommands:output_type -> hashicorp.vagrant.GetCommandsResponse + 5, // 16: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 5, // 17: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 5, // 18: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 5, // 19: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 14, // [14:20] is the sub-list for method output_type + 8, // [8:14] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_proto_ruby_vagrant_ruby_server_proto_init() } @@ -724,6 +787,18 @@ func file_proto_ruby_vagrant_ruby_server_proto_init() { return nil } } + file_proto_ruby_vagrant_ruby_server_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetCommandsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -731,7 +806,7 @@ func file_proto_ruby_vagrant_ruby_server_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_ruby_vagrant_ruby_server_proto_rawDesc, NumEnums: 1, - NumMessages: 7, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go b/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go index 73b50c6d4..a29d58df6 100644 --- a/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go +++ b/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go @@ -25,6 +25,7 @@ const _ = grpc.SupportPackageIsVersion7 type RubyVagrantClient interface { // Gets available ruby plugins GetPlugins(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetPluginsResponse, error) + GetCommands(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetCommandsResponse, error) ParseVagrantfile(ctx context.Context, in *ParseVagrantfileRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) ParseVagrantfileProc(ctx context.Context, in *ParseVagrantfileProcRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) ParseVagrantfileSubvm(ctx context.Context, in *ParseVagrantfileSubvmRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) @@ -48,6 +49,15 @@ func (c *rubyVagrantClient) GetPlugins(ctx context.Context, in *emptypb.Empty, o return out, nil } +func (c *rubyVagrantClient) GetCommands(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetCommandsResponse, error) { + out := new(GetCommandsResponse) + err := c.cc.Invoke(ctx, "/hashicorp.vagrant.RubyVagrant/GetCommands", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *rubyVagrantClient) ParseVagrantfile(ctx context.Context, in *ParseVagrantfileRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) { out := new(ParseVagrantfileResponse) err := c.cc.Invoke(ctx, "/hashicorp.vagrant.RubyVagrant/ParseVagrantfile", in, out, opts...) @@ -90,6 +100,7 @@ func (c *rubyVagrantClient) ParseVagrantfileProvider(ctx context.Context, in *Pa type RubyVagrantServer interface { // Gets available ruby plugins GetPlugins(context.Context, *emptypb.Empty) (*GetPluginsResponse, error) + GetCommands(context.Context, *emptypb.Empty) (*GetCommandsResponse, error) ParseVagrantfile(context.Context, *ParseVagrantfileRequest) (*ParseVagrantfileResponse, error) ParseVagrantfileProc(context.Context, *ParseVagrantfileProcRequest) (*ParseVagrantfileResponse, error) ParseVagrantfileSubvm(context.Context, *ParseVagrantfileSubvmRequest) (*ParseVagrantfileResponse, error) @@ -104,6 +115,9 @@ type UnimplementedRubyVagrantServer struct { func (UnimplementedRubyVagrantServer) GetPlugins(context.Context, *emptypb.Empty) (*GetPluginsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetPlugins not implemented") } +func (UnimplementedRubyVagrantServer) GetCommands(context.Context, *emptypb.Empty) (*GetCommandsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCommands not implemented") +} func (UnimplementedRubyVagrantServer) ParseVagrantfile(context.Context, *ParseVagrantfileRequest) (*ParseVagrantfileResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ParseVagrantfile not implemented") } @@ -147,6 +161,24 @@ func _RubyVagrant_GetPlugins_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +func _RubyVagrant_GetCommands_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RubyVagrantServer).GetCommands(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/hashicorp.vagrant.RubyVagrant/GetCommands", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RubyVagrantServer).GetCommands(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + func _RubyVagrant_ParseVagrantfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ParseVagrantfileRequest) if err := dec(in); err != nil { @@ -230,6 +262,10 @@ var RubyVagrant_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetPlugins", Handler: _RubyVagrant_GetPlugins_Handler, }, + { + MethodName: "GetCommands", + Handler: _RubyVagrant_GetCommands_Handler, + }, { MethodName: "ParseVagrantfile", Handler: _RubyVagrant_ParseVagrantfile_Handler, diff --git a/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_pb.rb b/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_pb.rb index a7bfa3623..42300d526 100644 --- a/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_pb.rb +++ b/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_pb.rb @@ -50,6 +50,9 @@ Google::Protobuf::DescriptorPool.generated_pool.build do optional :subvm, :message, 1, "hashicorp.vagrant.sdk.Config.RawRubyValue" optional :provider, :string, 2 end + add_message "hashicorp.vagrant.GetCommandsResponse" do + repeated :commands, :message, 1, "hashicorp.vagrant.sdk.Command.CommandInfo" + end end end @@ -63,5 +66,6 @@ module Hashicorp ParseVagrantfileResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.ParseVagrantfileResponse").msgclass ParseVagrantfileSubvmRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.ParseVagrantfileSubvmRequest").msgclass ParseVagrantfileProviderRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.ParseVagrantfileProviderRequest").msgclass + GetCommandsResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.GetCommandsResponse").msgclass end end diff --git a/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb b/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb index 69b1770ae..74005343c 100644 --- a/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb +++ b/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb @@ -18,6 +18,7 @@ module Hashicorp # Gets available ruby plugins rpc :GetPlugins, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::GetPluginsResponse + rpc :GetCommands, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::GetCommandsResponse rpc :ParseVagrantfile, ::Hashicorp::Vagrant::ParseVagrantfileRequest, ::Hashicorp::Vagrant::ParseVagrantfileResponse rpc :ParseVagrantfileProc, ::Hashicorp::Vagrant::ParseVagrantfileProcRequest, ::Hashicorp::Vagrant::ParseVagrantfileResponse rpc :ParseVagrantfileSubvm, ::Hashicorp::Vagrant::ParseVagrantfileSubvmRequest, ::Hashicorp::Vagrant::ParseVagrantfileResponse From a146f3beacdafadb8556fac7dc747a6beb489d56 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 29 Jun 2022 16:14:19 -0700 Subject: [PATCH 6/6] Fetch all ruby commands in single request --- internal/core/basis.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/internal/core/basis.go b/internal/core/basis.go index 0b1191ff1..b7b67e34d 100644 --- a/internal/core/basis.go +++ b/internal/core/basis.go @@ -564,19 +564,34 @@ func (b *Basis) Host() (host core.Host, err error) { // information before an actual command is run func (b *Basis) Init() (result *vagrant_server.Job_InitResult, err error) { b.logger.Debug("running init for basis") - result = &vagrant_server.Job_InitResult{ - Commands: []*vagrant_plugin_sdk.Command_CommandInfo{}, + list, err := b.plugins.RubyClient().GetCommands() + if err != nil { + return nil, err + } + existing := map[string]struct{}{} + for _, i := range list { + existing[i.Name] = struct{}{} } - ctx := context.Background() - cmds, err := b.typeComponents(ctx, component.CommandType) + result = &vagrant_server.Job_InitResult{ + Commands: list, + } + + cmds, err := b.plugins.Typed(component.CommandType) if err != nil { return nil, err } - for _, c := range cmds { + for _, cmdName := range cmds { + if _, ok := existing[cmdName]; ok { + continue + } + c, err := b.component(b.ctx, component.CommandType, cmdName) + if err != nil { + return nil, err + } fn := c.Value.(component.Command).CommandInfoFunc() - raw, err := b.callDynamicFunc(ctx, b.logger, fn, + raw, err := b.callDynamicFunc(b.ctx, b.logger, fn, (*[]*vagrant_plugin_sdk.Command_CommandInfo)(nil), argmapper.Typed(b.ctx), )