vagrant 0.1.4 → 0.2.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/Gemfile +1 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/bin/vagrant-box +1 -2
  5. data/bin/vagrant-down +1 -2
  6. data/bin/vagrant-halt +1 -2
  7. data/bin/vagrant-init +1 -2
  8. data/bin/vagrant-package +1 -2
  9. data/bin/vagrant-reload +1 -2
  10. data/bin/vagrant-resume +1 -2
  11. data/bin/vagrant-ssh +1 -2
  12. data/bin/vagrant-status +29 -0
  13. data/bin/vagrant-suspend +1 -2
  14. data/bin/vagrant-up +1 -2
  15. data/config/default.rb +5 -9
  16. data/keys/README.md +10 -0
  17. data/keys/vagrant +27 -0
  18. data/keys/vagrant.pub +1 -0
  19. data/lib/vagrant/actions/base.rb +14 -0
  20. data/lib/vagrant/actions/collection.rb +36 -0
  21. data/lib/vagrant/actions/runner.rb +4 -10
  22. data/lib/vagrant/actions/vm/boot.rb +4 -5
  23. data/lib/vagrant/actions/vm/customize.rb +17 -0
  24. data/lib/vagrant/actions/vm/destroy.rb +11 -2
  25. data/lib/vagrant/actions/vm/forward_ports.rb +24 -0
  26. data/lib/vagrant/actions/vm/import.rb +1 -0
  27. data/lib/vagrant/actions/vm/provision.rb +30 -52
  28. data/lib/vagrant/actions/vm/reload.rb +2 -2
  29. data/lib/vagrant/actions/vm/shared_folders.rb +37 -25
  30. data/lib/vagrant/actions/vm/up.rb +8 -4
  31. data/lib/vagrant/active_list.rb +66 -0
  32. data/lib/vagrant/commands.rb +44 -0
  33. data/lib/vagrant/config.rb +64 -47
  34. data/lib/vagrant/downloaders/file.rb +2 -12
  35. data/lib/vagrant/env.rb +48 -12
  36. data/lib/vagrant/provisioners/base.rb +22 -0
  37. data/lib/vagrant/provisioners/chef.rb +102 -0
  38. data/lib/vagrant/provisioners/chef_server.rb +96 -0
  39. data/lib/vagrant/provisioners/chef_solo.rb +67 -0
  40. data/lib/vagrant/ssh.rb +25 -6
  41. data/lib/vagrant/stacked_proc_runner.rb +33 -0
  42. data/lib/vagrant/vm.rb +8 -0
  43. data/lib/vagrant.rb +10 -5
  44. data/test/test_helper.rb +22 -6
  45. data/test/vagrant/actions/collection_test.rb +110 -0
  46. data/test/vagrant/actions/runner_test.rb +11 -7
  47. data/test/vagrant/actions/vm/boot_test.rb +7 -7
  48. data/test/vagrant/actions/vm/customize_test.rb +16 -0
  49. data/test/vagrant/actions/vm/destroy_test.rb +19 -6
  50. data/test/vagrant/actions/vm/forward_ports_test.rb +52 -0
  51. data/test/vagrant/actions/vm/import_test.rb +10 -3
  52. data/test/vagrant/actions/vm/provision_test.rb +75 -70
  53. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  54. data/test/vagrant/actions/vm/shared_folders_test.rb +62 -9
  55. data/test/vagrant/actions/vm/up_test.rb +4 -4
  56. data/test/vagrant/active_list_test.rb +169 -0
  57. data/test/vagrant/config_test.rb +145 -29
  58. data/test/vagrant/downloaders/file_test.rb +4 -19
  59. data/test/vagrant/env_test.rb +96 -23
  60. data/test/vagrant/provisioners/base_test.rb +27 -0
  61. data/test/vagrant/provisioners/chef_server_test.rb +175 -0
  62. data/test/vagrant/provisioners/chef_solo_test.rb +142 -0
  63. data/test/vagrant/provisioners/chef_test.rb +116 -0
  64. data/test/vagrant/ssh_test.rb +29 -8
  65. data/test/vagrant/stacked_proc_runner_test.rb +43 -0
  66. data/test/vagrant/vm_test.rb +23 -0
  67. data/vagrant.gemspec +35 -8
  68. metadata +42 -11
  69. data/script/vagrant-ssh-expect.sh +0 -22
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source :gemcutter
2
2
 
