Skip to content

Commit

Permalink
Merge pull request #30 from opscode/compupted-defaults
Browse files Browse the repository at this point in the history
Computed defaults
  • Loading branch information
fnichol committed Jul 23, 2013
2 parents becb652 + c6e9c9e commit b914e7e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,43 @@ berkshelf-vagrant, so upgrading this Vagrant plugin is recommended.

Please read the [Driver usage][driver_usage] page for more details.

## <a name="default-config"></a> Default Configuration

This driver can determine the Vagrant box name and download URL for a select
number of platforms. Currently, the following platform names are supported:

```ruby
---
platforms:
- name: ubuntu-10.04
- name: ubuntu-12.04
- name: ubuntu-12.10
- name: ubuntu-13.04
- name: centos-5.9
- name: centos-6.4
- name: debian-7.1.0
```

This will effectively generate a configuration similar to:

```ruby
---
platforms:
- name: ubuntu-10.04
driver_config:
box: opscode-ubuntu-10.04
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box
- name: ubuntu-12.04
driver_config:
box: opscode-ubuntu-12.04
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
- name: ubuntu-12.10
driver_config:
box: opscode-ubuntu-12.10
box_url: ...
# ...
```

## <a name="config"></a> Configuration

### <a name="config-box"></a> box
Expand Down
28 changes: 28 additions & 0 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class Vagrant < Kitchen::Driver::SSHBase

default_config :customize, { :memory => '256' }
default_config :synced_folders, {}
default_config :box do |driver|
driver.default_values("box")
end
default_config :box_url do |driver|
driver.default_values("box_url")
end

required_config :box

Expand Down Expand Up @@ -85,10 +91,32 @@ def verify_dependencies
check_berkshelf_plugin if config[:use_vagrant_berkshelf_plugin]
end

def default_values(value)
(default_boxes[instance.platform.name] || Hash.new)[value]
end

protected

WEBSITE = "http://downloads.vagrantup.com/"
MIN_VER = "1.1.0"
OMNITRUCK_PREFIX = "https://opscode-vm-bento.s3.amazonaws.com/vagrant"
PLATFORMS = %w{
ubuntu-10.04 ubuntu-12.04 ubuntu-12.10 ubuntu-13.04
centos-6.4 centos-5.9 debian-7.1.0
}

def default_boxes
@default_boxes ||= begin
hash = Hash.new
PLATFORMS.each do |platform|
hash[platform] = Hash.new
hash[platform]["box"] = "opscode-#{platform}"
hash[platform]["box_url"] =
"#{OMNITRUCK_PREFIX}/opscode_#{platform}_provisionerless.box"
end
hash
end
end

def run(cmd, options = {})
cmd = "echo #{cmd}" if config[:dry_run]
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/vagrant/vagrantfile_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def guest_block(arr)
arr << %{ c.vm.guest = #{config[:guest]}}
end
end

def network_block(arr)
Array(config[:network]).each do |network_options|
options = Array(network_options.dup)
Expand Down

0 comments on commit b914e7e

Please sign in to comment.