vagrant 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. data/.gitignore +1 -0
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +56 -0
  4. data/Gemfile +14 -3
  5. data/Gemfile.lock +38 -11
  6. data/README.md +1 -1
  7. data/bin/vagrant +20 -5
  8. data/config/default.rb +6 -8
  9. data/lib/vagrant.rb +40 -13
  10. data/lib/vagrant/action.rb +56 -16
  11. data/lib/vagrant/action/box/destroy.rb +3 -1
  12. data/lib/vagrant/action/box/download.rb +8 -13
  13. data/lib/vagrant/action/box/unpackage.rb +8 -11
  14. data/lib/vagrant/action/box/verify.rb +3 -3
  15. data/lib/vagrant/action/builder.rb +3 -30
  16. data/lib/vagrant/action/builtin.rb +6 -1
  17. data/lib/vagrant/action/environment.rb +14 -62
  18. data/lib/vagrant/action/general/package.rb +29 -22
  19. data/lib/vagrant/action/vm/boot.rb +5 -12
  20. data/lib/vagrant/action/vm/check_box.rb +4 -4
  21. data/lib/vagrant/action/vm/check_guest_additions.rb +4 -6
  22. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +2 -2
  23. data/lib/vagrant/action/vm/clear_nfs_exports.rb +1 -1
  24. data/lib/vagrant/action/vm/clear_shared_folders.rb +1 -1
  25. data/lib/vagrant/action/vm/customize.rb +1 -1
  26. data/lib/vagrant/action/vm/destroy.rb +1 -2
  27. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +1 -1
  28. data/lib/vagrant/action/vm/disable_networks.rb +11 -9
  29. data/lib/vagrant/action/vm/discard_state.rb +2 -2
  30. data/lib/vagrant/action/vm/export.rb +10 -11
  31. data/lib/vagrant/action/vm/forward_ports.rb +21 -9
  32. data/lib/vagrant/action/vm/halt.rb +3 -8
  33. data/lib/vagrant/action/vm/import.rb +16 -14
  34. data/lib/vagrant/action/vm/match_mac_address.rb +1 -1
  35. data/lib/vagrant/action/vm/network.rb +9 -16
  36. data/lib/vagrant/action/vm/nfs.rb +14 -18
  37. data/lib/vagrant/action/vm/provision.rb +5 -5
  38. data/lib/vagrant/action/vm/resume.rb +1 -1
  39. data/lib/vagrant/action/vm/share_folders.rb +6 -44
  40. data/lib/vagrant/action/vm/suspend.rb +1 -1
  41. data/lib/vagrant/action/warden.rb +74 -0
  42. data/lib/vagrant/box.rb +18 -82
  43. data/lib/vagrant/box_collection.rb +47 -0
  44. data/lib/vagrant/cli.rb +55 -0
  45. data/lib/vagrant/command/base.rb +106 -0
  46. data/lib/vagrant/command/box.rb +33 -0
  47. data/lib/vagrant/command/destroy.rb +17 -0
  48. data/lib/vagrant/command/group_base.rb +99 -0
  49. data/lib/vagrant/command/halt.rb +18 -0
  50. data/lib/vagrant/command/helpers.rb +33 -0
  51. data/lib/vagrant/command/init.rb +14 -0
  52. data/lib/vagrant/command/named_base.rb +14 -0
  53. data/lib/vagrant/command/package.rb +41 -0
  54. data/lib/vagrant/command/provision.rb +17 -0
  55. data/lib/vagrant/command/reload.rb +17 -0
  56. data/lib/vagrant/command/resume.rb +17 -0
  57. data/lib/vagrant/command/ssh.rb +41 -0
  58. data/lib/vagrant/command/ssh_config.rb +21 -0
  59. data/lib/vagrant/command/status.rb +23 -0
  60. data/lib/vagrant/command/suspend.rb +17 -0
  61. data/lib/vagrant/command/up.rb +20 -0
  62. data/lib/vagrant/command/upgrade_to_060.rb +45 -0
  63. data/lib/vagrant/command/version.rb +13 -0
  64. data/lib/vagrant/config.rb +107 -189
  65. data/lib/vagrant/config/base.rb +67 -0
  66. data/lib/vagrant/config/error_recorder.rb +19 -0
  67. data/lib/vagrant/config/nfs.rb +10 -0
  68. data/lib/vagrant/config/package.rb +9 -0
  69. data/lib/vagrant/config/ssh.rb +28 -0
  70. data/lib/vagrant/config/vagrant.rb +21 -0
  71. data/lib/vagrant/config/vm.rb +111 -0
  72. data/lib/vagrant/data_store.rb +68 -0
  73. data/lib/vagrant/downloaders/file.rb +3 -3
  74. data/lib/vagrant/downloaders/http.rb +5 -5
  75. data/lib/vagrant/environment.rb +246 -243
  76. data/lib/vagrant/errors.rb +306 -0
  77. data/lib/vagrant/hosts/base.rb +1 -1
  78. data/lib/vagrant/hosts/bsd.rb +3 -9
  79. data/lib/vagrant/hosts/linux.rb +3 -9
  80. data/lib/vagrant/plugin.rb +50 -0
  81. data/lib/vagrant/provisioners/base.rb +0 -6
  82. data/lib/vagrant/provisioners/chef.rb +63 -58
  83. data/lib/vagrant/provisioners/chef_server.rb +9 -11
  84. data/lib/vagrant/provisioners/chef_solo.rb +2 -2
  85. data/lib/vagrant/ssh.rb +34 -37
  86. data/lib/vagrant/systems/base.rb +0 -13
  87. data/lib/vagrant/systems/linux.rb +10 -33
  88. data/lib/vagrant/systems/solaris.rb +59 -0
  89. data/lib/vagrant/test_helpers.rb +109 -0
  90. data/lib/vagrant/ui.rb +65 -0
  91. data/lib/vagrant/util.rb +9 -19
  92. data/lib/vagrant/util/glob_loader.rb +19 -17
  93. data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
  94. data/lib/vagrant/util/plain_logger.rb +2 -0
  95. data/lib/vagrant/util/platform.rb +2 -0
  96. data/lib/vagrant/util/resource_logger.rb +5 -70
  97. data/lib/vagrant/util/retryable.rb +25 -0
  98. data/lib/vagrant/util/template_renderer.rb +1 -1
  99. data/lib/vagrant/version.rb +1 -1
  100. data/lib/vagrant/vm.rb +27 -13
  101. data/templates/commands/init/Vagrantfile.erb +13 -0
  102. data/templates/config/validation_failed.erb +7 -0
  103. data/templates/locales/en.yml +402 -0
  104. data/templates/package_Vagrantfile.erb +1 -1
  105. data/test/locales/en.yml +8 -0
  106. data/test/test_helper.rb +19 -103
  107. data/test/vagrant/action/box/destroy_test.rb +7 -19
  108. data/test/vagrant/action/box/download_test.rb +9 -25
  109. data/test/vagrant/action/box/package_test.rb +2 -2
  110. data/test/vagrant/action/box/unpackage_test.rb +8 -34
  111. data/test/vagrant/action/box/verify_test.rb +10 -19
  112. data/test/vagrant/action/builder_test.rb +0 -15
  113. data/test/vagrant/action/env/set_test.rb +1 -1
  114. data/test/vagrant/action/environment_test.rb +8 -26
  115. data/test/vagrant/action/general/package_test.rb +53 -53
  116. data/test/vagrant/action/vm/boot_test.rb +5 -22
  117. data/test/vagrant/action/vm/check_box_test.rb +35 -25
  118. data/test/vagrant/action/vm/clean_machine_folder_test.rb +1 -1
  119. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +1 -1
  120. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +1 -1
  121. data/test/vagrant/action/vm/clear_shared_folders_test.rb +1 -1
  122. data/test/vagrant/action/vm/customize_test.rb +2 -1
  123. data/test/vagrant/action/vm/destroy_test.rb +1 -2
  124. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +1 -1
  125. data/test/vagrant/action/vm/disable_networks_test.rb +10 -1
  126. data/test/vagrant/action/vm/discard_state_test.rb +10 -1
  127. data/test/vagrant/action/vm/export_test.rb +9 -37
  128. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +2 -2
  129. data/test/vagrant/action/vm/forward_ports_test.rb +19 -16
  130. data/test/vagrant/action/vm/halt_test.rb +11 -1
  131. data/test/vagrant/action/vm/import_test.rb +37 -21
  132. data/test/vagrant/action/vm/match_mac_address_test.rb +1 -1
  133. data/test/vagrant/action/vm/network_test.rb +8 -7
  134. data/test/vagrant/action/vm/nfs_helpers_test.rb +6 -3
  135. data/test/vagrant/action/vm/nfs_test.rb +20 -45
  136. data/test/vagrant/action/vm/package_test.rb +1 -1
  137. data/test/vagrant/action/vm/package_vagrantfile_test.rb +1 -1
  138. data/test/vagrant/action/vm/provision_test.rb +10 -17
  139. data/test/vagrant/action/vm/resume_test.rb +1 -1
  140. data/test/vagrant/action/vm/share_folders_test.rb +25 -106
  141. data/test/vagrant/action/vm/suspend_test.rb +1 -1
  142. data/test/vagrant/action/warden_test.rb +105 -0
  143. data/test/vagrant/action_test.rb +5 -27
  144. data/test/vagrant/box_collection_test.rb +44 -0
  145. data/test/vagrant/box_test.rb +5 -105
  146. data/test/vagrant/cli_test.rb +35 -0
  147. data/test/vagrant/command/base_test.rb +23 -0
  148. data/test/vagrant/command/group_base_test.rb +15 -0
  149. data/test/vagrant/command/helpers_test.rb +88 -0
  150. data/test/vagrant/config/base_test.rb +52 -0
  151. data/test/vagrant/config/error_recorder_test.rb +18 -0
  152. data/test/vagrant/config/ssh_test.rb +12 -0
  153. data/test/vagrant/config/vagrant_test.rb +11 -0
  154. data/test/vagrant/config/vm_test.rb +70 -0
  155. data/test/vagrant/config_test.rb +113 -206
  156. data/test/vagrant/data_store_test.rb +68 -0
  157. data/test/vagrant/downloaders/base_test.rb +1 -1
  158. data/test/vagrant/downloaders/file_test.rb +4 -3
  159. data/test/vagrant/downloaders/http_test.rb +14 -4
  160. data/test/vagrant/environment_test.rb +290 -590
  161. data/test/vagrant/errors_test.rb +42 -0
  162. data/test/vagrant/hosts/base_test.rb +1 -1
  163. data/test/vagrant/hosts/bsd_test.rb +3 -6
  164. data/test/vagrant/hosts/linux_test.rb +3 -5
  165. data/test/vagrant/plugin_test.rb +9 -0
  166. data/test/vagrant/provisioners/base_test.rb +1 -1
  167. data/test/vagrant/provisioners/chef_server_test.rb +31 -35
  168. data/test/vagrant/provisioners/chef_solo_test.rb +1 -1
  169. data/test/vagrant/provisioners/chef_test.rb +7 -7
  170. data/test/vagrant/ssh_session_test.rb +3 -10
  171. data/test/vagrant/ssh_test.rb +25 -33
  172. data/test/vagrant/systems/linux_test.rb +6 -71
  173. data/test/vagrant/ui_test.rb +29 -0
  174. data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
  175. data/test/vagrant/util/resource_logger_test.rb +14 -81
  176. data/test/vagrant/util/retryable_test.rb +38 -0
  177. data/test/vagrant/util/template_renderer_test.rb +4 -4
  178. data/test/vagrant/vm_test.rb +47 -26
  179. data/vagrant.gemspec +14 -12
  180. metadata +142 -108
  181. data/bin/.gitignore +0 -0
  182. data/lib/vagrant/action/action_exception.rb +0 -16
  183. data/lib/vagrant/action/env/error_halt.rb +0 -16
  184. data/lib/vagrant/action/exception_catcher.rb +0 -14
  185. data/lib/vagrant/action/vm/persist.rb +0 -22
  186. data/lib/vagrant/active_list.rb +0 -83
  187. data/lib/vagrant/command.rb +0 -27
  188. data/lib/vagrant/commands/base.rb +0 -181
  189. data/lib/vagrant/commands/box.rb +0 -16
  190. data/lib/vagrant/commands/box/add.rb +0 -30
  191. data/lib/vagrant/commands/box/list.rb +0 -30
  192. data/lib/vagrant/commands/box/remove.rb +0 -30
  193. data/lib/vagrant/commands/box/repackage.rb +0 -35
  194. data/lib/vagrant/commands/destroy.rb +0 -37
  195. data/lib/vagrant/commands/halt.rb +0 -43
  196. data/lib/vagrant/commands/init.rb +0 -36
  197. data/lib/vagrant/commands/package.rb +0 -81
  198. data/lib/vagrant/commands/provision.rb +0 -31
  199. data/lib/vagrant/commands/reload.rb +0 -36
  200. data/lib/vagrant/commands/resume.rb +0 -35
  201. data/lib/vagrant/commands/ssh.rb +0 -78
  202. data/lib/vagrant/commands/ssh_config.rb +0 -45
  203. data/lib/vagrant/commands/status.rb +0 -125
  204. data/lib/vagrant/commands/suspend.rb +0 -36
  205. data/lib/vagrant/commands/up.rb +0 -44
  206. data/lib/vagrant/exceptions/uncallable_action.rb +0 -17
  207. data/lib/vagrant/util/translator.rb +0 -35
  208. data/templates/strings.yml +0 -341
  209. data/templates/unison/crontab_entry.erb +0 -1
  210. data/templates/unison/script.erb +0 -71
  211. data/test/vagrant/action/env/error_halt_test.rb +0 -21
  212. data/test/vagrant/action/exception_catcher_test.rb +0 -30
  213. data/test/vagrant/action/vm/persist_test.rb +0 -50
  214. data/test/vagrant/active_list_test.rb +0 -173
  215. data/test/vagrant/command_test.rb +0 -53
  216. data/test/vagrant/commands/base_test.rb +0 -139
  217. data/test/vagrant/commands/box/add_test.rb +0 -34
  218. data/test/vagrant/commands/box/list_test.rb +0 -32
  219. data/test/vagrant/commands/box/remove_test.rb +0 -41
  220. data/test/vagrant/commands/box/repackage_test.rb +0 -52
  221. data/test/vagrant/commands/destroy_test.rb +0 -44
  222. data/test/vagrant/commands/halt_test.rb +0 -50
  223. data/test/vagrant/commands/init_test.rb +0 -71
  224. data/test/vagrant/commands/package_test.rb +0 -97
  225. data/test/vagrant/commands/provision_test.rb +0 -60
  226. data/test/vagrant/commands/reload_test.rb +0 -47
  227. data/test/vagrant/commands/resume_test.rb +0 -44
  228. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  229. data/test/vagrant/commands/ssh_test.rb +0 -129
  230. data/test/vagrant/commands/status_test.rb +0 -40
  231. data/test/vagrant/commands/suspend_test.rb +0 -44
  232. data/test/vagrant/commands/up_test.rb +0 -49
  233. data/test/vagrant/util/translator_test.rb +0 -61
  234. data/test/vagrant/util_test.rb +0 -27