3
3
  # Gems required for the lib to even run
4
- gem "virtualbox", ">= 0.5.0"
4
+ gem "virtualbox", ">= 0.5.2"
5
5
  gem "net-ssh", ">= 2.0.19"
6
6
  gem "net-scp", ">= 1.0.2"
7
7
  gem "git-style-binaries", ">= 0.1.10"
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gemspec.homepage = "http://github.com/mitchellh/vagrant"
11
11
  gemspec.authors = ["Mitchell Hashimoto", "John Bender"]
12
12
 
13
- gemspec.add_dependency('virtualbox', '>= 0.5.0')
13
+ gemspec.add_dependency('virtualbox', '>= 0.5.2')
14
14
  gemspec.add_dependency('net-ssh', '>= 2.0.19')
15
15
  gemspec.add_dependency('net-scp', '>= 1.0.2')
16
16
  gemspec.add_dependency('json', '>= 1.2.0')
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0.pre
data/bin/vagrant-box CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "manage boxes"
data/bin/vagrant-down CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "destroys the vagrant environment"
data/bin/vagrant-halt CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "forcibly halts the vagrant environment"
data/bin/vagrant-init CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "initializes directory for vagrant use"
data/bin/vagrant-package CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "package the current vagrant environment"
data/bin/vagrant-reload CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "reload the vagrant environment"
data/bin/vagrant-resume CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "resumes the vagrant environment"
data/bin/vagrant-ssh CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "opens an SSH connection into the VM"
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require File.expand_path('../../.bundle/environment', __FILE__)
4
+ rescue LoadError
5
+ # Fallback on rubygems
6
+ require "rubygems"
7
+ end
8
+
9
+ require 'git-style-binary/command'
10
+
11
+ # Get library
12
+ libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
+ require File.expand_path('vagrant', libdir)
14
+
15
+ GitStyleBinary.command do
16
+ short_desc "Outputs the status of the current environment"
17
+ banner <<-EOS
18
+ Usage: #{command.full_name} #{all_options_string}
19
+
20
+ This command outputs the status of the current environment. This command
21
+ tells you whether the environment is created, running, suspended,
22
+ etc.
23
+
24
+ EOS
25
+
26
+ run do |command|
27
+ Vagrant::Commands.status
28
+ end
29
+ end
data/bin/vagrant-suspend CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "suspends the vagrant environment"
data/bin/vagrant-up CHANGED
@@ -10,8 +10,7 @@ require 'git-style-binary/command'
10
10
 
11
11
  # Get library
12
12
  libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- $:.unshift(libdir) unless $:.include?(libdir)
14
- require 'vagrant'
13
+ require File.expand_path('vagrant', libdir)
15
14
 
16
15
  GitStyleBinary.command do
17
16
  short_desc "create the vagrant environment"
data/config/default.rb CHANGED
@@ -9,22 +9,18 @@ Vagrant::Config.run do |config|
9
9
  config.ssh.host = "localhost"
10
10
  config.ssh.forwarded_port_key = "ssh"
11
11
  config.ssh.max_tries = 10
12
- config.ssh.timeout = 10
12
+ config.ssh.timeout = 30
13
+ config.ssh.private_key_path = File.join(PROJECT_ROOT, 'keys', 'vagrant')
13
14
 
14
15
  config.vm.box_ovf = "box.ovf"
15
16
  config.vm.base_mac = "0800279C2E42"
16
17
  config.vm.project_directory = "/vagrant"
17
18
  config.vm.forward_port("ssh", 22, 2222)
18
19
  config.vm.disk_image_format = 'VMDK'
