From aa556b8a563413d7530c6f92ba79b0aa3c216010 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Thu, 29 May 2014 10:14:04 +0100 Subject: [PATCH] Allow use of local box for base box. config.vm.box refers to the box that is used as the starting point for the box being brought up. That later box gets its own name and can be packaged. By getting rid of the vm.box assignment it becomes possible to use a box that has been added to the local vagrant set up as the base. The Vagrantfile has been adjusted so that if conf['box_name'] is set it wins over conf['box_url'] with a fallback to box_url and then a fallback to the internally defined precise box. config.yaml.sample comments updated accordingly. Also took advantage of this moment to moan about Vagrant's handling of network interface identifiers (in the config sample). --- Vagrantfile | 22 +++++++++++++--------- config.yaml.sample | 9 ++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 6fe482d..0f20e19 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,7 +10,6 @@ require 'yaml' conf = YAML.load(File.open('config.yaml')) def configure_vm(name, vm, conf) - vm.box = name vm.hostname = conf["#{name}_hostname"] or name # we do an L2 bridge directly onto the physical network, which means @@ -66,18 +65,23 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| configure_vm("compute1", compute1.vm, conf) end end - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. + + # You can either name a Vagrant box you have locally added and use + # that as a starting point, or give a url from where the 'config.vm.box' + # box will be fetched. # # We start with the Ubuntu 12.04 upstream image, which will work. However - # building from this ever time is slow. So the recommended model is build + # building from this every time is slow. So the recommended model is build # the manager once, and recapture that. You do have to nuke a bunch of # network config information to make that capture work (documentation TBD). - - config.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box' - # this lets you use a locally accessible version faster - if conf['box_url'] - config.vm.box_url = conf['box_url'] + if conf['box_name'] + config.vm.box = conf['box_name'] + else + config.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box' + # this lets you use a locally accessible version faster + if conf['box_url'] + config.vm.box_url = conf['box_url'] + end end # Create a forwarded port mapping which allows access to a specific port diff --git a/config.yaml.sample b/config.yaml.sample index a1309be..5a8a5e9 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -8,8 +8,15 @@ stack_sshkey: > setup_mode: devstack # what interface on the host should be used for a bridge # will often be eth0, but vagrant needs to know for sure +# This needs to be the full string descriptor of the interface. +# On some systems this can be something annoying like +# 'en1: Wi-Fi (Airport)'. Vagrant will not use this setting +# unless you get it exactly right. bridge_int: eth1 -# A non upstream url for the base box, used to speed things up +# A non upstream for the base box, used to speed things up. +# Choose one of box_name (for a locally added box) or box_url +# for the url of a nearby box. +#box_name: 'my.favorite' #box_url: http://gallifrey/vagrant/devstack-2014-02-19.box # Local devstack options