Mitchell Hashimoto e0ec679838 vagrant ssh with full console works with new provider.
This works by now calling the `:ssh` action on the provider. This action
is allowed to do whatever it pleases, but should at some point probably
call the `SSHExec` built-in middleware.

The `SSHExec` built-in middleware was added. This uses the information
returned by `Machine#ssh_info` and uses the `Vagrant::Util::SSH` helper
to exec into the remote machine. The provider should do any work upfront
in verifying that the machine is ready to be SSHed into.
2012-08-05 13:45:24 -07:00

59 lines
1.7 KiB
Ruby

module VagrantPlugins
module ProviderVirtualBox
class Provider < Vagrant.plugin("1", :provider)
attr_reader :driver
def initialize(machine)
@machine = machine
@driver = Driver::Meta.new(@machine.id)
end
# @see Vagrant::Plugin::V1::Provider#action
def action(name)
# Attempt to get the action method from the Action class if it
# exists, otherwise return nil to show that we don't support the
# given action.
action_method = "action_#{name}"
return Action.send(action_method) if Action.respond_to?(action_method)
nil
end
# Returns the SSH info for accessing the VirtualBox VM.
def ssh_info
# If the VM is not created then we cannot possibly SSH into it, so
# we return nil.
return nil if state == :not_created
# Return what we know. The host is always "127.0.0.1" because
# VirtualBox VMs are always local. The port we try to discover
# by reading the forwarded ports.
return {
:host => "127.0.0.1",
:port => @driver.ssh_port(@machine.config.ssh.guest_port)
}
end
# Return the state of VirtualBox virtual machine by actually
# querying VBoxManage.
#
# @return [Symbol]
def state
return :not_created if !@driver.uuid
state = @driver.read_state
return :unknown if !state
state
end
# Returns a human-friendly string version of this provider which
# includes the machine's ID that this provider represents, if it
# has one.
#
# @return [String]
def to_s
id = @machine.id ? @machine.id : "new VM"
"VirtualBox (#{id})"
end
end
end
end