vagrantup 0.4.3.dev → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/config/default.rb +6 -6
  4. data/lib/vagrant.rb +6 -3
  5. data/lib/vagrant/action.rb +77 -0
  6. data/lib/vagrant/action/action_exception.rb +16 -0
  7. data/lib/vagrant/action/box/destroy.rb +19 -0
  8. data/lib/vagrant/action/box/download.rb +78 -0
  9. data/lib/vagrant/action/box/unpackage.rb +58 -0
  10. data/lib/vagrant/action/box/verify.rb +23 -0
  11. data/lib/vagrant/action/builder.rb +151 -0
  12. data/lib/vagrant/action/builtin.rb +114 -0
  13. data/lib/vagrant/action/env/error_halt.rb +16 -0
  14. data/lib/vagrant/action/env/set.rb +18 -0
  15. data/lib/vagrant/action/environment.rb +98 -0
  16. data/lib/vagrant/action/exception_catcher.rb +14 -0
  17. data/lib/vagrant/action/vm/boot.rb +54 -0
  18. data/lib/vagrant/action/vm/check_box.rb +27 -0
  19. data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
  20. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  21. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  22. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  23. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  24. data/lib/vagrant/action/vm/customize.rb +21 -0
  25. data/lib/vagrant/action/vm/destroy.rb +20 -0
  26. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
  27. data/lib/vagrant/action/vm/disable_networks.rb +26 -0
  28. data/lib/vagrant/action/vm/export.rb +53 -0
  29. data/lib/vagrant/action/vm/forward_ports.rb +121 -0
  30. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  31. data/lib/vagrant/action/vm/halt.rb +34 -0
  32. data/lib/vagrant/action/vm/import.rb +33 -0
  33. data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
  34. data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
  35. data/lib/vagrant/action/vm/nfs.rb +161 -0
  36. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  37. data/lib/vagrant/action/vm/package.rb +99 -0
  38. data/lib/vagrant/action/vm/persist.rb +22 -0
  39. data/lib/vagrant/action/vm/provision.rb +50 -0
  40. data/lib/vagrant/action/vm/resume.rb +20 -0
  41. data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
  42. data/lib/vagrant/action/vm/suspend.rb +20 -0
  43. data/lib/vagrant/box.rb +3 -7
  44. data/lib/vagrant/commands/base.rb +1 -3
  45. data/lib/vagrant/commands/package.rb +4 -9
  46. data/lib/vagrant/commands/up.rb +0 -2
  47. data/lib/vagrant/config.rb +15 -1
  48. data/lib/vagrant/downloaders/file.rb +1 -1
  49. data/lib/vagrant/downloaders/http.rb +2 -1
  50. data/lib/vagrant/environment.rb +18 -14
  51. data/lib/vagrant/hosts/base.rb +77 -0
  52. data/lib/vagrant/hosts/bsd.rb +53 -0
  53. data/lib/vagrant/hosts/linux.rb +52 -0
  54. data/lib/vagrant/provisioners/base.rb +17 -9
  55. data/lib/vagrant/provisioners/chef.rb +1 -1
  56. data/lib/vagrant/provisioners/chef_server.rb +4 -8
  57. data/lib/vagrant/provisioners/chef_solo.rb +1 -2
  58. data/lib/vagrant/ssh.rb +12 -4
  59. data/lib/vagrant/systems/base.rb +4 -0
  60. data/lib/vagrant/systems/linux.rb +12 -1
  61. data/lib/vagrant/util.rb +16 -0
  62. data/lib/vagrant/util/busy.rb +59 -0
  63. data/lib/vagrant/util/plain_logger.rb +11 -0
  64. data/lib/vagrant/util/platform.rb +18 -0
  65. data/lib/vagrant/util/resource_logger.rb +128 -0
  66. data/lib/vagrant/version.rb +6 -0
  67. data/lib/vagrant/vm.rb +10 -12
  68. data/templates/chef_solo_solo.erb +2 -1
  69. data/templates/nfs/exports.erb +3 -0
  70. data/templates/nfs/exports_linux.erb +3 -0
  71. data/templates/strings.yml +23 -3
  72. metadata +121 -196
  73. data/.gitignore +0 -11
  74. data/Gemfile +0 -18
  75. data/Rakefile +0 -41
  76. data/VERSION +0 -1
  77. data/bin/.gitignore +0 -0
  78. data/lib/vagrant/actions/base.rb +0 -130
  79. data/lib/vagrant/actions/box/add.rb +0 -23
  80. data/lib/vagrant/actions/box/destroy.rb +0 -14
  81. data/lib/vagrant/actions/box/download.rb +0 -67
  82. data/lib/vagrant/actions/box/unpackage.rb +0 -42
  83. data/lib/vagrant/actions/box/verify.rb +0 -32
  84. data/lib/vagrant/actions/collection.rb +0 -36
  85. data/lib/vagrant/actions/runner.rb +0 -131
  86. data/lib/vagrant/actions/vm/boot.rb +0 -43
  87. data/lib/vagrant/actions/vm/customize.rb +0 -19
  88. data/lib/vagrant/actions/vm/destroy.rb +0 -24
  89. data/lib/vagrant/actions/vm/down.rb +0 -22
  90. data/lib/vagrant/actions/vm/export.rb +0 -45
  91. data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
  92. data/lib/vagrant/actions/vm/halt.rb +0 -24
  93. data/lib/vagrant/actions/vm/import.rb +0 -23
  94. data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
  95. data/lib/vagrant/actions/vm/package.rb +0 -94
  96. data/lib/vagrant/actions/vm/provision.rb +0 -49
  97. data/lib/vagrant/actions/vm/reload.rb +0 -17
  98. data/lib/vagrant/actions/vm/resume.rb +0 -16
  99. data/lib/vagrant/actions/vm/start.rb +0 -26
  100. data/lib/vagrant/actions/vm/suspend.rb +0 -16
  101. data/lib/vagrant/actions/vm/up.rb +0 -53
  102. data/lib/vagrant/busy.rb +0 -79
  103. data/lib/vagrant/resource_logger.rb +0 -126
  104. data/lib/vagrant/util/error_helper.rb +0 -13
  105. data/lib/vagrant/util/output_helper.rb +0 -9
  106. data/test/test_helper.rb +0 -149
  107. data/test/vagrant/actions/base_test.rb +0 -32
  108. data/test/vagrant/actions/box/add_test.rb +0 -36
  109. data/test/vagrant/actions/box/destroy_test.rb +0 -17
  110. data/test/vagrant/actions/box/download_test.rb +0 -137
  111. data/test/vagrant/actions/box/unpackage_test.rb +0 -99
  112. data/test/vagrant/actions/box/verify_test.rb +0 -44
  113. data/test/vagrant/actions/collection_test.rb +0 -113
  114. data/test/vagrant/actions/runner_test.rb +0 -268
  115. data/test/vagrant/actions/vm/boot_test.rb +0 -49
  116. data/test/vagrant/actions/vm/customize_test.rb +0 -21
  117. data/test/vagrant/actions/vm/destroy_test.rb +0 -37
  118. data/test/vagrant/actions/vm/down_test.rb +0 -39
  119. data/test/vagrant/actions/vm/export_test.rb +0 -88
  120. data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
  121. data/test/vagrant/actions/vm/halt_test.rb +0 -65
  122. data/test/vagrant/actions/vm/import_test.rb +0 -45
  123. data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
  124. data/test/vagrant/actions/vm/network_test.rb +0 -291
  125. data/test/vagrant/actions/vm/package_test.rb +0 -254
  126. data/test/vagrant/actions/vm/provision_test.rb +0 -99
  127. data/test/vagrant/actions/vm/reload_test.rb +0 -46
  128. data/test/vagrant/actions/vm/resume_test.rb +0 -26
  129. data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
  130. data/test/vagrant/actions/vm/start_test.rb +0 -73
  131. data/test/vagrant/actions/vm/suspend_test.rb +0 -26
  132. data/test/vagrant/actions/vm/up_test.rb +0 -96
  133. data/test/vagrant/active_list_test.rb +0 -173
  134. data/test/vagrant/box_test.rb +0 -154
  135. data/test/vagrant/busy_test.rb +0 -78
  136. data/test/vagrant/command_test.rb +0 -53
  137. data/test/vagrant/commands/base_test.rb +0 -139
  138. data/test/vagrant/commands/box/add_test.rb +0 -34
  139. data/test/vagrant/commands/box/list_test.rb +0 -32
  140. data/test/vagrant/commands/box/remove_test.rb +0 -41
  141. data/test/vagrant/commands/destroy_test.rb +0 -44
  142. data/test/vagrant/commands/halt_test.rb +0 -50
  143. data/test/vagrant/commands/init_test.rb +0 -55
  144. data/test/vagrant/commands/package_test.rb +0 -104
  145. data/test/vagrant/commands/provision_test.rb +0 -60
  146. data/test/vagrant/commands/reload_test.rb +0 -44
  147. data/test/vagrant/commands/resume_test.rb +0 -44
  148. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  149. data/test/vagrant/commands/ssh_test.rb +0 -129
  150. data/test/vagrant/commands/status_test.rb +0 -40
  151. data/test/vagrant/commands/suspend_test.rb +0 -44
  152. data/test/vagrant/commands/up_test.rb +0 -47
  153. data/test/vagrant/config_test.rb +0 -287
  154. data/test/vagrant/downloaders/base_test.rb +0 -28
  155. data/test/vagrant/downloaders/file_test.rb +0 -33
  156. data/test/vagrant/downloaders/http_test.rb +0 -62
  157. data/test/vagrant/environment_test.rb +0 -770
  158. data/test/vagrant/provisioners/base_test.rb +0 -33
  159. data/test/vagrant/provisioners/chef_server_test.rb +0 -176
  160. data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
  161. data/test/vagrant/provisioners/chef_test.rb +0 -175
  162. data/test/vagrant/resource_logger_test.rb +0 -145
  163. data/test/vagrant/ssh_session_test.rb +0 -46
  164. data/test/vagrant/ssh_test.rb +0 -296
  165. data/test/vagrant/systems/linux_test.rb +0 -179
  166. data/test/vagrant/util/error_helper_test.rb +0 -5
  167. data/test/vagrant/util/output_helper_test.rb +0 -5
  168. data/test/vagrant/util/plain_logger_test.rb +0 -17
  169. data/test/vagrant/util/platform_test.rb +0 -18
  170. data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
  171. data/test/vagrant/util/template_renderer_test.rb +0 -144
  172. data/test/vagrant/util/translator_test.rb +0 -61
  173. data/test/vagrant/util_test.rb +0 -27
  174. data/test/vagrant/vm_test.rb +0 -235
  175. data/vagrant.gemspec +0 -291
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- pkg/*
2
- Vagrantfile
3
- .vagrant
4
- .bundle
5
- *.lock
6
- cookbooks/*
7
- _site/*
8
- !templates/*
9
- *.org
10
- .yardoc/
11
- doc/
data/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Gems required for the lib to even run
4
- gem "virtualbox", :git => "git://github.com/mitchellh/virtualbox.git"
5
- gem "net-ssh", ">= 2.0.19"
6
- gem "net-scp", ">= 1.0.2"
7
- gem "json", ">= 1.2.4"
8
- gem "archive-tar-minitar", "= 0.5.2"
9
- gem "mario", "~> 0.0.6"
10
-
11
- # Gems required for testing only. To install run
12
- # gem bundle test
13
- group :test do
14
- gem "contest", ">= 0.1.2"
15
- gem "mocha"
16
- gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9'
17
- gem "jeweler", "~> 1.4.0"
18
- end
data/Rakefile DELETED
@@ -1,41 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- begin
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gemspec|
6
- gemspec.name = "vagrant"
7
- gemspec.summary = "Vagrant is a tool for building and distributing virtualized development environments."
8
- gemspec.description = "Vagrant is a tool for building and distributing virtualized development environments."
9
- gemspec.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
10
- gemspec.homepage = "http://github.com/mitchellh/vagrant"
11
- gemspec.authors = ["Mitchell Hashimoto", "John Bender"]
12
-
13
- gemspec.add_dependency('virtualbox', '~> 0.7.3')
14
- gemspec.add_dependency('net-ssh', '>= 2.0.19')
15
- gemspec.add_dependency('net-scp', '>= 1.0.2')
16
- gemspec.add_dependency('json', '>= 1.2.0')
17
- gemspec.add_dependency('archive-tar-minitar', '= 0.5.2')
18
- gemspec.add_dependency('mario', '~> 0.0.6')
19
- end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler not available. Install it with: gem install jeweler"
23
- end
24
-
25
- task :default => :test
26
-
27
- Rake::TestTask.new do |t|
28
- t.libs << "test"
29
- t.pattern = 'test/**/*_test.rb'
30
- end
31
-
32
- begin
33
- require 'yard'
34
- YARD::Rake::YardocTask.new do |t|
35
- t.options = ['--main', 'README.md', '--markup', 'markdown']
36
- t.options += ['--title', 'Vagrant Developer Documentation']
37
- end
38
- rescue LoadError
39
- puts "Yard not available. Install it with: gem install yard"
40
- puts "if you wish to be able to generate developer documentation."
41
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.3.dev
File without changes
@@ -1,130 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- # Base class for any command actions.
4
- #
5
- # Actions are the smallest unit of functionality found within
6
- # Vagrant. Vagrant composes many actions together to execute
7
- # its complex tasks while keeping the individual pieces of a
8
- # task as discrete reusable actions. Actions are ran exclusively
9
- # by an {Runner action runner} which is simply a subclass of {Runner}.
10
- #
11
- # Actions work by implementing any or all of the following methods
12
- # which a {Runner} executes:
13
- #
14
- # * `prepare` - Called once for each action before any action has `execute!`
15
- # called. This is meant for basic setup.
16
- # * `execute!` - This is where the meat of the action typically goes;
17
- # the main code which executes the action.
18
- # * `cleanup` - This is called exactly once for each action after every
19
- # other action is completed. It is meant for cleaning up any resources.
20
- # * `rescue` - This is called if an exception occurs in _any action_. This
21
- # gives every other action a chance to clean itself up.
22
- #
23
- # For details of each step of an action, read the specific function call
24
- # documentation below.
25
- class Base
26
- # The {Runner runner} which is executing the action
27
- attr_reader :runner
28
-
29
- # Any options which are passed into the initializer as a hash.
30
- attr_reader :options
31
-
32
- # Included so subclasses don't need to include it themselves.
33
- include Vagrant::Util
34
-
35
- # A helper method for logging which simply gets the logger from
36
- # the runner. Since actions tend to log quite a bit, this
37
- # removes the need to prefix `logger` with `@runner` over and
38
- # over.
39
- def logger
40
- runner.env.logger
41
- end
42
-
43
- # Initialization of the action, passing any arguments which may have
44
- # been given to the {Runner runner}. This method can be used by subclasses
45
- # to save any of the configuration options which are passed in.
46
- def initialize(runner, options=nil)
47
- @runner = runner
48
- @options = options || {}
49
- end
50
-
51
- # This method is called once per action, allowing the action
52
- # to setup any callbacks, add more events, etc. Prepare is
53
- # called in the order the actions are defined, and the action
54
- # itself has no control over this.
55
- #
56
- # Examples of its usage:
57
- #
58
- # Perhaps we need an additional action only if a configuration is set:
59
- #
60
- # def prepare
61
- # @vm.actions << FooAction if Vagrant.config[:foo] == :bar
62
- # end
63
- #
64
- def prepare; end
65
-
66
- # This method is called once, after preparing, to execute the
67
- # actual task. This method is responsible for calling any
68
- # callbacks. Adding new actions here will have unpredictable
69
- # effects and should never be done.
70
- #
71
- # Examples of its usage:
72
- #
73
- # def execute!
74
- # @vm.invoke_callback(:before_oven, "cookies")
75
- # # Do lots of stuff here
76
- # @vm.invoke_callback(:after_oven, "more", "than", "one", "option")
77
- # end
78
- #
79
- def execute!; end
80
-
81
- # This method is called after all actions have finished executing.
82
- # It is meant as a place where final cleanup code can be done, knowing
83
- # that all other actions are finished using your data.
84
- def cleanup; end
85
-
86
- # This method is only called if some exception occurs in the chain
87
- # of actions. If an exception is raised in any action in the current
88
- # chain, then every action part of that chain has {#rescue} called
89
- # before raising the exception further. This method should be used to
90
- # perform any cleanup necessary in the face of errors.
91
- #
92
- # **Warning:** Since this method is called when an exception is already
93
- # raised, be _extra careful_ when implementing this method to handle
94
- # all your own exceptions, otherwise it'll mask the initially raised
95
- # exception.
96
- def rescue(exception); end
97
-
98
- # The following two methods are used for declaring action dependencies.
99
- # For example, you require that the reload action be in place before
100
- # a your new FooAction you might do the following
101
- #
102
- # def follows; [Reload] end
103
-
104
- # This method is called when the runner is determining the actions that
105
- # must precede a given action. You would say "This action follows [Action1, Action2]"
106
- def follows; [] end
107
-
108
- # This method is called when the runner is determining the actions that
109
- # must follow a given action. You would say "This action precedes [Action3, Action4]
110
- def precedes; [] end
111
- end
112
-
113
- # An exception which occured within an action. This should be used instead of
114
- # {Vagrant::Util#error_and_exit error_and_exit}, since it allows the {Runner} to call
115
- # {Base#rescue rescue} on all the actions and properly exit. Any message
116
- # passed into the {ActionException} is then shown and and vagrant exits.
117
- class ActionException < Exception
118
- attr_reader :key
119
- attr_reader :data
120
-
121
- def initialize(key, data = {})
122
- @key = key
123
- @data = data
124
-
125
- message = Vagrant::Util::Translator.t(key, data)
126
- super(message)
127
- end
128
- end
129
- end
130
- end
@@ -1,23 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- module Box
4
- # A meta-action which adds a box by downloading and unpackaging it.
5
- # This action downloads and unpackages a box with a given URI. This
6
- # is a _meta action_, meaning it simply adds more actions to the
7
- # action chain, and those actions do the work.
8
- #
9
- # This is the action called by {Box#add}.
10
- class Add < Base
11
- def prepare
12
- if File.exists?(@runner.directory)
13
- raise ActionException.new(:box_add_already_exists, :box_name => @runner.name)
14
- end
15
-
16
- @runner.add_action(Download)
17
- @runner.add_action(Unpackage)
18
- @runner.add_action(Verify)
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,14 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- module Box
4
- # Action to destroy a box. This action is not reversible and expects
5
- # to be called by a {Box} object.
6
- class Destroy < Base
7
- def execute!
8
- logger.info "Deleting box directory..."
9
- FileUtils.rm_rf(@runner.directory)
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,67 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- module Box
4
- # An action which acts on a box by downloading the box file from
5
- # the given URI into a temporary location. This action parses a
6
- # given URI and handles downloading it via one of the many Vagrant
7
- # downloads (such as {Vagrant::Downloaders::File}).
8
- #
9
- # This action cleans itself up by removing the downloaded box file.
10
- class Download < Base
11
- BASENAME = "box"
12
- BUFFERSIZE = 1048576 # 1 MB
13
-
14
- attr_reader :downloader
15
-
16
- def prepare
17
- # Check the URI given and prepare a downloader
18
- [Downloaders::HTTP, Downloaders::File].each do |dler|
19
- if dler.match?(@runner.uri)
20
- logger.info "Downloading via #{dler}..."
21
- @downloader = dler.new(@runner.env)
22
- end
23
- end
24
-
25
- raise ActionException.new(:box_download_unknown_type) unless @downloader
26
-
27
- # Prepare the downloader
28
- @downloader.prepare(@runner.uri)
29
- end
30
-
31
- def execute!
32
- with_tempfile do |tempfile|
33
- download_to(tempfile)
34
- @runner.temp_path = tempfile.path
35
- end
36
- end
37
-
38
- def cleanup
39
- if @runner.temp_path && File.exist?(@runner.temp_path)
40
- logger.info "Cleaning up downloaded box..."
41
- File.unlink(@runner.temp_path)
42
- end
43
- end
44
-
45
- def rescue(exception)
46
- cleanup
47
- end
48
-
49
- def with_tempfile
50
- logger.info "Creating tempfile for storing box file..."
51
- File.open(box_temp_path, Platform.tar_file_options) do |tempfile|
52
- yield tempfile
53
- end
54
- end
55
-
56
- def box_temp_path
57
- File.join(@runner.env.tmp_path, BASENAME + Time.now.to_i.to_s)
58
- end
59
-
60
- def download_to(f)
61
- logger.info "Copying box to temporary location..."
62
- downloader.download!(@runner.uri, f)
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,42 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- module Box
4
- # This action unpackages a downloaded box file into its final
5
- # box destination within the vagrant home folder.
6
- class Unpackage < Base
7
- def execute!
8
- @runner.invoke_around_callback(:unpackage) do
9
- setup_box_dir
10
- decompress
11
- end
12
- end
13
-
14
- def rescue(exception)
15
- if File.directory?(box_dir)
16
- logger.info "An error occurred, rolling back box unpackaging..."
17
- FileUtils.rm_rf(box_dir)
18
- end
19
- end
20
-
21
- def setup_box_dir
22
- if File.directory?(box_dir)
23
- error_and_exit(:box_already_exists, :box_name => @runner.name)
24
- end
25
-
26
- FileUtils.mkdir_p(box_dir)
27
- end
28
-
29
- def box_dir
30
- @runner.directory
31
- end
32
-
33
- def decompress
34
- Dir.chdir(box_dir) do
35
- logger.info "Extracting box to #{box_dir}..."
36
- Archive::Tar::Minitar.unpack(@runner.temp_path, box_dir)
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,32 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- module Box
4
- # This action verifies that a given box is valid. This works by attempting
5
- # to read/interpret the appliance file (OVF). If the reading succeeds, then
6
- # the box is assumed to be valid.
7
- class Verify < Base
8
- def execute!
9
- logger.info "Verifying box..."
10
- reload_configuration
11
- verify_appliance
12
- end
13
-
14
- def reload_configuration
15
- # We have to reload the environment config since we _just_ added the
16
- # box. We do this by setting the current box to the recently added box,
17
- # then reloading
18
- @runner.env.config.vm.box = @runner.name
19
- @runner.env.load_box!
20
- @runner.env.load_config!
21
- end
22
-
23
- def verify_appliance
24
- # We now try to read the applince. If it succeeds, we return true.
25
- VirtualBox::Appliance.new(@runner.ovf_file)
26
- rescue Exception
27
- raise ActionException.new(:box_verification_failed)
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,36 +0,0 @@
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
@@ -1,131 +0,0 @@
1
- module Vagrant
2
- module Actions
3
- # Base class for any class which will act as a runner
4
- # for actions. A runner handles queueing up and executing actions,
5
- # and executing the methods of an action in the proper order. The
6
- # action runner also handles invoking callbacks that actions may
7
- # request.
8
- #
9
- # # Executing Actions
10
- #
11
- # Actions can be executed by adding them and executing them all
12
- # at once:
13
- #
14
- # runner = Vagrant::Actions::Runner.new
15
- # runner.add_action(FooAction)
16
- # runner.add_action(BarAction)
17
- # runner.add_action(BazAction)
18
- # runner.execute!
19
- #
20
- # Single actions have a shorthand to be executed:
21
- #
22
- # Vagrant::Actions::Runner.execute!(FooAction)
23
- #
24
- # Arguments may be passed into added actions by adding them after
25
- # the action class:
26
- #
27
- # runner.add_action(FooAction, "many", "arguments", "may", "follow")
28
- #
29
- class Runner
30
- include Vagrant::Util
31
-
32
- class << self
33
- # Executes a specific action, optionally passing in any arguments to that
34
- # action. This method is shorthand to initializing a runner, adding a single
35
- # action, and executing it.
36
- def execute!(action_klass, *args)
37
- runner = new
38
- runner.add_action(action_klass, *args)
39
- runner.execute!
40
- end
41
- end
42
-
43
- # Returns an array of all the actions in queue. Because this
44
- # will persist accross calls (calling {#actions} twice will yield
45
- # exactly the same object), to clear or modify it, use the ruby
46
- # array methods which act on `self`, such as `Array#clear`.
47
- #
48
- # @return [Array]
49
- def actions
50
- @actions ||= Actions::Collection.new
51
- end
52
-
53
- # Returns the first action instance which matches the given class.
54
- #
55
- # @param [Class] action_klass The action to search for in the queue
56
- # @return [Object]
57
- def find_action(action_klass)
58
- actions.find { |a| a.is_a?(action_klass) }
59
- end
60
-
61
- # Add an action to the list of queued actions to execute. This method
62
- # appends the given action class to the end of the queue. Any arguments
63
- # given after the class are passed into the class constructor.
64
- def add_action(action_klass, *args)
65
- actions << action_klass.new(self, *args)
66
- end
67
-
68
- # Execute the actions in queue. This method can also optionally be used
69
- # to execute a single action on an instance. The syntax for executing a
70
- # single method on an instance is the same as the {execute!} class method.
71
- def execute!(single_action=nil, *args)
72
- if single_action
73
- actions.clear
74
- add_action(single_action, *args)
75
- end
76
-
77
- actions.duplicates!
78
- actions.dependencies!
79
-
80
- # Call the prepare method on each once its
81
- # initialized, then call the execute! method
82
- begin
83
- [:prepare, :execute!, :cleanup].each do |method|
84
- actions.each do |action|
85
- action.send(method)
86
- end
87
- end
88
- rescue Exception => e
89
- # Run the rescue code to do any emergency cleanup
90
- actions.each do |action|
91
- action.rescue(e)
92
- end
93
-
94
- # If its an ActionException, error and exit the message
95
- if e.is_a?(ActionException)
96
- error_and_exit(e.key, e.data)
97
- return
98
- end
99
-
100
- # Finally, reraise the exception
101
- raise
102
- end
103
-
104
- # Clear the actions
105
- actions.clear
106
- end
107
-
108
- # Invokes an "around callback" which invokes before_name and
109
- # after_name for the given callback name, yielding a block between
110
- # callback invokations.
111
- def invoke_around_callback(name, *args)
112
- invoke_callback("before_#{name}".to_sym, *args)
113
- yield
114
- invoke_callback("after_#{name}".to_sym, *args)
115
- end
116
-
117
- # Invokes a single callback. This method will go through each action
118
- # and call the method given in the parameter `name` if the action
119
- # responds to it.
120
- def invoke_callback(name, *args)
121
- # Attempt to call the method for the callback on each of the
122
- # actions
123
- results = []
124
- actions.each do |action|
125
- results << action.send(name, *args) if action.respond_to?(name)
126
- end
127
- results
128
- end
129
- end
130
- end
131
- end