It was evening, there was a lot to do. And almost everything is in VirtualBox. Using headless virtuals.
I have long appreciated the advantages of virtual machines for development, and I use them everywhere. As a result, I have a fleet of 5-10 virtual machines with different branches and projects. A few of which are constantly running.
90% of them run in headless mode. And take the IP dynamically. Since static control is constantly impossible, and it has other limitations. From here result - authentically it is not known with what address the virtualka will be started.
')
In this case, I have this order of launching a virtual machine:
1. start in normal mode
2. look inside ifconfig / ipconfig for address
3. extinguish it
4. we start in headless and we hope that the address will be the same
I think you are faced with this. If not, you can go to the next post. Under the cut there is no magic theory or special code. Under the cut - a simple and ready-made solution. For those to whom this small daily task is familiar.
On the VB tracker there is a corresponding
feature request . But it is closed as “works for me”. Here is the code for this solution:
VBoxManage guestproperty enumerate {`VBoxManage list runningvms | awk -F"{" '{print $2}'` | grep \ IP | awk -F"," '{print $2}' | awk '{print $2}'
The solution is “Linux only”, which does not suit me. There were no other solutions, especially more beautiful ones, and it was decided to write my own.
A small
script for node.js , which lists all running virtual machines and all their network addresses. First, he gets a list of running machines, after which he receives each of them:
Partial listing
exec("vboxmanage list runningvms", function (err, stdout, stderr) { if (stdout) { var vmNames = stdout.match(/"([^"]*)"/g); if (vmNames) { for (var x = 0; x < vmNames.length; x++) { var vmName = vmNames[x]; (function (vmName) { exec("VBoxManage guestproperty enumerate " + vmName, function (err, stdout, stderr) { getVmIps(err, stdout, stderr, vmName) }); })(vmName); } } else { console.log("No running VMs"); } } else { console.log(stderr); } });
Runs with the help of “node vmip” and shows something like:
Somemachine
192.168.13.188
U3
10.0.2.15
192.168.13.29
192.168.56.101
Xp
192.168.56.102
10.0.2.15
The script is tested on the used Windows / OS X. Completely devoid of beauty and filled with harsh practicality. If there is a demand, it will be supplemented.