data/lib/vagrant/ui.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'mario'
2
+
3
+ module Vagrant
4
+ # Vagrant UIs handle communication with the outside world (typically
5
+ # through a shell). They must respond to the typically logger methods
6
+ # of `warn`, `error`, `info`, and `confirm`.
7
+ class UI
8
+ attr_accessor :env
9
+
10
+ def initialize(env)
11
+ @env = env
12
+ end
13
+
14
+ [:warn, :error, :info, :confirm, :say_with_vm, :report_progress, :ask, :no?, :yes?].each do |method|
15
+ # By default these methods don't do anything. A silent UI.
16
+ define_method(method) { |*args| }
17
+ end
18
+
19
+ # A shell UI, which uses a `Thor::Shell` object to talk with
20
+ # a terminal.
21
+ class Shell < UI
22
+ def initialize(env, shell)
23
+ super(env)
24
+
25
+ @shell = shell
26
+ end
27
+
28
+ [[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
29
+ define_method(method) do |message, opts=nil|
30
+ @shell.say("#{line_reset}#{format_message(message, opts)}", color)
31
+ end
32
+ end
33
+
34
+ [:ask, :no?, :yes?].each do |method|
35
+ define_method(method) do |message, opts=nil|
36
+ opts ||= {}
37
+ @shell.send(method, format_message(message, opts), opts[:color])
38
+ end
39
+ end
40
+
41
+ def report_progress(progress, total, show_parts=true)
42
+ percent = (progress.to_f / total.to_f) * 100
43
+ line = "Progress: #{percent.to_i}%"
44
+ line << " (#{progress} / #{total})" if show_parts
45
+ line = "#{line_reset}#{line}"
46
+
47
+ @shell.say(line, nil, false)
48
+ end
49
+
50
+ protected
51
+
52
+ def format_message(message, opts=nil)
53
+ opts = { :prefix => true }.merge(opts || {})
54
+ message = "[#{env.resource}] #{message}" if opts[:prefix]
55
+ message
56
+ end
57
+
58
+ def line_reset
59
+ reset = "\r"
60
+ reset += "\e[0K" unless Mario::Platform.windows?
61
+ reset
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/vagrant/util.rb CHANGED
@@ -1,23 +1,13 @@
1
1
  module Vagrant
2
2
  module Util
3
- def self.included(base)
4
- base.extend(self)
5
- end
6
-
7
- def error_and_exit(key, data = {})
8
- abort <<-error
9
- =====================================================================
10
- Vagrant experienced an error!
11
-
12
- #{Translator.t(key, data).chomp}
13
- =====================================================================
14
- error
15
- end
16
-
17
- def wrap_output
18
- puts "====================================================================="
19
- yield
20
- puts "====================================================================="
21
- end
3
+ autoload :Busy, 'vagrant/util/busy'
4
+ autoload :GlobLoader, 'vagrant/util/glob_loader'
5
+ autoload :HashWithIndifferentAccess, 'vagrant/util/hash_with_indifferent_access'
6
+ autoload :PlainLogger, 'vagrant/util/plain_logger'
7
+ autoload :Platform, 'vagrant/util/platform'
8
+ autoload :ResourceLogger, 'vagrant/util/resource_logger'
9
+ autoload :Retryable, 'vagrant/util/retryable'
10
+ autoload :StackedProcRunner, 'vagrant/util/stacked_proc_runner'
11
+ autoload :TemplateRenderer, 'vagrant/util/template_renderer'
22
12
  end
23
13
  end
@@ -1,22 +1,24 @@
1
1
  module Vagrant
2
- # Eases the processes of loading specific files then globbing
3
- # the rest from a specified directory.
4
- module GlobLoader
5
- # Glob requires all ruby files in a directory, optionally loading select
6
- # files initially (since others may depend on them).
7
- #
8
- # @param [String] dir The directory to glob
9
- # @param [Array<String>] initial_files Initial files (relative to `dir`)
10
- # to load
11
- def self.glob_require(dir, initial_files=[])
12
- initial_files.each do |file|
13
- require File.expand_path(file, dir)
14
- end
2
+ module Util
3
+ # Eases the processes of loading specific files then globbing
4
+ # the rest from a specified directory.
5
+ module GlobLoader
6
+ # Glob requires all ruby files in a directory, optionally loading select
7
+ # files initially (since others may depend on them).
8
+ #
9
+ # @param [String] dir The directory to glob
10
+ # @param [Array<String>] initial_files Initial files (relative to `dir`)
11
+ # to load
12
+ def self.glob_require(dir, initial_files=[])
13
+ initial_files.each do |file|
14
+ require File.expand_path(file, dir)
15
+ end
15
16
 
16
- # Glob require the rest
17
- Dir[File.join(dir, "**", "*.rb")].each do |f|
18
- require File.expand_path(f)
17
+ # Glob require the rest
18
+ Dir[File.join(dir, "**", "*.rb")].each do |f|
19
+ require File.expand_path(f)
20
+ end
19
21
  end
20
22
  end
21
23
  end
22
- end
24
+ end
@@ -0,0 +1,63 @@
1
+ module Vagrant
2
+ module Util
3
+ # A hash with indifferent access. Mostly taken from Thor/Rails (thanks).
4
+ # Normally I'm not a fan of using an indifferent access hash sine Symbols
5
+ # are basically memory leaks in Ruby, but since Vagrant is typically a quick
6
+ # one-off binary run and it doesn't use too many hash keys where this is
7
+ # used, the effect should be minimal.
8
+ #
9
+ # hash[:foo] #=> 'bar'
10
+ # hash['foo'] #=> 'bar'
11
+ #
12
+ class HashWithIndifferentAccess < ::Hash
13
+ def initialize(hash={}, &block)
14
+ super(&block)
15
+
16
+ hash.each do |key, value|
17
+ self[convert_key(key)] = value
18
+ end
19
+ end
20
+
21
+ def [](key)
22
+ super(convert_key(key))
23
+ end
24
+
25
+ def []=(key, value)
26
+ super(convert_key(key), value)
27
+ end
28
+
29
+ def delete(key)
30
+ super(convert_key(key))
31
+ end
32
+
33
+ def values_at(*indices)
34
+ indices.collect { |key| self[convert_key(key)] }
35
+ end
36
+
37
+ def merge(other)
38
+ dup.merge!(other)
39
+ end
40
+
41
+ def merge!(other)
42
+ other.each do |key, value|
43
+ self[convert_key(key)] = value
44
+ end
45
+ self
46
+ end
47
+
48
+ def key?(key)
49
+ super(convert_key(key))
50
+ end
51
+
52
+ alias_method :include?, :key?
53
+ alias_method :has_key?, :key?
54
+ alias_method :member?, :key?
55
+
56
+ protected
57
+
58
+ def convert_key(key)
59
+ key.is_a?(Symbol) ? key.to_s : key
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,5 @@
1
+ require 'logger'
2
+
1
3
  module Vagrant
2
4
  module Util
3
5
  # Subclass of the standard library logger which has no format on
@@ -1,3 +1,5 @@
1
+ require 'mario'
2
+
1
3
  module Vagrant
2
4
  module Util
3
5
  # This class just contains some platform checking code.
@@ -11,14 +11,8 @@ module Vagrant
11
11
  #
12
12
  # This class is thread safe. The backing class which actually does
13
13
  # all the logging IO is protected.
14
- #
15
- # This class also handles progress meters of multiple resources and
16
- # handles all the proper interleaving and console updating to
17
- # display the progress meters in a way which doesn't conflict with
18
- # other incoming log messages.
19
14
  class ResourceLogger
20
15
  @@singleton_logger = nil
21
- @@progress_reporters = nil
22
16
  @@writer_lock = Mutex.new
23
17
 
24
18
  # The resource which this logger represents.
@@ -37,10 +31,11 @@ module Vagrant
37
31
  # instantiated, then the given environment will be used to
38
32
  # create a new logger.
39
33
  def singleton_logger(env=nil)
40
- if env && env.config && env.config.loaded?
41
- @@singleton_logger ||= PlainLogger.new(env.config.vagrant.log_output)
42
- else
43
- PlainLogger.new(nil)
34
+ return PlainLogger.new(nil) if !env.loaded?
35
+
36
+ @@singleton_logger ||= begin
37
+ file = env.log_path.join("#{Time.now.to_i}.log")
38
+ PlainLogger.new(file)
44
39
  end
45
40
  end
46
41
 
@@ -48,12 +43,6 @@ module Vagrant
48
43
  def reset_singleton_logger!
49
44
  @@singleton_logger = nil
50
45
  end
51
-
52
- # Returns the progress parts array which contains the various
53
- # progress reporters.
54
- def progress_reporters
55
- @@progress_reporters ||= {}
56
- end
57
46
  end
58
47
 
59
48
  def initialize(resource, env)
@@ -65,64 +54,10 @@ module Vagrant
65
54
  [:debug, :info, :error, :fatal].each do |method|
66
55
  define_method(method) do |message|
67
56
  @@writer_lock.synchronize do
68
- # We clear the line in case progress reports have been going
69
- # out.
70
- print(cl_reset)
71
57
  logger.send(method, "[#{resource}] #{message}")
72
58
  end
73
-
74
- # Once again flush the progress reporters since we probably
75
- # cleared any existing ones.
76
- flush_progress
77
59
  end
78
60
  end
79
-
80
- # Sets a progress report for the resource that this logger
81
- # represents. This progress report is interleaved within the output.
82
- def report_progress(progress, total, show_parts=true)
83
- # Simply add the progress reporter to the list of progress
84
- # reporters
85
- self.class.progress_reporters[resource] = {
86
- :progress => progress,
87
- :total => total,
88
- :show_parts => show_parts
89
- }
90
-
91
- # And force an update to occur
92
- flush_progress
93
- end
94
-
95
- # Clears the progress report for this resource
96
- def clear_progress
97
- self.class.progress_reporters.delete(resource)
98
- end
99
-
100
- def flush_progress
101
- # Don't do anything if there are no progress reporters
102
- return if self.class.progress_reporters.length <= 0
103
-
104
- @@writer_lock.synchronize do
105
- reports = []
106
-
107
- # First generate all the report percentages and output
108
- self.class.progress_reporters.each do |name, data|
109
- percent = (data[:progress].to_f / data[:total].to_f) * 100
110
- line = "#{name}: #{percent.to_i}%"
111
- line << " (#{data[:progress]} / #{data[:total]})" if data[:show_parts]
112
- reports << line
113
- end
114
-
115
- # Output it to stdout
116
- print "#{cl_reset}[progress] #{reports.join(" ")}"
117
- $stdout.flush
118
- end
119
- end
120
-
121
- def cl_reset
122
- reset = "\r"
123
- reset += "\e[0K" unless Mario::Platform.windows?
124
- reset
125
- end
126
61
  end
127
62
  end
128
63
  end
@@ -0,0 +1,25 @@
1
+ module Vagrant
2
+ module Util
3
+ module Retryable
4
+ # Retries a given block a specified number of times in the
5
+ # event the specified exception is raised. If the retries
6
+ # run out, the final exception is raised.
7
+ #
8
+ # This code is adapted slightly from the following blog post:
9
+ # http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/
10
+ def retryable(opts=nil)
11
+ opts = { :tries => 1, :on => Exception }.merge(opts || {})
12
+
13
+ begin
14
+ return yield
15
+ rescue opts[:on]
16
+ if (opts[:tries] -= 1) > 0
17
+ sleep opts[:sleep].to_f if opts[:sleep]
18
+ retry
19
+ end
20
+ raise
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -76,7 +76,7 @@ module Vagrant
76
76
  #
77
77
  # @return [String]
78
78
  def full_template_path
79
- File.join(PROJECT_ROOT, 'templates', "#{template}.erb").squeeze("/")
79
+ Vagrant.source_root.join('templates', "#{template}.erb").to_s.squeeze("/")
80
80
  end
81
81
  end
82
82
  end
@@ -2,5 +2,5 @@ module Vagrant
2
2
  # This will always be up to date with the current version of Vagrant,
3
3
  # since it is used to generate the gemspec and is also the source of
4
4
  # the version for `vagrant -v`
5
- VERSION = "0.5.4"
5
+ VERSION = "0.6.0"
6
6
  end
data/lib/vagrant/vm.rb CHANGED
@@ -5,14 +5,14 @@ module Vagrant
5
5
  attr_reader :env
6
6
  attr_reader :system
7
7
  attr_reader :name
8
- attr_accessor :vm
8
+ attr_reader :vm
9
9
 
10
10
  class << self
11
11
  # Finds a virtual machine by a given UUID and either returns
12
12
  # a Vagrant::VM object or returns nil.
13
- def find(uuid, env=nil, vm_name=nil)
13
+ def find(uuid, env=nil, name=nil)
14
14
  vm = VirtualBox::VM.find(uuid)
15
- new(:vm => vm, :env => env, :vm_name => vm_name)
15
+ new(:vm => vm, :env => env, :name => name)
16
16
  end
17
17
  end
18
18
 
@@ -20,13 +20,13 @@ module Vagrant
20
20
  defaults = {
21
21
  :vm => nil,
22
22
  :env => nil,
23
- :vm_name => nil
23
+ :name => nil
24
24
  }
25
25
 
26
26
  opts = defaults.merge(opts || {})
27
27
 
28
28
  @vm = opts[:vm]
29
- @name = opts[:vm_name]
29
+ @name = opts[:name]
30
30
 
31
31
  if !opts[:env].nil?
32
32
  # We have an environment, so we create a new child environment
@@ -35,7 +35,6 @@ module Vagrant
35
35
  @env = Vagrant::Environment.new({
36
36
  :cwd => opts[:env].cwd,
37
37
  :parent => opts[:env],
38
- :vm_name => opts[:vm_name],
39
38
  :vm => self
40
39
  }).load!
41
40
 
@@ -54,19 +53,15 @@ module Vagrant
54
53
 
55
54
  if system.is_a?(Class)
56
55
  @system = system.new(self)
57
- error_and_exit(:system_invalid_class, :system => system.to_s) unless @system.is_a?(Systems::Base)
56
+ raise Errors::VMSystemError.new(:_key => :invalid_class, :system => system.to_s) if !@system.is_a?(Systems::Base)
58
57
  elsif system.is_a?(Symbol)
59
58
  # Hard-coded internal systems
60
59
  mapping = { :linux => Systems::Linux }
61
60
 
62
- if !mapping.has_key?(system)
63
- error_and_exit(:system_unknown_type, :system => system.to_s)
64
- return # for tests
65
- end
66
-
61
+ raise Errors::VMSystemError.new(:_key => :unknown_type, :system => system.to_s) if !mapping.has_key?(system)
67
62
  @system = mapping[system].new(self)
68
63
  else
69
- error_and_exit(:system_unspecified)
64
+ raise Errors::VMSystemError.new(:unspecified)
70
65
  end
71
66
  end
72
67
 
@@ -85,6 +80,25 @@ module Vagrant
85
80
  !vm.nil?
86
81
  end
87
82
 
83
+ # Sets the currently active VM for this VM. If the VM is a valid,
84
+ # created virtual machine, then it will also update the local data
85
+ # to persist the VM. Otherwise, it will remove itself from the
86
+ # local data (if it exists).
87
+ def vm=(value)
88
+ @vm = value
89
+ env.local_data[:active] ||= {}
90
+
91
+ if value && value.uuid
92
+ env.local_data[:active][name.to_s] = value.uuid
93
+ else
94
+ env.local_data[:active].delete(name.to_s)
95
+ end
96
+
97
+ # Commit the local data so that the next time vagrant is initialized,
98
+ # it realizes the VM exists
99
+ env.local_data.commit
100
+ end
101
+
88
102
  def uuid
89
103
  vm ? vm.uuid : nil
90
104
  end