commands/rdp: no need fo rthe guest cap

This commit is contained in:
Mitchell Hashimoto 2014-04-12 16:16:57 -07:00
parent 617cf630b1
commit 5b960efcb1
5 changed files with 41 additions and 69 deletions

View File

@ -25,12 +25,7 @@ module VagrantPlugins
raise Vagrant::Errors::VMNotCreatedError raise Vagrant::Errors::VMNotCreatedError
end end
if !machine.guest.capability?(:rdp_info) rdp_info = get_rdp_info(machine)
raise Errors::GuestUnsupported,
name: machine.guest.name.to_s
end
rdp_info = machine.guest.capability(:rdp_info)
if !rdp_info if !rdp_info
raise Errors::RDPUndetected raise Errors::RDPUndetected
end end
@ -38,6 +33,46 @@ module VagrantPlugins
@env.host.capability(:rdp_client, rdp_info) @env.host.capability(:rdp_client, rdp_info)
end end
end end
protected
def get_rdp_info(machine)
ssh_info = machine.ssh_info
username = ssh_info[:username]
if machine.config.vm.communicator == :winrm
username = machine.config.winrm.username
end
host = ssh_info[:host]
port = 3389
if host == "127.0.0.1"
# We need to find a forwarded port...
search_port = 3389
ports = nil
if machine.provider.capability?(:forwarded_ports)
ports = machine.provider.capability(:forwarded_ports)
else
ports = {}.tap do |result|
machine.config.vm.networks.each do |type, netopts|
next if type != :forwarded_port
next if !netopts[:host]
result[netopts[:host]] = netopts[:guest]
end
end
end
ports = ports.invert
port = ports[search_port]
return nil if !port
end
return {
host: host,
port: port,
username: username,
}
end
end end
end end
end end

View File

@ -6,10 +6,6 @@ module VagrantPlugins
error_namespace("vagrant_rdp.errors") error_namespace("vagrant_rdp.errors")
end end
class GuestUnsupported < RDPError
error_key(:guest_unsupported)
end
class HostUnsupported < RDPError class HostUnsupported < RDPError
error_key(:host_unsupported) error_key(:host_unsupported)
end end

View File

@ -1,45 +0,0 @@
module VagrantPlugins
module GuestWindows
module Cap
class RDP
def self.rdp_info(machine)
ssh_info = machine.ssh_info
username = ssh_info[:username]
if machine.config.vm.communicator == :winrm
username = machine.config.winrm.username
end
host = ssh_info[:host]
port = 3389
if host == "127.0.0.1"
# We need to find a forwarded port...
search_port = 3389
ports = nil
if machine.provider.capability?(:forwarded_ports)
ports = machine.provider.capability(:forwarded_ports)
else
ports = {}.tap do |result|
machine.config.vm.networks.each do |type, netopts|
next if type != :forwarded_port
next if !netopts[:host]
result[netopts[:host]] = netopts[:guest]
end
end
end
ports = ports.invert
port = ports[search_port]
return nil if !port
end
return {
host: host,
port: port,
username: username,
}
end
end
end
end
end

View File

@ -49,11 +49,6 @@ module VagrantPlugins
Cap::MountSharedFolder Cap::MountSharedFolder
end end
guest_capability(:windows, :rdp_info) do
require_relative "cap/rdp"
Cap::RDP
end
guest_capability(:windows, :wait_for_reboot) do guest_capability(:windows, :wait_for_reboot) do
require_relative "cap/reboot" require_relative "cap/reboot"
Cap::Reboot Cap::Reboot

View File

@ -1,15 +1,6 @@
en: en:
vagrant_rdp: vagrant_rdp:
errors: errors:
guest_unsupported: |-
The guest OS detected by Vagrant ('%{name}') is reporting
that it does not supported RDP connections. If this is an
error, it is because Vagrant does not know how to connect
via RDP to this guest.
Please open an issue documenting how to connect via RDP
to this guest OS and we can fix this.
host_unsupported: |- host_unsupported: |-
Vagrant doesn't support running an RDP client on your Vagrant doesn't support running an RDP client on your
host OS. Currently only Windows is supported for RDP host OS. Currently only Windows is supported for RDP