-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only set custom
:box
& :box_url
values for known Bento boxes.
The default values for the `:box` and `:box_url` attributes were always implicitly based on the Bento project's base boxes (https://github.com/chef/bento). This meant that for a small number of common/known platforms, the box name and URLs could be pre-calculated to help with initial out-of-the-box experience. For example, given a platform name of `"ubuntu-14.04"`, a default box name of `"opscode-ubuntu-14.04"` and box URL could be computed (but only for VirtualBox or VMware-based providers). Any custom platform name would have to explicitly override the default value for at least `:box` if not also for `:box_url`. This commit makes the implicit default code for Bento boxes explicit. In other words, if your platform name does not match the pre-defined Bento box platforms, the default of `:box` will be the platform name and the `:box_url` will be `nil`. Similarly, if you use a provider other than VirtualBox or VMware-*, the default of `:box` will be the platform name and the `:box_url` will be `nil`. This update allows for less boilerplate configuration, for example: --- driver: name: vagrant provisioner: name: chef_zero platforms: - name: ubuntu-14.04 # a Bento box, config as before - name: ubuntu/trusty64 # defaults to the same name for :box - name: windows-8.1 # defaults to the sane name for :box # and a box_url of nil as there is no # sharable windows base box At a time in the near future, the S3 URLs for Bento boxes could move to Atlas (formerly Vagrant Cloud) box names, but the same defaulting logic can apply.
- Loading branch information
Showing
2 changed files
with
84 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,7 @@ module Driver | |
# @author Fletcher Nichol <[email protected]> | ||
class Vagrant < Kitchen::Driver::SSHBase | ||
|
||
default_config :box do |driver| | ||
"opscode-#{driver.instance.platform.name}" | ||
end | ||
default_config(:box) { |driver| driver.default_box } | ||
required_config :box | ||
|
||
default_config :box_check_update, nil | ||
|
@@ -82,16 +80,26 @@ def create(state) | |
info("Vagrant instance #{instance.to_str} created.") | ||
end | ||
|
||
# @return [String,nil] the Vagrant box for this Instance | ||
def default_box | ||
if bento_boxes.include?(instance.platform.name) | ||
"opscode-#{instance.platform.name}" | ||
else | ||
instance.platform.name | ||
end | ||
end | ||
|
||
# @return [String,nil] the Vagrant box URL for this Instance | ||
def default_box_url | ||
# No default neede for 1.5 onwards - Vagrant Cloud only needs a box name | ||
return if Gem::Version.new(vagrant_version) >= Gem::Version.new(1.5) | ||
return unless bento_boxes.include?(instance.platform.name) | ||
|
||
bucket = config[:provider] | ||
bucket = "vmware" if config[:provider] =~ /^vmware_(.+)$/ | ||
provider = config[:provider] | ||
provider = "vmware" if config[:provider] =~ /^vmware_(.+)$/ | ||
|
||
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{bucket}/" \ | ||
"opscode_#{instance.platform.name}_chef-provisionerless.box" | ||
if %w[virtualbox vmware].include?(provider) | ||
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{provider}/" \ | ||
"opscode_#{instance.platform.name}_chef-provisionerless.box" | ||
end | ||
end | ||
|
||
# Destroys an instance. | ||
|
@@ -149,6 +157,19 @@ def verify_dependencies | |
WEBSITE = "http://www.vagrantup.com/downloads.html".freeze | ||
MIN_VER = "1.1.0".freeze | ||
|
||
# Retuns a list of Vagrant base boxes produced by the Bento project | ||
# (https://github.com/chef/bento). | ||
# | ||
# @return [Arrau<String>] list of Bento box names | ||
# @api private | ||
def bento_boxes | ||
%W[ | ||
centos-5.11 centos-6.6 centos-7.0 debian-6.0.10 debian-7.8 fedora-20 | ||
fedora-21 freebsd-9.3 freebsd-10.1 opensuse-13.1 ubuntu-10.04 | ||
ubuntu-12.04 ubuntu-14.04 ubuntu-14.10 | ||
].map { |name| [name, "#{name}-i386"] }.flatten | ||
end | ||
|
||
# Renders and writes out a Vagrantfile dedicated to this instance. | ||
# | ||
# @api private | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters