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
@@ -0,0 +1,306 @@
1
+ # This file contains all of the internal errors in Vagrant's core
2
+ # commands, actions, etc.
3
+
4
+ module Vagrant
5
+ # This module contains all of the internal errors in Vagrant's core.
6
+ # These errors are _expected_ errors and as such don't typically represent
7
+ # bugs in Vagrant itself. These are meant as a way to detect errors and
8
+ # display them in a user-friendly way.
9
+ #
10
+ # # Defining a new Error
11
+ #
12
+ # To define a new error, inherit from {VagrantError}, which lets Vagrant
13
+ # know that this is an expected error, and also gives you some helpers for
14
+ # providing exit codes and error messages. An example is shown below, then
15
+ # it is explained:
16
+ #
17
+ # class MyError < Vagrant::Errors::VagrantError
18
+ # error_key "my_error"
19
+ # end
20
+ #
21
+ # This creates an error with an I18n error key of "my_error." {VagrantError}
22
+ # uses I18n to look up error messages, in the "vagrant.errors" namespace. So
23
+ # in the above, the error message would be the translation of "vagrant.errors.my_error"
24
+ #
25
+ # If you don't want to use I18n, you can override the {#initialize} method and
26
+ # set your own error message.
27
+ #
28
+ # # Raising an Error
29
+ #
30
+ # To raise an error, it is nothing special, just raise it like any normal
31
+ # exception:
32
+ #
33
+ # raise MyError.new
34
+ #
35
+ # Eventually this exception will bubble out to the `vagrant` binary which
36
+ # will show a nice error message. And if it is raised in the middle of a
37
+ # middleware sequence, then {Action::Warden} will catch it and begin the
38
+ # recovery process prior to exiting.
39
+ module Errors
40
+ # Main superclass of any errors in Vagrant. This provides some
41
+ # convenience methods for setting the status code and error key.
42
+ # The status code is used by the `vagrant` executable as the
43
+ # error code, and the error key is used as a default message from
44
+ # I18n.
45
+ class VagrantError < StandardError
46
+ @@used_codes = []
47
+
48
+ def self.status_code(code = nil)
49
+ if code
50
+ raise "Status code already in use: #{code}" if @@used_codes.include?(code)
51
+ @@used_codes << code
52
+ end
53
+
54
+ define_method(:status_code) { code }
55
+ end
56
+
57
+ def self.error_key(key=nil, namespace=nil)
58
+ define_method(:error_key) { key }
59
+ error_namespace(namespace) if namespace
60
+ end
61
+
62
+ def self.error_namespace(namespace)
63
+ define_method(:error_namespace) { namespace }
64
+ end
65
+
66
+ def initialize(message=nil, *args)
67
+ message = { :_key => message } if message && !message.is_a?(Hash)
68
+ message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {})
69
+ message = translate_error(message)
70
+
71
+ super
72
+ end
73
+
74
+ # The default error namespace which is used for the error key.
75
+ # This can be overridden here or by calling the "error_namespace"
76
+ # class method.
77
+ def error_namespace; "vagrant.errors"; end
78
+
79
+ # The key for the error message. This should be set using the
80
+ # {error_key} method but can be overridden here if needed.
81
+ def error_key; nil; end
82
+
83
+ protected
84
+
85
+ def translate_error(opts)
86
+ return nil if !opts[:_key]
87
+ I18n.t("#{opts[:_namespace]}.#{opts[:_key]}", opts)
88
+ end
89
+ end
90
+
91
+ class BaseVMNotFound < VagrantError
92
+ status_code(18)
93
+ error_key(:base_vm_not_found)
94
+ end
95
+
96
+ class BoxAlreadyExists < VagrantError
97
+ status_code(14)
98
+ error_key(:already_exists, "vagrant.actions.box.unpackage")
99
+ end
100
+
101
+ class BoxDownloadUnknownType < VagrantError
102
+ status_code(13)
103
+ error_key(:unknown_type, "vagrant.actions.box.download")
104
+ end
105
+
106
+ class BoxNotFound < VagrantError
107
+ status_code(2)
108
+ error_key(:box_not_found)
109
+ end
110
+
111
+ class BoxNotSpecified < VagrantError
112
+ status_code(22)
113
+ error_key(:not_specified, "vagrant.actions.vm.check_box")
114
+ end
115
+
116
+ class BoxSpecifiedDoesntExist < VagrantError
117
+ status_code(23)
118
+ error_key(:does_not_exist, "vagrant.actions.vm.check_box")
119
+ end
120
+
121
+ class BoxVerificationFailed < VagrantError
122
+ status_code(15)
123
+ error_key(:failed, "vagrant.actions.box.verify")
124
+ end
125
+
126
+ class CLIMissingEnvironment < VagrantError
127
+ status_code(1)
128
+ error_key(:cli_missing_env)
129
+ end
130
+
131
+ class ConfigValidationFailed < VagrantError
132
+ status_code(42)
133
+ error_key(:config_validation)
134
+ end
135
+
136
+ class DownloaderFileDoesntExist < VagrantError
137
+ status_code(37)
138
+ error_key(:file_missing, "vagrant.downloaders.file")
139
+ end
140
+
141
+ class DownloaderHTTPSocketError < VagrantError
142
+ status_code(38)
143
+ error_key(:socket_error, "vagrant.downloaders.http")
144
+ end
145
+
146
+ class ForwardPortAutolistEmpty < VagrantError
147
+ status_code(27)
148
+ error_key(:auto_empty, "vagrant.actions.vm.forward_ports")
149
+ end
150
+
151
+ class ForwardPortBelowThreshold < VagrantError
152
+ status_code(25)
153
+ error_key(:below_threshold_error, "vagrant.actions.vm.forward_ports")
154
+ end
155
+
156
+ class ForwardPortCollision < VagrantError
157
+ status_code(26)
158
+ error_key(:collision_error, "vagrant.actions.vm.forward_ports")
159
+ end
160
+
161
+ class MultiVMEnvironmentRequired < VagrantError
162
+ status_code(5)
163
+ error_key(:multi_vm_required)
164
+ end
165
+
166
+ class MultiVMTargetRequired < VagrantError
167
+ status_code(7)
168
+ error_key(:multi_vm_target_required)
169
+ end
170
+
171
+ class NetworkCollision < VagrantError
172
+ status_code(29)
173
+ error_key(:collides, "vagrant.actions.vm.network")
174
+ end
175
+
176
+ class NetworkNotFound < VagrantError
177
+ status_code(30)
178
+ error_key(:not_found, "vagrant.actions.vm.network")
179
+ end
180
+
181
+ class NFSHostRequired < VagrantError
182
+ status_code(31)
183
+ error_key(:host_required, "vagrant.actions.vm.nfs")
184
+ end
185
+
186
+ class NFSNotSupported < VagrantError
187
+ status_code(32)
188
+ error_key(:not_supported, "vagrant.actions.vm.nfs")
189
+ end
190
+
191
+ class NFSNoHostNetwork < VagrantError
192
+ status_code(33)
193
+ error_key(:no_host_network, "vagrant.actions.vm.nfs")
194
+ end
195
+
196
+ class NoEnvironmentError < VagrantError
197
+ status_code(3)
198
+ error_key(:no_env)
199
+ end
200
+
201
+ class PackageIncludeMissing < VagrantError
202
+ status_code(20)
203
+ error_key(:include_file_missing, "vagrant.actions.general.package")
204
+ end
205
+
206
+ class PackageOutputExists < VagrantError
207
+ status_code(16)
208
+ error_key(:output_exists, "vagrant.actions.general.package")
209
+ end
210
+
211
+ class PackageRequiresDirectory < VagrantError
212
+ status_code(19)
213
+ error_key(:requires_directory, "vagrant.actions.general.package")
214
+ end
215
+
216
+ class PersistDotfileExists < VagrantError
217
+ status_code(34)
218
+ error_key(:dotfile_error, "vagrant.actions.vm.persist")
219
+ end
220
+
221
+ class ProvisionInvalidClass < VagrantError
222
+ status_code(35)
223
+ error_key(:invalid_class, "vagrant.actions.vm.provision")
224
+ end
225
+
226
+ class ProvisionUnknownType < VagrantError
227
+ status_code(36)
228
+ error_key(:unknown_type, "vagrant.actions.vm.provision")
229
+ end
230
+
231
+ class SSHAuthenticationFailed < VagrantError
232
+ status_code(11)
233
+ error_key(:ssh_authentication_failed)
234
+ end
235
+
236
+ class SSHConnectionRefused < VagrantError
237
+ status_code(43)
238
+ error_key(:ssh_connection_refused)
239
+ end
240
+
241
+ class SSHKeyBadPermissions < VagrantError
242
+ status_code(12)
243
+ error_key(:ssh_key_bad_permissions)
244
+ end
245
+
246
+ class SSHUnavailableWindows < VagrantError
247
+ status_code(10)
248
+ error_key(:ssh_unavailable_windows)
249
+ end
250
+
251
+ class VagrantInterrupt < VagrantError
252
+ status_code(40)
253
+ error_key(:interrupted)
254
+ end
255
+
256
+ class VagrantfileSyntaxError < VagrantError
257
+ status_code(41)
258
+ error_key(:vagrantfile_syntax_error)
259
+ end
260
+
261
+ class VirtualBoxInvalidOSE < VagrantError
262
+ status_code(9)
263
+ error_key(:virtualbox_invalid_ose)
264
+ end
265
+
266
+ class VirtualBoxInvalidVersion < VagrantError
267
+ status_code(17)
268
+ error_key(:virtualbox_invalid_version)
269
+ end
270
+
271
+ class VirtualBoxNotDetected < VagrantError
272
+ status_code(8)
273
+ error_key(:virtualbox_not_detected)
274
+ end
275
+
276
+ class VMFailedToBoot < VagrantError
277
+ status_code(21)
278
+ error_key(:failed_to_boot, "vagrant.actions.vm.boot")
279
+ end
280
+
281
+ class VMImportFailure < VagrantError
282
+ status_code(28)
283
+ error_key(:failure, "vagrant.actions.vm.import")
284
+ end
285
+
286
+ class VMNotCreatedError < VagrantError
287
+ status_code(6)
288
+ error_key(:vm_creation_required)
289
+ end
290
+
291
+ class VMNotFoundError < VagrantError
292
+ status_code(4)
293
+ error_key(:vm_not_found)
294
+ end
295
+
296
+ class VMPowerOffToPackage < VagrantError
297
+ status_code(24)
298
+ error_key(:power_off, "vagrant.actions.vm.export")
299
+ end
300
+
301
+ class VMSystemError < VagrantError
302
+ status_code(39)
303
+ error_namespace("vagrant.errors.system")
304
+ end
305
+ end
306
+ end
@@ -45,7 +45,7 @@ module Vagrant
45
45
  end