20
+ config.vm.provisioner = nil
21
+ config.vm.shared_folder_uid = nil
22
+ config.vm.shared_folder_gid = nil
19
23
 
20
24
  config.package.name = 'vagrant'
21
25
  config.package.extension = '.box'
22
-
23
- config.chef.enabled = false
24
- config.chef.cookbooks_path = "cookbooks"
25
- config.chef.provisioning_path = "/tmp/vagrant-chef"
26
- config.chef.json = {
27
- :instance_role => "vagrant",
28
- :recipes => ["vagrant_main"]
29
- }
30
26
  end
data/keys/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Insecure Keypair
2
+
3
+ These keys are the "insecure" public/private keypair we offer to
4
+ [base box creators](http://vagrantup.com/docs/base_boxes.html) for use in their base boxes so that
5
+ vagrant installations can automatically SSH into the boxes.
6
+
7
+ If you're working with a team or company or with a custom box and
8
+ you want more secure SSH, you should create your own keypair
9
+ and configure the private key in the Vagrantfile with
10
+ `config.ssh.private_key_path`
data/keys/vagrant ADDED
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
3
+ w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
4
+ kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
5
+ hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
6
+ Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
7
+ yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd
8
+ ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1
9
+ Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf
10
+ TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK
11
+ iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A
12
+ sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf
13
+ 4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP
14
+ cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk
15
+ EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN
16
+ CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX
17
+ 3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG
18
+ YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj
19
+ 3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+
20
+ dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz
21
+ 6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC
22
+ P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF
23
+ llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ
24
+ kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
25
+ +vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
26
+ NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
27
+ -----END RSA PRIVATE KEY-----
data/keys/vagrant.pub ADDED
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== johnbender@vagrant.local
@@ -82,6 +82,20 @@ module Vagrant
82
82
  # all your own exceptions, otherwise it'll mask the initially raised
83
83
  # exception.
84
84
  def rescue(exception); end
85
+
86
+ # The following two methods are used for declaring action dependencies.
87
+ # For example, you require that the reload action be in place before
88
+ # a your new FooAction you might do the following
89
+ #
90
+ # def follows; [Reload] end
91
+
92
+ # This method is called when the runner is determining the actions that
93
+ # must precede a given action. You would say "This action follows [Action1, Action2]"
94
+ def follows; [] end
95
+
96
+ # This method is called when the runner is determining the actions that
97
+ # must follow a given action. You would say "This action precedes [Action3, Action4]
98
+ def precedes; [] end
85
99
  end
86
100
 
87
101
  # An exception which occured within an action. This should be used instead of
@@ -0,0 +1,36 @@
1
+ module Vagrant
2
+ module Actions
3
+ class Collection < Array
4
+ def dependencies!
5
+ each_with_index do |action, i|
6
+ action.follows.each do |klass|
7
+ unless self[0..i].klasses.include?(klass)
8
+ raise DependencyNotSatisfiedException.new("#{action.class} action must follow #{klass}")
9
+ end
10
+ end
11
+
12
+ action.precedes.each do |klass|
13
+ unless self[i..length].klasses.include?(klass)
14
+ raise DependencyNotSatisfiedException.new("#{action.class} action must precede #{klass}")
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def duplicates?
21
+ klasses.uniq.size != size
22
+ end
23
+
24
+ def duplicates!
25
+ raise DuplicateActionException.new if duplicates?
26
+ end
27
+
28
+ def klasses
29
+ map { |o| o.class }
30
+ end
31
+ end
32
+
33
+ class DuplicateActionException < Exception; end
34
+ class DependencyNotSatisfiedException < Exception; end
35
+ end
36
+ end
@@ -47,7 +47,7 @@ module Vagrant
47
47
  #
48
48
  # @return [Array]
49
49
  def actions
50
- @actions ||= []
50
+ @actions ||= Actions::Collection.new
51
51
  end
52
52
 
53
53
  # Returns the first action instance which matches the given class.
@@ -75,9 +75,9 @@ module Vagrant
75
75
  add_action(single_action, *args)
76
76
  end
77
77
 
78
- # Raising it here might be too late and hard debug where the actions are comming from (meta actions)
79
- raise DuplicateActionException.new if action_klasses.uniq.size < action_klasses.size
80
-
78
+ actions.duplicates!
79
+ actions.dependencies!
80
+
81
81
  # Call the prepare method on each once its
82
82
  # initialized, then call the execute! method
83
83
  begin
@@ -127,12 +127,6 @@ module Vagrant
127
127
  end
128
128
  results
129
129
  end
130
-
131
- def action_klasses
132
- actions.map { |a| a.class }
133
- end
134
130
  end
135
-
136
- class DuplicateActionException < Exception; end
137
131
  end
138
132
  end
@@ -2,6 +2,10 @@ module Vagrant
2
2
  module Actions
3
3
  module VM
4
4
  class Boot < Base
5
+ def prepare
6
+ Vagrant.config.vm.share_folder("vagrant-root", Vagrant.config.vm.project_directory, Env.root_path)
7
+ end
8
+
5
9
  def execute!
6
10
  @runner.invoke_around_callback(:boot) do
7
11
  # Startup the VM
@@ -17,11 +21,6 @@ error
17
21
  end
18
22
  end
19
23
 
20
- def collect_shared_folders
21
- # The root shared folder for the project
22
- ["vagrant-root", Env.root_path, Vagrant.config.vm.project_directory]
23
- end
24
-
25
24
  def boot
26
25
  logger.info "Booting VM..."
27
26
  @runner.vm.start(:headless, true)
@@ -0,0 +1,17 @@
1
+ module Vagrant
2
+ module Actions
3
+ module VM
4
+ class Customize < Base
5
+ def execute!
6
+ logger.info "Running any VM customizations..."
7
+
8
+ # Run the customization procs over the VM
9
+ Vagrant.config.vm.run_procs!(@runner.vm)
10
+
11
+ # Save the vm
12
+ @runner.vm.save(true)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -4,10 +4,19 @@ module Vagrant
4
4
  class Destroy < Base
5
5
  def execute!
6
6
  @runner.invoke_around_callback(:destroy) do
7
- logger.info "Destroying VM and associated drives..."
8
- @runner.vm.destroy(:destroy_image => true)
7
+ destroy_vm
8
+ depersist
9
9
  end
10
10
  end
11
+
12
+ def destroy_vm
13
+ logger.info "Destroying VM and associated drives..."
14
+ @runner.vm.destroy(:destroy_image => true)
15
+ end
16
+
17
+ def depersist
18
+ Env.depersist_vm(@runner)
19
+ end
11
20
  end
12
21
  end
13
22
  end
@@ -2,6 +2,30 @@ module Vagrant
2
2
  module Actions
3
3
  module VM
4
4
  class ForwardPorts < Base
5
+ def prepare
6
+ VirtualBox::VM.all.each do |vm|
7
+ next if !vm.running? || vm.uuid == @runner.uuid
8
+
9
+ vm.forwarded_ports.each do |fp|
10
+ Vagrant.config.vm.forwarded_ports.each do |name, options|
11
+ if fp.hostport.to_s == options[:hostport].to_s
12
+ raise ActionException.new(<<-msg)
13
+ Vagrant cannot forward the specified ports on this VM, since they
14
+ would collide with another VirtualBox virtual machine's forwarded
15
+ ports! The "#{name}" forwarded port (#{fp.hostport}) is already in use on the host
16
+ machine.
17
+
18
+ To fix this, modify your current projects Vagrantfile to use another
19
+ port. Example, where '1234' would be replaced by a unique host port:
20
+
21
+ config.vm.forward_port("#{name}", #{options[:guestport]}, 1234)
22
+ msg
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
5
29
  def execute!
6
30
  clear
7
31
  forward_ports
@@ -8,6 +8,7 @@ module Vagrant
8
8
  logger.info "Importing base VM (#{Vagrant::Env.box.ovf_file})..."
9
9
  # Use the first argument passed to the action
10
10
  @runner.vm = VirtualBox::VM.import(Vagrant::Env.box.ovf_file)
11
+ raise ActionException.new("The VM import failed! Try running `VBoxManage import` on the box file manually for more verbose error output.") unless @runner.vm
11
12
  end
12
13
  end
13
14
  end
@@ -2,68 +2,46 @@ module Vagrant
2
2
  module Actions
3
3
  module VM
4
4
  class Provision < Base
5
- def execute!
6
- chown_provisioning_folder
7
- setup_json
8
- setup_solo_config
9
- run_chef_solo
10
- end
11
-
12
- def chown_provisioning_folder
13
- logger.info "Setting permissions on provisioning folder..."
14
- SSH.execute do |ssh|
15
- ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}")
16
- end
17
- end
18
-
19
- def setup_json
20
- logger.info "Generating JSON and uploading..."
21
-
22
- # Set up initial configuration
23
- data = {
24
- :config => Vagrant.config,
25
- :directory => Vagrant.config.vm.project_directory,
26
- }
5
+ attr_reader :provisioner
27
6
 
28
- # And wrap it under the "vagrant" namespace
29
- data = { :vagrant => data }
7
+ def intialize(*args)
8
+ super
30
9
 
31
- # Merge with the "extra data" which isn't put under the
32
- # vagrant namespace by default
33
- data.merge!(Vagrant.config.chef.json)
34
-
35
- json = data.to_json
36
-
37
- SSH.upload!(StringIO.new(json), File.join(Vagrant.config.chef.provisioning_path, "dna.json"))
10
+ @provisioner = nil
38
11
  end
39
12
 
40
- def setup_solo_config
41
- solo_file = <<-solo
42
- file_cache_path "#{Vagrant.config.chef.provisioning_path}"
43
- cookbook_path "#{cookbooks_path}"
44
- solo
13
+ def prepare
14
+ provisioner = Vagrant.config.vm.provisioner
45
15
 
46
- logger.info "Uploading chef-solo configuration script..."
47
- SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "solo.rb"))
48
- end
16
+ if provisioner.nil?
17
+ logger.info("Provisioning not enabled, ignoring this step")
18
+ return
19
+ end
49
20
 
