diff --git a/lib/vagrant/guest.rb b/lib/vagrant/guest.rb index c9d1e9af1..575669188 100644 --- a/lib/vagrant/guest.rb +++ b/lib/vagrant/guest.rb @@ -21,6 +21,8 @@ module Vagrant class Guest include CapabilityHost + autoload :Remote, "vagrant/guest/remote" + def initialize(machine, guests, capabilities) @capabilities = capabilities @guests = guests diff --git a/lib/vagrant/guest/remote.rb b/lib/vagrant/guest/remote.rb new file mode 100644 index 000000000..a0d81541a --- /dev/null +++ b/lib/vagrant/guest/remote.rb @@ -0,0 +1,63 @@ +module Vagrant + class Guest + # This module enables Guests 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 + + def initialize(machine, guests, capabilities) + @capabilities = capabilities + @guests = guests + @machine = machine + @logger = Log4r::Logger.new("vagrant::guest") + end + + def initialize_capabilities!(host, hosts, capabilities, *args) + # no-op + end + + def detect! + # no-op + # This operation not happen in Ruby, instead rely + # on getting the guest from the remote machine + 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 guest capability #{cap_name} with args #{args}") + if !client.capability?(cap_name) + raise Errors::GuestCapabilityNotFound, + cap: cap_name.to_s, + guest: name + end + client.capability(cap_name, @machine.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 guest capability #{cap_name}") + client.capability?(cap_name) + end + + # Returns the specified or detected guest type name. + # + # @return [Symbol] + def name + client.parents[0] + end + end + end +end diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index 7b8c51339..7dcc937b1 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -241,6 +241,7 @@ module Vagrant end SERVER_MODE_CALLBACKS = [ + ->{ Vagrant::Guest.prepend(Vagrant::Guest::Remote) }, ->{ Vagrant::Machine.prepend(Vagrant::Machine::Remote) }, ->{ Vagrant::Environment.prepend(Vagrant::Environment::Remote) }, ->{ Vagrant::MachineIndex.prepend(Vagrant::MachineIndex::Remote) }, diff --git a/plugins/commands/serve/client/guest.rb b/plugins/commands/serve/client/guest.rb index 3d18cf1e6..3effcce5a 100644 --- a/plugins/commands/serve/client/guest.rb +++ b/plugins/commands/serve/client/guest.rb @@ -21,6 +21,17 @@ module VagrantPlugins self.new(connect(proto: g, broker: broker), broker) end + # @return [] parents + def parents + @logger.debug("getting parents") + req = SDK::FuncSpec::Args.new( + args: [] + ) + res = client.parents(req) + @logger.debug("got parents #{res}") + res.parents + end + # @param [Symbol] cap_name Capability name # @return [Boolean] def capability?(cap_name) @@ -34,7 +45,7 @@ module VagrantPlugins )] ) res = client.has_capability(req) - @logger.debug("got resutl #{res}") + @logger.debug("got result #{res}") res.has_capability end