frapposelli/vagrant-vcloud — pull request #61 by StefanScherer (2014-05-18 15:06:23+00:00)
Title: Add capability forwarded ports

I have added the provider capability forwarded_ports so Vagrant 1.6.2 can retrieve the correct port number for winrm if the guest is driven with the new winrm communicator.

My `Vagrantfile`:

```ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

if Vagrant.has_plugin?("vagrant-vcloud")
config.vm.provider :vcloud do |vcloud|
vcloud.vapp_prefix = "test"
vcloud.ip_subnet = "192.168.33.1/255.255.255.0" # our test subnet with fixed IP adresses for everyone
end
end

config.vm.define :"tst" do |tst|
tst.vm.box = "windows_2008_r2"
tst.vm.hostname = "tst"

tst.vm.communicator = "winrm"
tst.vm.network :private_network, ip: "192.168.33.2", gateway: "192.168.33.1"
tst.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", auto_correct: true
tst.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true

tst.vm.provision "shell", path: "scripts/provision.ps1"
end

config.vm.define :"tst2" do |tst|
tst.vm.box = "windows_2008_r2"
tst.vm.hostname = "tst2"

tst.vm.communicator = "winrm"
tst.vm.network :private_network, ip: "192.168.33.3", gateway: "192.168.33.1"
tst.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", auto_correct: true
tst.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
tst.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true

tst.vm.provision "shell", path: "scripts/provision.ps1"
end

end
```

My provision test script `scripts/provision.ps1`:

```ps1
$box = Get-ItemProperty -Path HKLM:SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName -Name "ComputerName"
$box = $box.ComputerName.ToString().ToLower()

Write-Host "This guest box is $box (registry ComputerName)"
Write-Host "This guest box is $env:COMPUTERNAME (env COMPUTERNAME)"
```

Without the change, the provisioning of the `tst2` box will go into the first one with the default 55985 port from Vagrant 1.6.2.

This will also help making the `vagrant rdp` command work in the near future, but there still is a bug in Vagrant 1.6.2 which does not use the capability to get the correct port, so it always uses 3389 which is always the box that has the edge gateway port forwarding 3389 -> 3389.

See [Vagrant issue 3832](https://github.com/mitchellh/vagrant/issues/3832) for more details.