frapposelli/vagrant-vcloud — pull request #77 by StefanScherer (2014-05-28 07:02:12+00:00)
Title: Fix to reuse port forwardings after vagrant destroy box + vagrant up box

This is a fix for #63 to reuse the port forwardings of a previous `vagrant up boxname` run.

Now you can do a `vagrant destroy -f boxname` and `vagrant up boxname` and have the same port forwardings. So external saved ssh-config (eg. with `vagrant ssh-config boxname >vagrant.ssh.config` ) settings will work after re-creating a box.

Also the edge gateway is untouched after a `vagrant destroy` + `vagrant up` step.

A sample output looks like this:

### vagrant up --provider=vcloud
Create a sample vApp with two boxes `tst` and `tst2`. The edge gateway is used in this sample.

```
Bringing machine 'tst' up with 'vcloud' provider...
Bringing machine 'tst2' up with 'vcloud' provider...
==> tst: Building vApp...
==> tst: vApp vcloud-ubuntu-vagrant-meanstack-ide-precise64-aeedf371 successfully created.
==> tst: Setting VM hardware...
==> tst: Powering on VM...
==> tst: Fixed port collision for 22 => 2222. Now on port 2206.
==> tst: Forwarding Ports: VM port 22 -> vShield Edge port 2206
==> tst: Creating NAT rules on [SS-EDGE] for IP [10.115.4.4] port 2206.
==> tst: Rsyncing folder: /home/vagrant/code/vcloud-ubuntu/ => /vagrant
==> tst: Running provisioner: shell...
tst: Running: /tmp/vagrant-shell20140528-2556-1pmtusy.sh
==> tst: stdin: is not a tty
==> tst: Provisioning host tst ...
==> tst2: Adding VM to existing vApp...
==> tst2: Setting VM hardware...
==> tst2: Powering on VM...
==> tst2: Fixed port collision for 22 => 2222. Now on port 2207.
==> tst2: Forwarding Ports: VM port 22 -> vShield Edge port 2207
==> tst2: Creating NAT rules on [SS-EDGE] for IP [10.115.4.4] port 2207.
==> tst2: Rsyncing folder: /home/vagrant/code/vcloud-ubuntu/ => /vagrant
==> tst2: Running provisioner: shell...
tst2: Running: /tmp/vagrant-shell20140528-2556-o0sfra.sh
==> tst2: stdin: is not a tty
==> tst2: Provisioning host tst2 ...
```

### vagrant pristine -f tst2
Now destroy and recreate tst2 box.
I use `vagrant pristine -f tst2` for that in a single command.

```
==> tst2: Powering off VM...
==> tst2: Destroying VM...
Bringing machine 'tst2' up with 'vcloud' provider...
==> tst2: Adding VM to existing vApp...
==> tst2: Setting VM hardware...
==> tst2: Powering on VM...
==> tst2: Fixed port collision for 22 => 2222. Now on port 2207.
==> tst2: Forwarding Ports: VM port 22 -> vShield Edge port 2207
==> tst2: Waiting for SSH Access on 10.100.50.4:2207 ...
==> tst2: Rsyncing folder: /home/vagrant/code/vcloud-ubuntu/ => /vagrant
==> tst2: Running provisioner: shell...
tst2: Running: /tmp/vagrant-shell20140528-4885-1e4qo4a.sh
==> tst2: stdin: is not a tty
==> tst2: Provisioning host tst2 ...
```

As you can see, the edge gateway keeps untouched for this. The port 2207 is reused for SSH for the box tst2. Only the vApp-Network NAT rule must be recreated, because this will be removed automatically by vCloud, as it seems.