46
46
 
47
47
  # Initialzes a new host. This method shouldn't be called directly,
48
- # typically, since it will be called by {Environment#load_host!}
48
+ # typically, since it will be called by {Environment#load!}.
49
49
  #
50
50
  # @param [Environment] env
51
51
  def initialize(env)
@@ -3,17 +3,11 @@ module Vagrant
3
3
  # Represents a BSD host, such as FreeBSD and Darwin (Mac OS X).
4
4
  class BSD < Base
5
5
  include Util
6
+ include Util::Retryable
6
7
 
7
8
  def nfs?
8
- tries = 10
9
- begin
9
+ retryable(:tries => 10, :on => TypeError) do
10
10
  system("which nfsd > /dev/null 2>&1")
11
- rescue TypeError
12
- tries -= 1
13
- retry if tries > 0
14
-
15
- # Hopefully this point isn't reached
16
- raise
17
11
  end
18
12
  end
19
13
 
@@ -25,7 +19,7 @@ module Vagrant
25
19
 
26
20
  # The sleep ensures that the output is truly flushed before any `sudo`
27
21
  # commands are issued.
28
- env.logger.info "Preparing to edit /etc/exports. Administrator priveleges will be required..."
22
+ env.ui.info I18n.t("vagrant.hosts.bsd.nfs_export.prepare")
29
23
  sleep 0.5
