Skip to content

Commit 4c8732b

Browse files
committed
Load global ruby plugins when runner starts up
1 parent 05f2879 commit 4c8732b

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

internal/serverclient/ruby_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66

7+
"github.com/golang/protobuf/ptypes/empty"
78
"github.com/hashicorp/go-hclog"
89
"github.com/hashicorp/go-plugin"
910
"google.golang.org/grpc"
@@ -58,7 +59,7 @@ func (r *RubyVagrantClient) GRPCBroker() *plugin.GRPCBroker {
5859
}
5960

6061
func (r *RubyVagrantClient) GetPlugins() ([]*ruby_vagrant.Plugin, error) {
61-
plugins, err := r.client.GetPlugins(context.Background(), &ruby_vagrant.GetPluginsRequest{})
62+
plugins, err := r.client.GetGlobalPlugins(context.Background(), &empty.Empty{})
6263
if err != nil {
6364
return nil, err
6465
}

plugins/commands/serve/service/internal_service.rb

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,47 @@ def initialize(pp)
2121
klass.new(project_path)
2222
end
2323

24-
def get_plugins(req, _)
25-
plugins = []
26-
env = vagrant_env(req.project_path)
24+
def extract_plugin_protos(plugin_manager)
25+
plugins = [[:commands, :COMMAND],
26+
[:communicators, :COMMUNICATOR],
27+
[:config, :CONFIG],
28+
[:guests, :GUEST],
29+
[:hosts, :HOST],
30+
[:provider_configs, :CONFIG],
31+
[:providers, :PROVIDER],
32+
[:provisioner_configs, :CONFIG],
33+
[:provisioners, :PROVISIONER],
34+
[:push_configs, :CONFIG],
35+
[:pushes, :PUSH],
36+
[:synced_folders, :SYNCEDFOLDER]].map do |method, const|
37+
plugin_manager.send(method).map do |k, v|
38+
Hashicorp::Vagrant::Plugin.new(
39+
name: k,
40+
type: Hashicorp::Vagrant::Plugin::Type.const_get(const),
41+
options: Google::Protobuf::Any.pack(
42+
_convert_options_to_proto(const, v)
43+
)
44+
)
45+
end
46+
end.flatten
47+
Hashicorp::Vagrant::GetPluginsResponse.new(
48+
plugins: plugins
49+
)
50+
end
51+
52+
def get_global_plugins(req, _)
2753
plugin_manager = Vagrant::Plugin::V2::Plugin.local_manager
2854
globalized_plugins = Vagrant::Plugin::Manager.instance.globalize!
55+
Vagrant::Plugin::Manager.instance.load_plugins(globalized_plugins)
56+
extract_plugin_protos(plugin_manager)
57+
end
58+
59+
def get_local_plugins(req, _)
60+
env = vagrant_env(req.project_path)
61+
plugin_manager = Vagrant::Plugin::V2::Plugin.local_manager
2962
localized_plugins = Vagrant::Plugin::Manager.instance.localize!(env)
30-
Vagrant::Plugin::Manager.instance.load_plugins(globalized_plugins.merge(localized_plugins))
31-
plugins = [[:commands, :COMMAND],
32-
[:communicators, :COMMUNICATOR],
33-
[:config, :CONFIG],
34-
[:guests, :GUEST],
35-
[:hosts, :HOST],
36-
[:provider_configs, :CONFIG],
37-
[:providers, :PROVIDER],
38-
[:provisioner_configs, :CONFIG],
39-
[:provisioners, :PROVISIONER],
40-
[:push_configs, :CONFIG],
41-
[:pushes, :PUSH],
42-
[:synced_folders, :SYNCEDFOLDER]].map do |method, const|
43-
plugin_manager.send(method).map do |k, v|
44-
Hashicorp::Vagrant::Plugin.new(
45-
name: k,
46-
type: Hashicorp::Vagrant::Plugin::Type.const_get(const),
47-
options: Google::Protobuf::Any.pack(
48-
_convert_options_to_proto(const, v)
49-
)
50-
)
51-
end
52-
end.flatten
53-
Hashicorp::Vagrant::GetPluginsResponse.new(
54-
plugins: plugins
55-
)
63+
Vagrant::Plugin::Manager.instance.load_plugins(localized_plugins)
64+
extract_plugin_protos(plugin_manager)
5665
end
5766

5867
def stop(_, _)

0 commit comments

Comments
 (0)