50
- def run_chef_solo
51
- logger.info "Running chef recipes..."
52
- SSH.execute do |ssh|
53
- ssh.exec!("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
54
- # TODO: Very verbose. It would be easier to save the data and only show it during
55
- # an error, or when verbosity level is set high
56
- logger.info("#{stream}: #{data}")
57
- end
21
+ if provisioner.is_a?(Class)
22
+ @provisioner = provisioner.new
23
+ raise ActionException.new("Provisioners must be an instance of Vagrant::Provisioners::Base") unless @provisioner.is_a?(Provisioners::Base)
24
+ elsif provisioner.is_a?(Symbol)
25
+ # We have a few hard coded provisioners for built-ins
26
+ mapping = {
27
+ :chef_solo => Provisioners::ChefSolo,
28
+ :chef_server => Provisioners::ChefServer
29
+ }
30
+
31
+ provisioner_klass = mapping[provisioner]
32
+ raise ActionException.new("Unknown provisioner type: #{provisioner}") if provisioner_klass.nil?
33
+ @provisioner = provisioner_klass.new
58
34
  end
59
- end
60
35
 
61
- def cookbooks_path
62
- File.join(Vagrant.config.chef.provisioning_path, "cookbooks")
36
+ logger.info "Provisioning enabled with #{@provisioner.class}"
37
+ @provisioner.prepare
63
38
  end
64
39
 
65
- def collect_shared_folders
66
- ["vagrant-provisioning", File.expand_path(Vagrant.config.chef.cookbooks_path, Env.root_path), cookbooks_path]
40
+ def execute!
41
+ if provisioner
42
+ logger.info "Beginning provisioning process..."
43
+ provisioner.provision!
44
+ end
67
45
  end
68
46
  end
69
47
  end
@@ -3,9 +3,9 @@ module Vagrant
3
3
  module VM
4
4
  class Reload < Base
5
5
  def prepare
6
- steps = [ForwardPorts, SharedFolders, Boot]
6
+ steps = [Customize, ForwardPorts, SharedFolders, Boot]
7
7
  steps.unshift(Halt) if @runner.vm.running?
8
- steps << Provision if Vagrant.config.chef.enabled
8
+ steps << Provision if !Vagrant.config.vm.provisioner.nil?
9
9
 
10
10
  steps.each do |action_klass|
11
11
  @runner.add_action(action_klass)
@@ -3,32 +3,15 @@ module Vagrant
3
3
  module VM
4
4
  class SharedFolders < Base
5
5
  def shared_folders
6
- shared_folders = @runner.invoke_callback(:collect_shared_folders)
7
-
8
- # Basic filtering of shared folders. Basically only verifies that
9
- # the result is an array of 3 elements. In the future this should
10
- # also verify that the host path exists, the name is valid,
11
- # and that the guest path is valid.
12
- shared_folders.collect do |folder|
13
- if folder.is_a?(Array) && folder.length == 3
14
- folder
15
- else
16
- nil
17
- end
18
- end.compact
6
+ Vagrant.config.vm.shared_folders.inject([]) do |acc, data|
7
+ name, value = data
8
+ acc << [name, File.expand_path(value[:hostpath]), value[:guestpath]]
9
+ end
19
10
  end
20
11
 
21
12
  def before_boot
22
- logger.info "Creating shared folders metadata..."
23
-
24
- shared_folders.each do |name, hostpath, guestpath|
25
- folder = VirtualBox::SharedFolder.new
26
- folder.name = name
27
- folder.hostpath = hostpath
28
- @runner.vm.shared_folders << folder
29
- end
30
-
31
- @runner.vm.save(true)
13
+ clear_shared_folders
14
+ create_metadata
32
15
  end
33
16
 
34
17
  def after_boot
@@ -44,14 +27,43 @@ module Vagrant
44
27
  end
45
28
  end
46
29
 
30
+ def clear_shared_folders
31
+ logger.info "Clearing previously set shared folders..."
32
+
33
+ @runner.vm.shared_folders.each do |shared_folder|
34
+ shared_folder.destroy
35
+ end
36
+
37
+ @runner.reload!
38
+ end
39
+
40
+ def create_metadata
41
+ logger.info "Creating shared folders metadata..."
42
+
43
+ shared_folders.each do |name, hostpath, guestpath|
44
+ folder = VirtualBox::SharedFolder.new
45
+ folder.name = name
46
+ folder.hostpath = hostpath
47
+ @runner.vm.shared_folders << folder
48
+ end
49
+
50
+ @runner.vm.save(true)
51
+ end
52
+
47
53
  def mount_folder(ssh, name, guestpath, sleeptime=5)
48
54
  # Note: This method seems pretty OS-specific and could also use
49
55
  # some configuration options. For now its duct tape and "works"
50
56
  # but should be looked at in the future.
51
- attempts = 0
52
57
 
58
+ # Determine the permission string to attach to the mount command
59
+ perms = []
60
+ perms << "uid=#{Vagrant.config.vm.shared_folder_uid}"
61
+ perms << "gid=#{Vagrant.config.vm.shared_folder_gid}"
62
+ perms = " -o #{perms.join(",")}" if !perms.empty?
63
+
64
+ attempts = 0
53
65
  while true
54
- result = ssh.exec!("sudo mount -t vboxsf #{name} #{guestpath}") do |ch, type, data|
66
+ result = ssh.exec!("sudo mount -t vboxsf#{perms} #{name} #{guestpath}") do |ch, type, data|
55
67
  # net/ssh returns the value in ch[:result] (based on looking at source)
56
68
  ch[:result] = !!(type == :stderr && data =~ /No such device/i)
57
69
  end