diff --git a/bin/vagrant b/bin/vagrant index 8470c7087..7ca30b391 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -199,9 +199,10 @@ begin # Doing this prevents Vagrant from attempting to load an # Environment directly. if sub_cmd == "serve" + cmd = Vagrant.plugin("2").manager.commands[:serve].first Vagrant.enable_server_mode! - cmd = Vagrant.plugin("2").manager.commands[:serve].first.call - result = cmd.new([], nil).execute + cmd_call = cmd.call + result = cmd_call.new([], nil).execute exit(result) else # Create the environment, which is the cwd of wherever the diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 651d53452..128b42d69 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -181,6 +181,8 @@ module Vagrant c.register([:"2", :provisioner]) { Plugin::V2::Provisioner } c.register([:"2", :push]) { Plugin::V2::Push } c.register([:"2", :synced_folder]) { Plugin::V2::SyncedFolder } + + c.register(:remote) { Plugin::Remote::Plugin } end # Configure a Vagrant environment. The version specifies the version @@ -229,6 +231,10 @@ module Vagrant # @param [String] component # @return [Class] def self.plugin(version, component=nil) + # TODO + if component.nil? && Vagrant.server_mode? + version = "remote" + end # Build up the key and return a result key = version.to_s.to_sym key = [key, component.to_s.to_sym] if component diff --git a/lib/vagrant/plugin/remote/manager.rb b/lib/vagrant/plugin/remote/manager.rb index c220dd414..d86183fee 100644 --- a/lib/vagrant/plugin/remote/manager.rb +++ b/lib/vagrant/plugin/remote/manager.rb @@ -18,25 +18,32 @@ module Vagrant @registered = {} end - # This returns all the registered communicators. + # This returns all the registered commands. + # + # @return [Registry>] + def commands + @registered[:command] + end + + # This returns all the registered communicators. # # @return [Hash] def communicators - registered[:communincator] + @registered[:communincator] end # This returns all the registered guests. # # @return [Hash] def guests - registered[:guest] + @registered[:guest] end # This returns all the registered guests. # # @return [Hash] def hosts - registered[:host] + @registered[:host] end # This returns all synced folder implementations. diff --git a/lib/vagrant/plugin/remote/plugin.rb b/lib/vagrant/plugin/remote/plugin.rb index 049f066fd..8af39ed14 100644 --- a/lib/vagrant/plugin/remote/plugin.rb +++ b/lib/vagrant/plugin/remote/plugin.rb @@ -2,7 +2,21 @@ module Vagrant module Plugin module Remote # This is the wrapper class for all Remote plugins. - class Plugin + class Plugin < Vagrant::Plugin::V2::Plugin + + # This returns the manager for all Remote plugins. + # + # @return [Remote::Manager] + def self.manager + @manager ||= Manager.new + end + + # Returns the {Components} for this plugin. + # + # @return [Components] + def self.components + @components ||= Vagrant::Plugin::V2::Components.new + end end end end diff --git a/plugins/commands/serve/service/guest_service.rb b/plugins/commands/serve/service/guest_service.rb index 3bce7980b..652d64032 100644 --- a/plugins/commands/serve/service/guest_service.rb +++ b/plugins/commands/serve/service/guest_service.rb @@ -8,7 +8,7 @@ module VagrantPlugins include CapabilityPlatformService def initialize(*args, **opts, &block) - caps = Vagrant.plugin("2").manager.guest_capabilities + caps = Vagrant::Plugin::V2::Plugin.manager.guest_capabilities default_args = { Client::Target => SDK::FuncSpec::Value.new( type: "hashicorp.vagrant.sdk.Args.Target", @@ -40,7 +40,7 @@ module VagrantPlugins with_info(ctx) do |info| plugin_name = info.plugin_name machine = mapper.funcspec_map(req, expect: Vagrant::Machine) - plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first + plugin = Vagrant::Plugin::V2::Plugin.manager.guests[plugin_name.to_s.to_sym].to_a.first if !plugin logger.debug("Failed to locate guest plugin for: #{plugin_name}") raise "Failed to locate guest plugin for: #{plugin_name.inspect}" @@ -72,7 +72,7 @@ module VagrantPlugins def parent(req, ctx) with_info(ctx) do |info| plugin_name = info.plugin_name - guest_hash = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a + guest_hash = Vagrant::Plugin::V2::Plugin.manager.guests[plugin_name.to_s.to_sym].to_a plugin = guest_hash.first if !plugin raise "Failed to locate guest plugin for: #{plugin_name.inspect}" diff --git a/plugins/commands/serve/service/host_service.rb b/plugins/commands/serve/service/host_service.rb index 942ab1620..be6215e80 100644 --- a/plugins/commands/serve/service/host_service.rb +++ b/plugins/commands/serve/service/host_service.rb @@ -8,7 +8,7 @@ module VagrantPlugins include CapabilityPlatformService def initialize(*args, **opts, &block) - caps = Vagrant.plugin("2").manager.host_capabilities + caps =Vagrant::Plugin::V2::Plugin.manager.host_capabilities default_args = { Vagrant::Environment => SDK::FuncSpec::Value.new( type: "hashicorp.vagrant.sdk.Args.Project", @@ -39,7 +39,7 @@ module VagrantPlugins with_info(ctx) do |info| plugin_name = info.plugin_name statebag = mapper.funcspec_map(req, expect: Client::StateBag) - plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first + plugin = Vagrant::Plugin::V2::Plugin.manager.hosts[plugin_name.to_s.to_sym].to_a.first if !plugin raise "Failed to locate host plugin for: #{plugin_name.inspect}" end @@ -70,7 +70,7 @@ module VagrantPlugins def parent(req, ctx) with_info(ctx) do |info| plugin_name = info.plugin_name - host_hash = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a + host_hash = Vagrant::Plugin::V2::Plugin.manager.hosts[plugin_name.to_s.to_sym].to_a plugin = host_hash.first if !plugin raise "Failed to locate host plugin for: #{plugin_name.inspect}" diff --git a/plugins/commands/serve/service/synced_folder_service.rb b/plugins/commands/serve/service/synced_folder_service.rb index 9b4ed4245..d17f7185f 100644 --- a/plugins/commands/serve/service/synced_folder_service.rb +++ b/plugins/commands/serve/service/synced_folder_service.rb @@ -43,7 +43,7 @@ module VagrantPlugins project = target.project env = Vagrant::Environment.new({client: project}) machine = env.machine(target.name.to_sym, target.provider_name.to_sym) - + sf = get_synced_folder_plugin(plugin_name) logger.debug("got sf #{sf}") usable = sf.usable?(machine) @@ -153,9 +153,9 @@ module VagrantPlugins end private - + def get_synced_folder_plugin(plugin_name) - synced_folders = Vagrant.plugin("2").manager.synced_folders + synced_folders = Vagrant::Plugin::V2::Plugin.manager.synced_folders logger.debug("got synced folders #{synced_folders}") plugin = [plugin_name.to_s.to_sym].to_a.first logger.debug("got plugin #{plugin}")