The HDP 2.5 Sandbox VM for VirtualBox comes without the preconfigured port forwardings that allow you to map all the important Web UIs to ports on the host machine. Instead of going through the motions of entering all the port forwardings manually, I decided to copy them from the earlier Tech-Preview release using the VBoxManage CLI. The process has three steps:
Obtain the new VM's SSID, which is a unique identifier that VirtualBox uses to address a VM.
Read out the forwarding rules from the "old" (tech preview) VM
For each rule, configure a matching rule in the "new" VM
Here is the code:
VMID=$(VBoxManage list vms | perl -ne '/Docker.*{(.*)}/ && print $1')
This bit gets the new VM's list entry (it is called "Hortonworks Docker Sandbox"), and parses the SSID, which is the bit that is enclosed by curly brackets. We need the SSID in the next step:
VBoxManage showvminfo "Hortonworks Sandbox with HDP 2.5 Technical Preview" | perl -ne '/NIC.*?Rule.*name = (.*?),.*protocol = (.*?),.*host ip = (.*?),.*host port = (.*?),.*guest ip = (.*?),.*guest port = (.*?)$/ && print "'"VBoxManage modifyvm $VMID --natpf1 "'$1,$2,$3,$4,$5,$6\n"' | bash
The vminfo command lists all kinds of data about the "old" VM, including the port forwarding rules. These are parsed with a Perl regular expression. The output of the Perl one-liner is a list of VBoxManage commands that create one rule each in the new VM's settings. The output is fed into bash via a pipe, and voilà! After running
VBoxManage startvm "Hortonworks Docker Sandbox"
the new Sandbox VM is available with All WebUIs in the familiar way!