30
24
 
31
25
  output.split("\n").each do |line|
@@ -3,18 +3,12 @@ module Vagrant
3
3
  # Represents a Linux based host, such as Ubuntu.
4
4
  class Linux < Base
5
5
  include Util
6
+ include Util::Retryable
6
7
 
7
8
  def nfs?
8
- tries = 10
9
- begin
9
+ retryable(:tries => 10, :on => TypeError) do
10
10
  # Check procfs to see if NFSd is a supported filesystem
11
11
  system("cat /proc/filesystems | grep nfsd > /dev/null 2>&1")
12
- rescue TypeError
13
- tries -= 1
14
- retry if tries > 0
15
-
16
- # Hopefully this point isn't reached
17
- raise
18
12
  end
19
13
  end
20
14
 
@@ -24,7 +18,7 @@ module Vagrant
24
18
  :ip => ip,
25
19
  :folders => folders)
26
20
 
27
- env.logger.info "Preparing to edit /etc/exports. Administrator priveleges will be required..."
21
+ env.ui.info I18n.t("vagrant.hosts.linux.nfs_export.prepare")
28
22
  sleep 0.5
29
23
 
30
24
  output.split("\n").each do |line|
@@ -0,0 +1,50 @@
1
+ require "rubygems"
2
+
3
+ module Vagrant
4
+ # Represents a single plugin and also manages loading plugins from
5
+ # RubyGems. If a plugin has a `vagrant_init.rb` file somewhere on its
6
+ # load path, then this class will find it and load it. For logging purposes
7
+ # (for debugging), the list of loaded plugins is stored in the {plugins}
8
+ # array.
9
+ class Plugin
10
+ # The array of loaded plugins.
11
+ @@plugins = []
12
+
13
+ # The gemspec of this plugin. This is an actual gemspec object.
14
+ attr_reader :gemspec
15
+
16
+ # The path to the `vagrant_init.rb` file which was loaded for this plugin.
17
+ attr_reader :file
18
+
19
+ # Loads all the plugins for Vagrant. Plugins are currently
20
+ # gems which have a "vagrant_init.rb" somewhere on their
21
+ # load path. This file is loaded to kick off the load sequence
22
+ # for that plugin.
23
+ def self.load!
24
+ # Look for a vagrant_init.rb in all the gems, but only the
25
+ # latest version of the gems.
26
+ Gem.source_index.latest_specs.each do |spec|
27
+ file = Gem.searcher.matching_files(spec, "vagrant_init.rb").first
28
+ next if !file
29
+
30
+ @@plugins << new(spec, file)
31
+ end
32
+ end
33
+
34
+ # Returns the array of plugins which are currently loaded by
35
+ # Vagrant.
36
+ #
37
+ # @return [Array]
38
+ def self.plugins; @@plugins; end
39
+
40
+ # Initializes a new plugin, given a Gemspec and the path to the
41
+ # gem's `vagrant_init.rb` file. This should never be called manually.
42
+ # Instead {load!} creates all the instances.
43
+ def initialize(spec, file)
44
+ @gemspec = spec
45
+ @file = file
46
+
47
+ load file
48
+ end
49
+ end
50
+ end
@@ -30,12 +30,6 @@ module Vagrant
30
30
  env.vm
