Defining machine names using VirtualBox

394 views
Skip to first unread message

POFlynn

unread,
Jul 28, 2014, 12:55:09 PM7/28/14
to vagra...@googlegroups.com
Got my Vagrant freak on and I'm loving it but now I want more.... So the team is building boxes locally using VirtualBox as a provider using chef/vagrant source from a Git repo, yaay. But they want to be able to build multiple boxes on their laptops. I initially told them to simply re-clone the repo into a different directory and vagrant up from there and that worked as the VB provider will put a timestamp in the machine name and thus each machine from each directory will have a unique name in VirtualBox. But then the team wanted the version of our s/w in the name (as they build machines from many sources and wanted to know which was which in the VirtualBox GUI) so I added a "vb.name = $version" type entry which gives a nice name with a version number but also drops the timestamp and thus prevents them from building the same versioned machine in another directory as that machine will have the same name. So I added a nicety but broke what is to them, a feature. 

So I guess really I'd like to be able to specify a machine name using the version of our s/w but the remainder of the machine name is random in some fashion (and persists across reboots). Am I asking too much?

Thanks.

Alvaro Miranda Aguilera

unread,
Jul 28, 2014, 6:53:14 PM7/28/14
to vagra...@googlegroups.com
ok, 3 replies for you:

The one I would do:

create a group.

inside the virtualbox block, add this:

vm_name = $version
memory = 2048
core = 2
group = "unique_name"

  config.vm.provider :virtualbox do |vb|
        vb.name = vm_name + "." + Time.now.strftime("%y%m%d%H%M")
        vb.customize ["modifyvm", :id, "--memory", memory]
        vb.customize ["modifyvm", :id, "--cpus", core]
        vb.customize ["modifyvm", :id, "--groups", group]
      end

This will create a group inside the virtualbox gui, and you will be able to identity the VM.



The one you did ask:
Vagrantfile is in ruby, plus you can read and write to the OS so you can potentially do something like this

create a file, put inside the timestamp

then you can read that file and reuse the timestamp and add the version you want

that is IF you want to the same exact name to persist accross reboots.

The one i will suggest related to what you ask:
if you don't need the same to persist across reboots (the same random part) and can change, then you can go for something more simple, like:

vm_name = $version
vb.name = vm_name + "." + Time.now.strftime("%y%m%d%H%M")





Alvaro.






--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul O'Flynn

unread,
Jul 29, 2014, 12:25:32 AM7/29/14
to vagra...@googlegroups.com

Great information Alvaro! Thanks a lot. I assumed I couldn't use the time function in the machine name as it would mean it would have a different name when I next tried to do a vagrant halt but indeed your suggestion works perfectly and certainly meets my needs.  Minor update for anyone else reading this; when specifying a group name it seemed to me that I needed to precede the group name with a '/', ie

vb.customize ["modifyvm", :id, "--groups", "/vagrant"]

Thanks a bundle!

You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/Dgq8xLS1DXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages