diff --git a/lib/vagrant/environment/remote.rb b/lib/vagrant/environment/remote.rb index 4f73dec32..51fe42ea3 100644 --- a/lib/vagrant/environment/remote.rb +++ b/lib/vagrant/environment/remote.rb @@ -68,6 +68,14 @@ module Vagrant hook(:environment_load, runner: Action::Runner.new(env: self)) end + # Returns the host object associated with this environment. + # + # @return [Class] + def host + h = @client.host + Vagrant::Host.new(h, nil, nil, self) + end + # Gets a target (machine) by name # # @param [String] machine name diff --git a/lib/vagrant/host.rb b/lib/vagrant/host.rb index 7b6ef2b76..2bc9d8793 100644 --- a/lib/vagrant/host.rb +++ b/lib/vagrant/host.rb @@ -9,6 +9,8 @@ module Vagrant class Host include CapabilityHost + autoload :Remote, "vagrant/host/remote" + def initialize(host, hosts, capabilities, env) initialize_capabilities!(host, hosts, capabilities, env) end diff --git a/lib/vagrant/host/remote.rb b/lib/vagrant/host/remote.rb new file mode 100644 index 000000000..45f0bda2f --- /dev/null +++ b/lib/vagrant/host/remote.rb @@ -0,0 +1,57 @@ +module Vagrant + class Host + # This module enables Host for server mode + module Remote + + # Add an attribute accesor for the client + # when applied to the Guest class + def self.prepended(klass) + klass.class_eval do + attr_accessor :client + end + end + + # @param [] host client + # @param hosts - unused + # @param capabilities - unused + # @param [Vagrant::Environment] + def initialize(host, hosts, capabilities, env) + @env = env + @client = host + @logger = Log4r::Logger.new("vagrant::host") + end + + def initialize_capabilities!(host, hosts, capabilities, *args) + # no-op + end + + # Executes the capability with the given name, optionally passing more + # arguments onwards to the capability. If the capability returns a value, + # it will be returned. + # + # @param [Symbol] cap_name Name of the capability + def capability(cap_name, *args) + @logger.debug("running remote host capability #{cap_name} with args #{args}") + if !client.has_capability?(cap_name) + raise Errors::GuestCapabilityNotFound, + cap: cap_name.to_s, + guest: name + end + client.capability(cap_name, @env.to_proto, *args) + end + + # Tests whether the given capability is possible. + # + # @param [Symbol] cap_name Capability name + # @return [Boolean] + def capability?(cap_name) + @logger.debug("checking for remote host capability #{cap_name}") + client.has_capability?(cap_name) + end + + def to_proto + client.proto + end + end + end +end diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index 7dcc937b1..fcf385f8f 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -242,6 +242,7 @@ module Vagrant SERVER_MODE_CALLBACKS = [ ->{ Vagrant::Guest.prepend(Vagrant::Guest::Remote) }, + ->{ Vagrant::Host.prepend(Vagrant::Host::Remote) }, ->{ Vagrant::Machine.prepend(Vagrant::Machine::Remote) }, ->{ Vagrant::Environment.prepend(Vagrant::Environment::Remote) }, ->{ Vagrant::MachineIndex.prepend(Vagrant::MachineIndex::Remote) },