31
31
  end
32
32
 
33
- # This method returns the environment's logger as a convenience
34
- # method.
35
- def logger
36
- env.logger
37
- end
38
-
39
33
  # This is the method called to "prepare" the provisioner. This is called
40
34
  # before any actions are run by the action runner (see {Vagrant::Actions::Runner}).
41
35
  # This can be used to setup shared folders, forward ports, etc. Whatever is
@@ -3,9 +3,67 @@ module Vagrant
3
3
  # This class is a base class where the common functinality shared between
4
4
  # chef-solo and chef-client provisioning are stored. This is **not an actual
5
5
  # provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
6
+ class Chef < Base
7
+ def prepare
8
+ raise ChefError.new(:invalid_provisioner)
9
+ end
10
+
11
+ def verify_binary(binary)
12
+ vm.ssh.execute do |ssh|
13
+ # Checks for the existence of chef binary and error if it
14
+ # doesn't exist.
15
+ ssh.exec!("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
16
+ end
17
+ end
18
+
19
+ def chown_provisioning_folder
20
+ vm.ssh.execute do |ssh|
21
+ ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}")
22
+ ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}")
23
+ end
24
+ end
25
+
26
+ def setup_config(template, filename, template_vars)
27
+ config_file = TemplateRenderer.render(template, {
28
+ :log_level => env.config.chef.log_level.to_sym
29
+ }.merge(template_vars))
30
+
31
+ vm.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename))
32
+ end
33
+
34
+ def setup_json
35
+ env.ui.info I18n.t("vagrant.provisioners.chef.json")
36
+
37
+ # Set up initial configuration
38
+ data = {
39
+ :config => env.config.to_hash,
40
+ :directory => env.config.vm.shared_folders["v-root"][:guestpath],
41
+ }
42
+
43
+ # And wrap it under the "vagrant" namespace
44
+ data = { :vagrant => data }
45
+
46
+ # Merge with the "extra data" which isn't put under the
47
+ # vagrant namespace by default
48
+ data.merge!(env.config.chef.json)
49
+
50
+ json = data.to_json
51
+
52
+ vm.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json"))
53
+ end
54
+ end
55
+
56
+ class Chef < Base
57
+ class ChefError < Errors::VagrantError
58
+ error_namespace("vagrant.provisioners.chef")
59
+ end
60
+ end
61
+
6
62
  class Chef < Base
