From 76a7c63f8bb53907c792b2244380bda445786841 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 12 Apr 2014 16:12:13 -0700 Subject: [PATCH] guests/windows: detect the port for RDP --- plugins/guests/windows/cap/rdp.rb | 27 ++++++++++++++++++++++++++- plugins/hosts/windows/cap/rdp.rb | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugins/guests/windows/cap/rdp.rb b/plugins/guests/windows/cap/rdp.rb index 2c9c1e6d9..bc4c5be8c 100644 --- a/plugins/guests/windows/cap/rdp.rb +++ b/plugins/guests/windows/cap/rdp.rb @@ -9,8 +9,33 @@ module VagrantPlugins 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: machine.provider.capability(:public_address), + host: host, + port: port, username: username, } end diff --git a/plugins/hosts/windows/cap/rdp.rb b/plugins/hosts/windows/cap/rdp.rb index f5bbce8bb..04dd17da4 100644 --- a/plugins/hosts/windows/cap/rdp.rb +++ b/plugins/hosts/windows/cap/rdp.rb @@ -11,6 +11,7 @@ module VagrantPlugins opts = { "drivestoredirect:s" => "*", "full address:s" => rdp_info[:host], + "port:i" => rdp_info[:port], "prompt for credentials:i" => "1", "username:s" => rdp_info[:username], }