From 5b960efcb1d21c82ebd92dac594b2baed95d0566 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 12 Apr 2014 16:16:57 -0700 Subject: [PATCH] commands/rdp: no need fo rthe guest cap --- plugins/commands/rdp/command.rb | 47 +++++++++++++++++++++++++++---- plugins/commands/rdp/errors.rb | 4 --- plugins/guests/windows/cap/rdp.rb | 45 ----------------------------- plugins/guests/windows/plugin.rb | 5 ---- templates/locales/command_rdp.yml | 9 ------ 5 files changed, 41 insertions(+), 69 deletions(-) delete mode 100644 plugins/guests/windows/cap/rdp.rb diff --git a/plugins/commands/rdp/command.rb b/plugins/commands/rdp/command.rb index bcdde61bf..0ce3b9c4d 100644 --- a/plugins/commands/rdp/command.rb +++ b/plugins/commands/rdp/command.rb @@ -25,12 +25,7 @@ module VagrantPlugins raise Vagrant::Errors::VMNotCreatedError end - if !machine.guest.capability?(:rdp_info) - raise Errors::GuestUnsupported, - name: machine.guest.name.to_s - end - - rdp_info = machine.guest.capability(:rdp_info) + rdp_info = get_rdp_info(machine) if !rdp_info raise Errors::RDPUndetected end @@ -38,6 +33,46 @@ module VagrantPlugins @env.host.capability(:rdp_client, rdp_info) 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 diff --git a/plugins/commands/rdp/errors.rb b/plugins/commands/rdp/errors.rb index 873441fb0..6147b9fbf 100644 --- a/plugins/commands/rdp/errors.rb +++ b/plugins/commands/rdp/errors.rb @@ -6,10 +6,6 @@ module VagrantPlugins error_namespace("vagrant_rdp.errors") end - class GuestUnsupported < RDPError - error_key(:guest_unsupported) - end - class HostUnsupported < RDPError error_key(:host_unsupported) end diff --git a/plugins/guests/windows/cap/rdp.rb b/plugins/guests/windows/cap/rdp.rb deleted file mode 100644 index bc4c5be8c..000000000 --- a/plugins/guests/windows/cap/rdp.rb +++ /dev/null @@ -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 diff --git a/plugins/guests/windows/plugin.rb b/plugins/guests/windows/plugin.rb index c5e74a629..fa1408314 100644 --- a/plugins/guests/windows/plugin.rb +++ b/plugins/guests/windows/plugin.rb @@ -49,11 +49,6 @@ module VagrantPlugins Cap::MountSharedFolder end - guest_capability(:windows, :rdp_info) do - require_relative "cap/rdp" - Cap::RDP - end - guest_capability(:windows, :wait_for_reboot) do require_relative "cap/reboot" Cap::Reboot diff --git a/templates/locales/command_rdp.yml b/templates/locales/command_rdp.yml index 3bc94b52d..7f37eefd5 100644 --- a/templates/locales/command_rdp.yml +++ b/templates/locales/command_rdp.yml @@ -1,15 +1,6 @@ en: vagrant_rdp: 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: |- Vagrant doesn't support running an RDP client on your host OS. Currently only Windows is supported for RDP