Skip to content

Commit d5007d4

Browse files
soapy1phinze
authored andcommitted
Use remote plugin module when in server mode
1 parent e951c4d commit d5007d4

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

bin/vagrant

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ begin
199199
# Doing this prevents Vagrant from attempting to load an
200200
# Environment directly.
201201
if sub_cmd == "serve"
202+
cmd = Vagrant.plugin("2").manager.commands[:serve].first
202203
Vagrant.enable_server_mode!
203-
cmd = Vagrant.plugin("2").manager.commands[:serve].first.call
204-
result = cmd.new([], nil).execute
204+
cmd_call = cmd.call
205+
result = cmd_call.new([], nil).execute
205206
exit(result)
206207
else
207208
# Create the environment, which is the cwd of wherever the

lib/vagrant.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ module Vagrant
181181
c.register([:"2", :provisioner]) { Plugin::V2::Provisioner }
182182
c.register([:"2", :push]) { Plugin::V2::Push }
183183
c.register([:"2", :synced_folder]) { Plugin::V2::SyncedFolder }
184+
185+
c.register(:remote) { Plugin::Remote::Plugin }
184186
end
185187

186188
# Configure a Vagrant environment. The version specifies the version
@@ -229,6 +231,10 @@ def self.has_plugin?(name, version=nil)
229231
# @param [String] component
230232
# @return [Class]
231233
def self.plugin(version, component=nil)
234+
# TODO
235+
if component.nil? && Vagrant.server_mode?
236+
version = "remote"
237+
end
232238
# Build up the key and return a result
233239
key = version.to_s.to_sym
234240
key = [key, component.to_s.to_sym] if component

lib/vagrant/plugin/remote/manager.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,32 @@ def initialize()
1818
@registered = {}
1919
end
2020

21-
# This returns all the registered communicators.
21+
# This returns all the registered commands.
22+
#
23+
# @return [Registry<Symbol, Array<Proc, Hash>>]
24+
def commands
25+
@registered[:command]
26+
end
27+
28+
# This returns all the registered communicators.
2229
#
2330
# @return [Hash]
2431
def communicators
25-
registered[:communincator]
32+
@registered[:communincator]
2633
end
2734

2835
# This returns all the registered guests.
2936
#
3037
# @return [Hash]
3138
def guests
32-
registered[:guest]
39+
@registered[:guest]
3340
end
3441

3542
# This returns all the registered guests.
3643
#
3744
# @return [Hash]
3845
def hosts
39-
registered[:host]
46+
@registered[:host]
4047
end
4148

4249
# This returns all synced folder implementations.

lib/vagrant/plugin/remote/plugin.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@ module Vagrant
22
module Plugin
33
module Remote
44
# This is the wrapper class for all Remote plugins.
5-
class Plugin
5+
class Plugin < Vagrant::Plugin::V2::Plugin
6+
7+
# This returns the manager for all Remote plugins.
8+
#
9+
# @return [Remote::Manager]
10+
def self.manager
11+
@manager ||= Manager.new
12+
end
13+
14+
# Returns the {Components} for this plugin.
15+
#
16+
# @return [Components]
17+
def self.components
18+
@components ||= Vagrant::Plugin::V2::Components.new
19+
end
620
end
721
end
822
end

plugins/commands/serve/service/guest_service.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class GuestService < Hashicorp::Vagrant::Sdk::GuestService::Service
88
include CapabilityPlatformService
99

1010
def initialize(*args, **opts, &block)
11-
caps = Vagrant.plugin("2").manager.guest_capabilities
11+
caps = Vagrant::Plugin::V2::Plugin.manager.guest_capabilities
1212
default_args = {
1313
Client::Target => SDK::FuncSpec::Value.new(
1414
type: "hashicorp.vagrant.sdk.Args.Target",
@@ -40,7 +40,7 @@ def detect(req, ctx)
4040
with_info(ctx) do |info|
4141
plugin_name = info.plugin_name
4242
machine = mapper.funcspec_map(req, expect: Vagrant::Machine)
43-
plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first
43+
plugin = Vagrant::Plugin::V2::Plugin.manager.guests[plugin_name.to_s.to_sym].to_a.first
4444
if !plugin
4545
logger.debug("Failed to locate guest plugin for: #{plugin_name}")
4646
raise "Failed to locate guest plugin for: #{plugin_name.inspect}"
@@ -72,7 +72,7 @@ def parent_spec(*_)
7272
def parent(req, ctx)
7373
with_info(ctx) do |info|
7474
plugin_name = info.plugin_name
75-
guest_hash = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a
75+
guest_hash = Vagrant::Plugin::V2::Plugin.manager.guests[plugin_name.to_s.to_sym].to_a
7676
plugin = guest_hash.first
7777
if !plugin
7878
raise "Failed to locate guest plugin for: #{plugin_name.inspect}"

plugins/commands/serve/service/host_service.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class HostService < Hashicorp::Vagrant::Sdk::HostService::Service
88
include CapabilityPlatformService
99

1010
def initialize(*args, **opts, &block)
11-
caps = Vagrant.plugin("2").manager.host_capabilities
11+
caps =Vagrant::Plugin::V2::Plugin.manager.host_capabilities
1212
default_args = {
1313
Vagrant::Environment => SDK::FuncSpec::Value.new(
1414
type: "hashicorp.vagrant.sdk.Args.Project",
@@ -39,7 +39,7 @@ def detect(req, ctx)
3939
with_info(ctx) do |info|
4040
plugin_name = info.plugin_name
4141
statebag = mapper.funcspec_map(req, expect: Client::StateBag)
42-
plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first
42+
plugin = Vagrant::Plugin::V2::Plugin.manager.hosts[plugin_name.to_s.to_sym].to_a.first
4343
if !plugin
4444
raise "Failed to locate host plugin for: #{plugin_name.inspect}"
4545
end
@@ -70,7 +70,7 @@ def parent_spec(*_)
7070
def parent(req, ctx)
7171
with_info(ctx) do |info|
7272
plugin_name = info.plugin_name
73-
host_hash = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a
73+
host_hash = Vagrant::Plugin::V2::Plugin.manager.hosts[plugin_name.to_s.to_sym].to_a
7474
plugin = host_hash.first
7575
if !plugin
7676
raise "Failed to locate host plugin for: #{plugin_name.inspect}"

plugins/commands/serve/service/synced_folder_service.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def usable(req, ctx)
4343
project = target.project
4444
env = Vagrant::Environment.new({client: project})
4545
machine = env.machine(target.name.to_sym, target.provider_name.to_sym)
46-
46+
4747
sf = get_synced_folder_plugin(plugin_name)
4848
logger.debug("got sf #{sf}")
4949
usable = sf.usable?(machine)
@@ -153,9 +153,9 @@ def cleanup(req, ctx)
153153
end
154154

155155
private
156-
156+
157157
def get_synced_folder_plugin(plugin_name)
158-
synced_folders = Vagrant.plugin("2").manager.synced_folders
158+
synced_folders = Vagrant::Plugin::V2::Plugin.manager.synced_folders
159159
logger.debug("got synced folders #{synced_folders}")
160160
plugin = [plugin_name.to_s.to_sym].to_a.first
161161
logger.debug("got plugin #{plugin}")

0 commit comments

Comments
 (0)