7
63
  # This is the configuration which is available through `config.chef`
8
64
  class ChefConfig < Vagrant::Config::Base
65
+ configures :chef
66
+
9
67
  # Chef server specific config
10
68
  attr_accessor :chef_server_url
11
69
  attr_accessor :validation_key_path
@@ -34,7 +92,7 @@ module Vagrant
34
92
  @log_level = :info
35
93
  @json = {
36
94
  :instance_role => "vagrant",
37
- :run_list => ["recipe[vagrant_main]"]
95
+ :run_list => []
38
96
  }
39
97
  end
40
98
 
@@ -60,67 +118,14 @@ module Vagrant
60
118
  run_list << name
61
119
  end
62
120
 
63
- def to_json(*a)
121
+ def instance_variables_hash
64
122
  # Overridden so that the 'json' key could be removed, since its just
65
123
  # merged into the config anyways
66
- data = instance_variables_hash
67
- data.delete(:json)
68
- data.to_json(*a)
69
- end
70
- end
71
-
72
- # Tell the Vagrant configure class about our custom configuration
73
- Config.configures :chef, ChefConfig
74
-
75
- def prepare
76
- action_env.error!(:chef_base_invalid_provisioner)
77
- end
78
-
79
- def verify_binary(binary)
80
- vm.ssh.execute do |ssh|
81
- # Checks for the existence of chef binary and error if it
82
- # doesn't exist.
83
- ssh.exec!("which #{binary}", :error_key => :chef_not_detected, :error_data => {:binary => binary})
84
- end
85
- end
86
-
87
- def chown_provisioning_folder
88
- logger.info "Setting permissions on chef provisioning folder..."
89
- vm.ssh.execute do |ssh|
90
- ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}")
91
- ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}")
124
+ result = super
125
+ result.delete("json")
126
+ result
92
127
  end
93
128
  end
94
-
95
- def setup_config(template, filename, template_vars)
96
- config_file = TemplateRenderer.render(template, {
97
- :log_level => env.config.chef.log_level.to_sym
98
- }.merge(template_vars))
99
-
100
- logger.info "Uploading chef configuration script..."
101
- vm.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename))
102
- end
103
-
104
- def setup_json
105
- logger.info "Generating chef JSON and uploading..."
106
-
107
- # Set up initial configuration
108
- data = {
109
- :config => env.config,
110
- :directory => env.config.vm.shared_folders["v-root"][:guestpath],
111
- }
112
-
113
- # And wrap it under the "vagrant" namespace
114
- data = { :vagrant => data }
115
-
116
- # Merge with the "extra data" which isn't put under the
117
- # vagrant namespace by default
118
- data.merge!(env.config.chef.json)
119
-
120
- json = data.to_json
121
-
122
- vm.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json"))
123
- end
124
129
  end
125
130
  end
126
131
  end