vagrant 0.8.10 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. data/CHANGELOG.md +77 -1
  2. data/Gemfile +0 -14
  3. data/LICENSE +1 -1
  4. data/bin/vagrant +47 -20
  5. data/config/default.rb +6 -14
  6. data/lib/vagrant.rb +132 -5
  7. data/lib/vagrant/action.rb +45 -123
  8. data/lib/vagrant/action/box/destroy.rb +7 -3
  9. data/lib/vagrant/action/box/download.rb +8 -8
  10. data/lib/vagrant/action/box/package.rb +2 -2
  11. data/lib/vagrant/action/box/unpackage.rb +13 -7
  12. data/lib/vagrant/action/box/verify.rb +5 -5
  13. data/lib/vagrant/action/builder.rb +23 -19
  14. data/lib/vagrant/action/builtin.rb +117 -79
  15. data/lib/vagrant/action/env/set.rb +7 -4
  16. data/lib/vagrant/action/environment.rb +3 -41
  17. data/lib/vagrant/action/general/package.rb +14 -29
  18. data/lib/vagrant/action/general/validate.rb +2 -2
  19. data/lib/vagrant/action/runner.rb +53 -0
  20. data/lib/vagrant/action/vm/boot.rb +9 -9
  21. data/lib/vagrant/action/vm/check_accessible.rb +2 -2
  22. data/lib/vagrant/action/vm/check_box.rb +10 -12
  23. data/lib/vagrant/action/vm/check_guest_additions.rb +8 -8
  24. data/lib/vagrant/action/vm/check_port_collisions.rb +85 -0
  25. data/lib/vagrant/action/vm/clean_machine_folder.rb +4 -4
  26. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +3 -11
  27. data/lib/vagrant/action/vm/clear_network_interfaces.rb +31 -0
  28. data/lib/vagrant/action/vm/clear_shared_folders.rb +2 -11
  29. data/lib/vagrant/action/vm/customize.rb +19 -9
  30. data/lib/vagrant/action/vm/destroy.rb +4 -4
  31. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +2 -12
  32. data/lib/vagrant/action/vm/discard_state.rb +4 -4
  33. data/lib/vagrant/action/vm/export.rb +13 -8
  34. data/lib/vagrant/action/vm/forward_ports.rb +55 -102
  35. data/lib/vagrant/action/vm/halt.rb +9 -6
  36. data/lib/vagrant/action/vm/host_name.rb +4 -4
  37. data/lib/vagrant/action/vm/import.rb +19 -10
  38. data/lib/vagrant/action/vm/match_mac_address.rb +4 -9
  39. data/lib/vagrant/action/vm/network.rb +300 -94
  40. data/lib/vagrant/action/vm/nfs.rb +41 -26
  41. data/lib/vagrant/action/vm/package.rb +1 -1
  42. data/lib/vagrant/action/vm/package_vagrantfile.rb +5 -2
  43. data/lib/vagrant/action/vm/provision.rb +42 -13
  44. data/lib/vagrant/action/vm/provisioner_cleanup.rb +2 -2
  45. data/lib/vagrant/action/vm/{clear_nfs_exports.rb → prune_nfs_exports.rb} +7 -7
  46. data/lib/vagrant/action/vm/resume.rb +4 -4
  47. data/lib/vagrant/action/vm/setup_package_files.rb +54 -0
  48. data/lib/vagrant/action/vm/share_folders.rb +63 -39
  49. data/lib/vagrant/action/vm/suspend.rb +4 -4
  50. data/lib/vagrant/action/warden.rb +13 -6
  51. data/lib/vagrant/box.rb +9 -55
  52. data/lib/vagrant/box_collection.rb +22 -17
  53. data/lib/vagrant/cli.rb +62 -47
  54. data/lib/vagrant/command.rb +18 -20
  55. data/lib/vagrant/command/base.rb +135 -90
  56. data/lib/vagrant/command/box.rb +46 -21
  57. data/lib/vagrant/command/box_add.rb +33 -0
  58. data/lib/vagrant/command/box_list.rb +25 -0
  59. data/lib/vagrant/command/box_remove.rb +23 -0
  60. data/lib/vagrant/command/box_repackage.rb +23 -0
  61. data/lib/vagrant/command/destroy.rb +16 -5
  62. data/lib/vagrant/command/halt.rb +25 -7
  63. data/lib/vagrant/command/init.rb +30 -7
  64. data/lib/vagrant/command/package.rb +49 -18
  65. data/lib/vagrant/command/provision.rb +22 -9
  66. data/lib/vagrant/command/reload.rb +18 -5
  67. data/lib/vagrant/command/resume.rb +18 -5
  68. data/lib/vagrant/command/ssh.rb +69 -31
  69. data/lib/vagrant/command/ssh_config.rb +37 -22
  70. data/lib/vagrant/command/status.rb +22 -20
  71. data/lib/vagrant/command/suspend.rb +18 -5
  72. data/lib/vagrant/command/up.rb +41 -8
  73. data/lib/vagrant/communication.rb +7 -0
  74. data/lib/vagrant/communication/base.rb +56 -0
  75. data/lib/vagrant/communication/ssh.rb +200 -0
  76. data/lib/vagrant/config.rb +29 -103
  77. data/lib/vagrant/config/base.rb +18 -26
  78. data/lib/vagrant/config/container.rb +37 -0
  79. data/lib/vagrant/config/error_recorder.rb +1 -1
  80. data/lib/vagrant/config/loader.rb +125 -0
  81. data/lib/vagrant/config/nfs.rb +1 -3
  82. data/lib/vagrant/config/package.rb +1 -3
  83. data/lib/vagrant/config/ssh.rb +31 -16
  84. data/lib/vagrant/config/top.rb +36 -25
  85. data/lib/vagrant/config/vagrant.rb +2 -5
  86. data/lib/vagrant/config/vm.rb +115 -56
  87. data/lib/vagrant/config/vm/provisioner.rb +16 -20
  88. data/lib/vagrant/config/vm/sub_vm.rb +1 -1
  89. data/lib/vagrant/data_store.rb +23 -15
  90. data/lib/vagrant/downloaders/base.rb +7 -5
  91. data/lib/vagrant/downloaders/file.rb +4 -4
  92. data/lib/vagrant/downloaders/http.rb +4 -5
  93. data/lib/vagrant/driver.rb +7 -0
  94. data/lib/vagrant/driver/virtualbox.rb +121 -0
  95. data/lib/vagrant/driver/virtualbox_4_0.rb +411 -0
  96. data/lib/vagrant/driver/virtualbox_4_1.rb +411 -0
  97. data/lib/vagrant/driver/virtualbox_base.rb +284 -0
  98. data/lib/vagrant/environment.rb +221 -240
  99. data/lib/vagrant/errors.rb +74 -25
  100. data/lib/vagrant/guest.rb +16 -0
  101. data/lib/vagrant/guest/arch.rb +48 -0
  102. data/lib/vagrant/{systems → guest}/base.rb +30 -18
  103. data/lib/vagrant/guest/debian.rb +61 -0
  104. data/lib/vagrant/{systems → guest}/freebsd.rb +11 -18
  105. data/lib/vagrant/guest/gentoo.rb +32 -0
  106. data/lib/vagrant/guest/linux.rb +78 -0
  107. data/lib/vagrant/{systems → guest}/linux/config.rb +2 -4
  108. data/lib/vagrant/guest/linux/error.rb +9 -0
  109. data/lib/vagrant/guest/redhat.rb +66 -0
  110. data/lib/vagrant/guest/solaris.rb +114 -0
  111. data/lib/vagrant/{systems → guest}/suse.rb +2 -2
  112. data/lib/vagrant/guest/ubuntu.rb +23 -0
  113. data/lib/vagrant/hosts.rb +23 -6
  114. data/lib/vagrant/hosts/arch.rb +7 -3
  115. data/lib/vagrant/hosts/base.rb +36 -46
  116. data/lib/vagrant/hosts/bsd.rb +53 -16
  117. data/lib/vagrant/hosts/fedora.rb +14 -0
  118. data/lib/vagrant/hosts/freebsd.rb +6 -36
  119. data/lib/vagrant/hosts/linux.rb +45 -20
  120. data/lib/vagrant/hosts/windows.rb +16 -0
  121. data/lib/vagrant/provisioners.rb +10 -7
  122. data/lib/vagrant/provisioners/base.rb +11 -34
  123. data/lib/vagrant/provisioners/chef.rb +30 -26
  124. data/lib/vagrant/provisioners/chef_client.rb +37 -23
  125. data/lib/vagrant/provisioners/chef_solo.rb +61 -16
  126. data/lib/vagrant/provisioners/puppet.rb +70 -38
  127. data/lib/vagrant/provisioners/puppet_server.rb +12 -13
  128. data/lib/vagrant/provisioners/shell.rb +24 -24
  129. data/lib/vagrant/registry.rb +49 -0
  130. data/lib/vagrant/ssh.rb +82 -153
  131. data/lib/vagrant/ui.rb +118 -50
  132. data/lib/vagrant/util/busy.rb +1 -1
  133. data/lib/vagrant/util/file_mode.rb +12 -0
  134. data/lib/vagrant/util/network_ip.rb +28 -0
  135. data/lib/vagrant/util/platform.rb +1 -0
  136. data/lib/vagrant/util/subprocess.rb +227 -0
  137. data/lib/vagrant/version.rb +1 -1
  138. data/lib/vagrant/vm.rb +111 -97
  139. data/tasks/acceptance.rake +3 -3
  140. data/tasks/test.rake +7 -2
  141. data/templates/commands/init/Vagrantfile.erb +11 -4
  142. data/templates/{ssh_config.erb → commands/ssh_config/config.erb} +0 -0
  143. data/templates/guests/arch/network_dhcp.erb +7 -0
  144. data/templates/guests/arch/network_static.erb +7 -0
  145. data/templates/guests/debian/network_dhcp.erb +6 -0
  146. data/templates/guests/debian/network_static.erb +7 -0
  147. data/templates/guests/gentoo/network_dhcp.erb +4 -0
  148. data/templates/guests/gentoo/network_static.erb +4 -0
  149. data/templates/guests/redhat/network_dhcp.erb +6 -0
  150. data/templates/guests/redhat/network_static.erb +7 -0
  151. data/templates/locales/en.yml +241 -122
  152. data/templates/{chef_server_client.erb → provisioners/chef_client/client.erb} +0 -0
  153. data/templates/{chef_solo_solo.erb → provisioners/chef_solo/solo.erb} +0 -0
  154. data/test/acceptance/base.rb +10 -10
  155. data/test/acceptance/box_test.rb +28 -6
  156. data/test/acceptance/destroy_test.rb +1 -1
  157. data/test/acceptance/halt_test.rb +4 -4
  158. data/test/acceptance/init_test.rb +3 -3
  159. data/test/acceptance/networking/host_only_test.rb +37 -0
  160. data/test/acceptance/networking/port_forward_test.rb +125 -0
  161. data/test/acceptance/package_test.rb +46 -0
  162. data/test/acceptance/provisioning/basic_test.rb +61 -0
  163. data/test/acceptance/provisioning/chef_solo_test.rb +37 -0
  164. data/test/acceptance/provisioning/shell_test.rb +53 -0
  165. data/test/acceptance/resume_test.rb +1 -1
  166. data/test/acceptance/skeletons/chef_solo_basic/README.md +3 -0
  167. data/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb +5 -0
  168. data/test/acceptance/skeletons/chef_solo_json/README.md +3 -0
  169. data/test/acceptance/skeletons/chef_solo_json/cookbooks/basic/recipes/default.rb +6 -0
  170. data/test/acceptance/skeletons/provisioner_multi/README.md +3 -0
  171. data/test/acceptance/skeletons/provisioner_multi/cookbooks/basic/recipes/default.rb +5 -0
  172. data/test/acceptance/ssh_test.rb +7 -2
  173. data/test/acceptance/support/config.rb +1 -1
  174. data/test/acceptance/support/isolated_environment.rb +41 -150
  175. data/test/acceptance/support/matchers/match_output.rb +1 -1
  176. data/test/acceptance/support/matchers/succeed.rb +14 -0
  177. data/test/acceptance/support/network_tests.rb +29 -0
  178. data/test/acceptance/support/output.rb +9 -1
  179. data/test/acceptance/support/shared/base_context.rb +16 -9
  180. data/test/acceptance/support/shared/command_examples.rb +4 -4
  181. data/test/acceptance/suspend_test.rb +1 -1
  182. data/test/acceptance/up_basic_test.rb +26 -7
  183. data/test/acceptance/up_with_box_url.rb +1 -1
  184. data/test/acceptance/vagrant_test.rb +1 -1
  185. data/test/acceptance/version_test.rb +0 -5
  186. data/test/support/isolated_environment.rb +46 -0
  187. data/test/{acceptance/support → support}/tempdir.rb +0 -0
  188. data/test/unit/base.rb +21 -0
  189. data/test/unit/support/isolated_environment.rb +39 -0
  190. data/test/unit/support/shared/base_context.rb +30 -0
  191. data/test/unit/vagrant/action/builder_test.rb +126 -177
  192. data/test/unit/vagrant/action/environment_test.rb +10 -21
  193. data/test/unit/vagrant/action/runner_test.rb +65 -0
  194. data/test/unit/vagrant/action/warden_test.rb +64 -97
  195. data/test/unit/vagrant/box_collection_test.rb +44 -33
  196. data/test/unit/vagrant/box_test.rb +25 -65
  197. data/test/unit/vagrant/command/base_test.rb +141 -14
  198. data/test/unit/vagrant/config/base_test.rb +16 -43
  199. data/test/unit/vagrant/config/loader_test.rb +79 -0
  200. data/test/unit/vagrant/config/top_test.rb +69 -0
  201. data/test/unit/vagrant/config/vm_test.rb +62 -47
  202. data/test/unit/vagrant/config_test.rb +16 -151
  203. data/test/unit/vagrant/data_store_test.rb +43 -61
  204. data/test/unit/vagrant/downloaders/base_test.rb +12 -22
  205. data/test/unit/vagrant/downloaders/file_test.rb +58 -31
  206. data/test/unit/vagrant/downloaders/http_test.rb +12 -86
  207. data/test/unit/vagrant/environment_test.rb +107 -536
  208. data/test/unit/vagrant/hosts_test.rb +36 -0
  209. data/test/unit/vagrant/registry_test.rb +56 -0
  210. data/test/unit/vagrant/util/file_checksum_test.rb +23 -0
  211. data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +23 -24
  212. data/test/unit/vagrant/util/network_ip_test.rb +17 -0
  213. data/test/unit/vagrant/util/retryable_test.rb +90 -34
  214. data/test/unit/vagrant_test.rb +27 -0
  215. data/test/{unit → unit_legacy}/locales/en.yml +0 -0
  216. data/test/{unit → unit_legacy}/test_helper.rb +0 -0
  217. data/test/{unit → unit_legacy}/vagrant/action/box/destroy_test.rb +0 -0
  218. data/test/{unit → unit_legacy}/vagrant/action/box/download_test.rb +0 -0
  219. data/test/{unit → unit_legacy}/vagrant/action/box/package_test.rb +0 -0
  220. data/test/{unit → unit_legacy}/vagrant/action/box/unpackage_test.rb +0 -0
  221. data/test/{unit → unit_legacy}/vagrant/action/box/verify_test.rb +0 -0
  222. data/test/{unit → unit_legacy}/vagrant/action/env/set_test.rb +0 -0
  223. data/test/{unit → unit_legacy}/vagrant/action/general/package_test.rb +0 -0
  224. data/test/{unit → unit_legacy}/vagrant/action/general/validate_test.rb +0 -0
  225. data/test/{unit → unit_legacy}/vagrant/action/vm/boot_test.rb +0 -0
  226. data/test/{unit → unit_legacy}/vagrant/action/vm/check_accessible_test.rb +0 -0
  227. data/test/{unit → unit_legacy}/vagrant/action/vm/check_box_test.rb +0 -0
  228. data/test/{unit → unit_legacy}/vagrant/action/vm/check_guest_additions_test.rb +0 -0
  229. data/test/{unit → unit_legacy}/vagrant/action/vm/clean_machine_folder_test.rb +0 -0
  230. data/test/{unit → unit_legacy}/vagrant/action/vm/clear_forwarded_ports_test.rb +0 -0
  231. data/test/{unit → unit_legacy}/vagrant/action/vm/clear_nfs_exports_test.rb +0 -0
  232. data/test/{unit → unit_legacy}/vagrant/action/vm/clear_shared_folders_test.rb +0 -0
  233. data/test/{unit → unit_legacy}/vagrant/action/vm/customize_test.rb +0 -0
  234. data/test/{unit → unit_legacy}/vagrant/action/vm/destroy_test.rb +0 -0
  235. data/test/{unit → unit_legacy}/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +0 -0
  236. data/test/{unit → unit_legacy}/vagrant/action/vm/discard_state_test.rb +0 -0
  237. data/test/{unit → unit_legacy}/vagrant/action/vm/export_test.rb +0 -0
  238. data/test/{unit → unit_legacy}/vagrant/action/vm/forward_ports_helpers_test.rb +0 -0
  239. data/test/{unit → unit_legacy}/vagrant/action/vm/forward_ports_test.rb +0 -0
  240. data/test/{unit → unit_legacy}/vagrant/action/vm/halt_test.rb +0 -0
  241. data/test/{unit → unit_legacy}/vagrant/action/vm/host_name_test.rb +0 -0
  242. data/test/{unit → unit_legacy}/vagrant/action/vm/import_test.rb +0 -0
  243. data/test/{unit → unit_legacy}/vagrant/action/vm/match_mac_address_test.rb +0 -0
  244. data/test/{unit → unit_legacy}/vagrant/action/vm/modify_test.rb +0 -0
  245. data/test/{unit → unit_legacy}/vagrant/action/vm/network_test.rb +0 -0
  246. data/test/{unit → unit_legacy}/vagrant/action/vm/nfs_helpers_test.rb +0 -0
  247. data/test/{unit → unit_legacy}/vagrant/action/vm/nfs_test.rb +0 -0
  248. data/test/{unit → unit_legacy}/vagrant/action/vm/package_test.rb +0 -0
  249. data/test/{unit → unit_legacy}/vagrant/action/vm/package_vagrantfile_test.rb +0 -0
  250. data/test/{unit → unit_legacy}/vagrant/action/vm/provision_test.rb +0 -0
  251. data/test/{unit → unit_legacy}/vagrant/action/vm/provisioner_cleanup_test.rb +0 -0
  252. data/test/{unit → unit_legacy}/vagrant/action/vm/resume_test.rb +0 -0
  253. data/test/{unit → unit_legacy}/vagrant/action/vm/share_folders_test.rb +0 -0
  254. data/test/{unit → unit_legacy}/vagrant/action/vm/suspend_test.rb +0 -0
  255. data/test/{unit → unit_legacy}/vagrant/action_test.rb +0 -0
  256. data/test/unit_legacy/vagrant/box_collection_test.rb +45 -0
  257. data/test/unit_legacy/vagrant/box_test.rb +74 -0
  258. data/test/{unit → unit_legacy}/vagrant/cli_test.rb +0 -0
  259. data/test/unit_legacy/vagrant/command/base_test.rb +23 -0
  260. data/test/{unit → unit_legacy}/vagrant/command/group_base_test.rb +0 -0
  261. data/test/{unit → unit_legacy}/vagrant/command/helpers_test.rb +0 -0
  262. data/test/{unit → unit_legacy}/vagrant/command/init_test.rb +0 -0
  263. data/test/{unit → unit_legacy}/vagrant/command/package_test.rb +0 -0
  264. data/test/unit_legacy/vagrant/config/base_test.rb +52 -0
  265. data/test/{unit → unit_legacy}/vagrant/config/error_recorder_test.rb +0 -0
  266. data/test/{unit → unit_legacy}/vagrant/config/ssh_test.rb +0 -0
  267. data/test/{unit → unit_legacy}/vagrant/config/vagrant_test.rb +0 -0
  268. data/test/{unit → unit_legacy}/vagrant/config/vm/provisioner_test.rb +0 -0
  269. data/test/unit_legacy/vagrant/config/vm_test.rb +47 -0
  270. data/test/unit_legacy/vagrant/config_test.rb +148 -0
  271. data/test/unit_legacy/vagrant/downloaders/http_test.rb +93 -0
  272. data/test/unit_legacy/vagrant/environment_test.rb +539 -0
  273. data/test/{unit → unit_legacy}/vagrant/errors_test.rb +0 -0
  274. data/test/{unit → unit_legacy}/vagrant/hosts/base_test.rb +0 -0
  275. data/test/{unit → unit_legacy}/vagrant/hosts/bsd_test.rb +0 -0
  276. data/test/{unit → unit_legacy}/vagrant/hosts/linux_test.rb +0 -0
  277. data/test/{unit → unit_legacy}/vagrant/plugin_test.rb +0 -0
  278. data/test/{unit → unit_legacy}/vagrant/provisioners/base_test.rb +0 -0
  279. data/test/{unit → unit_legacy}/vagrant/provisioners/chef_client_test.rb +0 -0
  280. data/test/{unit → unit_legacy}/vagrant/provisioners/chef_solo_test.rb +0 -0
  281. data/test/{unit → unit_legacy}/vagrant/provisioners/chef_test.rb +0 -0
  282. data/test/{unit → unit_legacy}/vagrant/provisioners/puppet_server_test.rb +0 -0
  283. data/test/{unit → unit_legacy}/vagrant/provisioners/puppet_test.rb +0 -0
  284. data/test/{unit → unit_legacy}/vagrant/provisioners/shell_test.rb +0 -0
  285. data/test/{unit → unit_legacy}/vagrant/ssh/session_test.rb +0 -0
  286. data/test/{unit → unit_legacy}/vagrant/ssh_test.rb +0 -0
  287. data/test/{unit → unit_legacy}/vagrant/systems/base_test.rb +0 -0
  288. data/test/{unit → unit_legacy}/vagrant/systems/linux_test.rb +0 -0
  289. data/test/{unit → unit_legacy}/vagrant/util/busy_test.rb +0 -0
  290. data/test/{unit → unit_legacy}/vagrant/util/counter_test.rb +0 -0
  291. data/test/{unit → unit_legacy}/vagrant/util/platform_test.rb +0 -0
  292. data/test/{unit → unit_legacy}/vagrant/util/stacked_proc_runner_test.rb +0 -0
  293. data/test/{unit → unit_legacy}/vagrant/util/template_renderer_test.rb +0 -0
  294. data/test/{unit → unit_legacy}/vagrant/vm_test.rb +0 -0
  295. data/vagrant.gemspec +7 -9
  296. metadata +214 -216
  297. data/keys/vagrant.ppk +0 -26
  298. data/lib/vagrant/action/box.rb +0 -11
  299. data/lib/vagrant/action/env.rb +0 -7
  300. data/lib/vagrant/action/general.rb +0 -8
  301. data/lib/vagrant/action/vm.rb +0 -34
  302. data/lib/vagrant/action/vm/forward_ports_helpers.rb +0 -28
  303. data/lib/vagrant/action/vm/modify.rb +0 -37
  304. data/lib/vagrant/action/vm/nfs_helpers.rb +0 -11
  305. data/lib/vagrant/command/group_base.rb +0 -107
  306. data/lib/vagrant/command/helpers.rb +0 -33
  307. data/lib/vagrant/command/named_base.rb +0 -14
  308. data/lib/vagrant/command/upgrade_to_060.rb +0 -45
  309. data/lib/vagrant/command/version.rb +0 -13
  310. data/lib/vagrant/ssh/session.rb +0 -136
  311. data/lib/vagrant/systems.rb +0 -13
  312. data/lib/vagrant/systems/arch.rb +0 -34
  313. data/lib/vagrant/systems/debian.rb +0 -36
  314. data/lib/vagrant/systems/gentoo.rb +0 -27
  315. data/lib/vagrant/systems/linux.rb +0 -82
  316. data/lib/vagrant/systems/linux/error.rb +0 -9
  317. data/lib/vagrant/systems/redhat.rb +0 -48
  318. data/lib/vagrant/systems/solaris.rb +0 -113
  319. data/lib/vagrant/systems/ubuntu.rb +0 -17
  320. data/templates/network_entry_arch.erb +0 -9
  321. data/templates/network_entry_debian.erb +0 -8
  322. data/templates/network_entry_gentoo.erb +0 -5
  323. data/templates/network_entry_redhat.erb +0 -9
  324. data/test/unit/vagrant/ui_test.rb +0 -29
@@ -1,80 +1,148 @@
1
+ require "log4r"
2
+
1
3
  module Vagrant
2
- # Vagrant UIs handle communication with the outside world (typically
3
- # through a shell). They must respond to the typically logger methods
4
- # of `warn`, `error`, `info`, and `confirm`.
5
- class UI
6
- attr_accessor :env
7
-
8
- def initialize(env)
9
- @env = env
10
- end
4
+ module UI
5
+ # Vagrant UIs handle communication with the outside world (typically
6
+ # through a shell). They must respond to the following methods:
7
+ #
8
+ # * `info`
9
+ # * `warn`
10
+ # * `error`
11
+ # * `success`
12
+ class Interface
13
+ attr_accessor :resource
11
14
 
12
- [:warn, :error, :info, :confirm].each do |method|
13
- define_method(method) do |message, *opts|
14
- # Log normal console messages
15
- env.logger.info("ui") { message }
15
+ def initialize(resource)
16
+ @logger = Log4r::Logger.new("vagrant::ui::interface")
17
+ @resource = resource
16
18
  end
17
- end
18
-
19
- [:clear_line, :report_progress, :ask, :no?, :yes?].each do |method|
20
- # By default do nothing, these aren't logged
21
- define_method(method) { |*args| }
22
- end
23
19
 
24
- # A shell UI, which uses a `Thor::Shell` object to talk with
25
- # a terminal.
26
- class Shell < UI
27
- def initialize(env, shell)
28
- super(env)
20
+ [:ask, :warn, :error, :info, :success].each do |method|
21
+ define_method(method) do |message, *opts|
22
+ # Log normal console messages
23
+ @logger.info { "#{method}: #{message}" }
24
+ end
25
+ end
29
26
 
30
- @shell = shell
27
+ [:clear_line, :report_progress].each do |method|
28
+ # By default do nothing, these aren't logged
29
+ define_method(method) { |*args| }
31
30
  end
31
+ end
32
+
33
+ # This is a UI implementation that does nothing.
34
+ class Silent < Interface; end
32
35
 
33
- [[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
36
+ # This is a UI implementation that outputs the text as is. It
37
+ # doesn't add any color.
38
+ class Basic < Interface
39
+ # Use some light meta-programming to create the various methods to
40
+ # output text to the UI. These all delegate the real functionality
41
+ # to `say`.
42
+ [:info, :warn, :error, :success].each do |method|
34
43
  class_eval <<-CODE
35
- def #{method}(message, opts=nil)
44
+ def #{method}(message, *args)
36
45
  super(message)
37
- opts ||= {}
38
- opts[:new_line] = true if !opts.has_key?(:new_line)
39
- @shell.say("\#{format_message(message, opts)}", #{color.inspect}, opts[:new_line])
46
+ say(#{method.inspect}, message, *args)
40
47
  end
41
48
  CODE
42
49
  end
43
50
 
44
- [:ask, :no?, :yes?].each do |method|
45
- class_eval <<-CODE
46
- def #{method}(message, opts=nil)
47
- super(message)
48
- opts ||= {}
49
- @shell.send(#{method.inspect}, format_message(message, opts), opts[:color])
50
- end
51
- CODE
51
+ def ask(message, opts=nil)
52
+ super(message)
53
+
54
+ # Setup the options so that the new line is suppressed
55
+ opts ||= {}
56
+ opts[:new_line] = false if !opts.has_key?(:new_line)
57
+ opts[:prefix] = false if !opts.has_key?(:prefix)
58
+
59
+ # Output the data
60
+ say(:info, message, opts)
61
+
62
+ # Get the results and chomp off the newline
63
+ STDIN.gets.chomp
52
64
  end
53
65
 
66
+ # This is used to output progress reports to the UI.
67
+ # Send this method progress/total and it will output it
68
+ # to the UI. Send `clear_line` to clear the line to show
69
+ # a continuous progress meter.
54
70
  def report_progress(progress, total, show_parts=true)
55
71
  percent = (progress.to_f / total.to_f) * 100
56
- line = "Progress: #{percent.to_i}%"
57
- line << " (#{progress} / #{total})" if show_parts
72
+ line = "Progress: #{percent.to_i}%"
73
+ line << " (#{progress} / #{total})" if show_parts
58
74
 
59
- @shell.say(line, nil, false)
75
+ info(line, :new_line => false)
60
76
  end
61
77
 
62
78
  def clear_line
63
- @shell.say(line_reset, nil, false)
79
+ reset = "\r"
80
+ reset += "\e[0K" unless Util::Platform.windows?
81
+ reset
82
+
83
+ info(reset, :new_line => false)
64
84
  end
65
85
 
66
- protected
86
+ # This method handles actually outputting a message of a given type
87
+ # to the console.
88
+ def say(type, message, opts=nil)
89
+ defaults = { :new_line => true, :prefix => true }
90
+ opts = defaults.merge(opts || {})
91
+
92
+ # Determine whether we're expecting to output our
93
+ # own new line or not.
94
+ printer = opts[:new_line] ? :puts : :print
67
95
 
68
- def format_message(message, opts=nil)
69
- opts = { :prefix => true }.merge(opts || {})
70
- message = "[#{env.resource}] #{message}" if opts[:prefix]
96
+ # Determine the proper IO channel to send this message
97
+ # to based on the type of the message
98
+ channel = type == :error || opts[:channel] == :error ? $stderr : $stdout
99
+
100
+ # Output!
101
+ channel.send(printer, format_message(type, message, opts))
102
+ end
103
+
104
+ # This is called by `say` to format the message for output.
105
+ def format_message(type, message, opts=nil)
106
+ opts ||= {}
107
+ message = "[#{@resource}] #{message}" if opts[:prefix]
71
108
  message
72
109
  end
110
+ end
73
111
 
74
- def line_reset
75
- reset = "\r"
76
- reset += "\e[0K" unless Util::Platform.windows?
77
- reset
112
+ # This is a UI implementation that outputs color for various types
113
+ # of messages. This should only be used with a TTY that supports color,
114
+ # but is up to the user of the class to verify this is the case.
115
+ class Colored < Basic
116
+ # Terminal colors
117
+ COLORS = {
118
+ :clear => "\e[0m",
119
+ :red => "\e[31m",
120
+ :green => "\e[32m",
121
+ :yellow => "\e[33m"
122
+ }
123
+
124
+ # Mapping between type of message and the color to output
125
+ COLOR_MAP = {
126
+ :warn => COLORS[:yellow],
127
+ :error => COLORS[:red],
128
+ :success => COLORS[:green]
129
+ }
130
+
131
+ # This is called by `say` to format the message for output.
132
+ def format_message(type, message, opts=nil)
133
+ # Get the format of the message before adding color.
134
+ message = super
135
+
136
+ # Colorize the message if there is a color for this type of message,
137
+ # either specified by the options or via the default color map.
138
+ if opts.has_key?(:color)
139
+ color = COLORS[opts[:color]]
140
+ message = "#{color}#{message}#{COLORS[:clear]}"
141
+ else
142
+ message = "#{COLOR_MAP[type]}#{message}#{COLORS[:clear]}" if COLOR_MAP[type]
143
+ end
144
+
145
+ message
78
146
  end
79
147
  end
80
148
  end
@@ -46,7 +46,7 @@ module Vagrant
46
46
 
47
47
  # Fires all the registered callbacks.
48
48
  def fire_callbacks
49
- registered.each { |r| r.call }
49
+ registered.reverse.each { |r| r.call }
50
50
  end
51
51
 
52
52
  # Helper method to get access to the class variable. This is mostly
@@ -0,0 +1,12 @@
1
+ module Vagrant
2
+ module Util
3
+ class FileMode
4
+ # This returns the file permissions as a string from
5
+ # an octal number.
6
+ def self.from_octal(octal)
7
+ perms = sprintf("%o", octal)
8
+ perms.reverse[0..2].reverse
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module Vagrant
2
+ module Util
3
+ module NetworkIP
4
+ # Returns the network address of the given IP and subnet.
5
+ #
6
+ # @return [String]
7
+ def network_address(ip, subnet)
8
+ ip = ip_parts(ip)
9
+ netmask = ip_parts(subnet)
10
+
11
+ # Bitwise-AND each octet to get the network address
12
+ # in octets and join each part with a period to get
13
+ # the resulting network address.
14
+ ip.map { |part| part & netmask.shift }.join(".")
15
+ end
16
+
17
+ protected
18
+
19
+ # Splits an IP into the four octets and returns each as an
20
+ # integer in an array.
21
+ #
22
+ # @return [Array<Integer>]
23
+ def ip_parts(ip)
24
+ ip.split(".").map { |i| i.to_i }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rbconfig'
2
+ require 'tempfile'
2
3
 
3
4
  module Vagrant
4
5
  module Util
@@ -0,0 +1,227 @@
1
+ require 'childprocess'
2
+ require 'log4r'
3
+
4
+ require 'vagrant/util/platform'
5
+
6
+ module Vagrant
7
+ module Util
8
+ # Execute a command in a subprocess, gathering the results and
9
+ # exit status.
10
+ #
11
+ # This class also allows you to read the data as it is outputted
12
+ # from the subprocess in real time, by simply passing a block to
13
+ # the execute method.
14
+ class Subprocess
15
+ # The chunk size for reading from subprocess IO.
16
+ READ_CHUNK_SIZE = 4096
17
+
18
+ # Convenience method for executing a method.
19
+ def self.execute(*command, &block)
20
+ new(*command).execute(&block)
21
+ end
22
+
23
+ def initialize(*command)
24
+ @options = command.last.is_a?(Hash) ? command.pop : {}
25
+ @command = command
26
+ @logger = Log4r::Logger.new("vagrant::util::subprocess")
27
+ end
28
+
29
+ def execute
30
+ # Get the timeout, if we have one
31
+ timeout = @options[:timeout]
32
+ workdir = @options[:workdir] || Dir.pwd
33
+
34
+ # Build the ChildProcess
35
+ @logger.info("Starting process: #{@command.inspect}")
36
+ process = ChildProcess.build(*@command)
37
+
38
+ # Create the pipes so we can read the output in real time as
39
+ # we execute the command.
40
+ stdout, stdout_writer = IO.pipe
41
+ stderr, stderr_writer = IO.pipe
42
+ process.io.stdout = stdout_writer
43
+ process.io.stderr = stderr_writer
44
+ process.duplex = true
45
+
46
+ # Set the environment on the process if we must
47
+ if @options[:env]
48
+ @options[:env].each do |k, v|
49
+ process.environment[k] = v
50
+ end
51
+ end
52
+
53
+ # Start the process
54
+ begin
55
+ Dir.chdir(workdir) do
56
+ process.start
57
+ end
58
+ rescue ChildProcess::LaunchError
59
+ # Raise our own version of the error so that users of the class
60
+ # don't need to be aware of ChildProcess
61
+ raise LaunchError
62
+ end
63
+
64
+ # Make sure the stdin does not buffer
65
+ process.io.stdin.sync = true
66
+
67
+ # Close the writer pipes, since we're just reading
68
+ stdout_writer.close
69
+ stderr_writer.close
70
+
71
+ # Create a dictionary to store all the output we see.
72
+ io_data = { stdout => "", stderr => "" }
73
+
74
+ # Record the start time for timeout purposes
75
+ start_time = Time.now.to_i
76
+
77
+ @logger.debug("Selecting on IO")
78
+ while true
79
+ results = IO.select([stdout, stderr], [process.io.stdin], nil, timeout || 5)
80
+ readers, writers = results
81
+
82
+ # Check if we have exceeded our timeout
83
+ raise TimeoutExceeded, process.pid if timeout && (Time.now.to_i - start_time) > timeout
84
+
85
+ # Check the readers to see if they're ready
86
+ if !readers.empty?
87
+ readers.each do |r|
88
+ # Read from the IO object
89
+ data = read_io(r)
90
+
91
+ # We don't need to do anything if the data is empty
92
+ next if data.empty?
93
+
94
+ io_name = r == stdout ? :stdout : :stderr
95
+ @logger.debug("#{io_name}: #{data}")
96
+
97
+ io_data[r] += data
98
+ yield io_name, data if block_given?
99
+ end
100
+ end
101
+
102
+ # Break out if the process exited. We have to do this before
103
+ # attempting to write to stdin otherwise we'll get a broken pipe
104
+ # error.
105
+ break if process.exited?
106
+
107
+ # Check the writers to see if they're ready, and notify any listeners
108
+ if !writers.empty?
109
+ yield :stdin, process.io.stdin if block_given?
110
+ end
111
+ end
112
+
113
+ # Wait for the process to end.
114
+ begin
115
+ remaining = (timeout || 32000) - (Time.now.to_i - start_time)
116
+ remaining = 0 if remaining < 0
117
+ @logger.debug("Waiting for process to exit. Remaining to timeout: #{remaining}")
118
+
119
+ process.poll_for_exit(remaining)
120
+ rescue ChildProcess::TimeoutError
121
+ raise TimeoutExceeded, process.pid
122
+ end
123
+
124
+ @logger.debug("Exit status: #{process.exit_code}")
125
+
126
+ # Read the final output data, since it is possible we missed a small
127
+ # amount of text between the time we last read data and when the
128
+ # process exited.
129
+ [stdout, stderr].each do |io|
130
+ # Read the extra data, ignoring if there isn't any
131
+ extra_data = read_io(io)
132
+ next if extra_data == ""
133
+
134
+ # Log it out and accumulate
135
+ @logger.debug(extra_data)
136
+ io_data[io] += extra_data
137
+
138
+ # Yield to any listeners any remaining data
139
+ io_name = io == stdout ? :stdout : :stderr
140
+ yield io_name, extra_data if block_given?
141
+ end
142
+
143
+ # Return an exit status container
144
+ return Result.new(process.exit_code, io_data[stdout], io_data[stderr])
145
+ end
146
+
147
+ protected
148
+
149
+ # Reads data from an IO object while it can, returning the data it reads.
150
+ # When it encounters a case when it can't read anymore, it returns the
151
+ # data.
152
+ #
153
+ # @return [String]
154
+ def read_io(io)
155
+ data = ""
156
+
157
+ while true
158
+ begin
159
+ if Platform.windows?
160
+ # Windows doesn't support non-blocking reads on
161
+ # file descriptors or pipes so we have to get
162
+ # a bit more creative.
163
+ data << io.readpartial(READ_CHUNK_SIZE)
164
+ else
165
+ # Do a simple non-blocking read on the IO object
166
+ data << io.read_nonblock(READ_CHUNK_SIZE)
167
+ end
168
+ rescue Exception => e
169
+ # The catch-all rescue here is to support multiple Ruby versions,
170
+ # since we use some Ruby 1.9 specific exceptions.
171
+
172
+ breakable = false
173
+ if e.is_a?(EOFError)
174
+ # An `EOFError` means this IO object is done!
175
+ breakable = true
176
+ elsif defined?(IO::WaitReadable) && e.is_a?(IO::WaitReadable)
177
+ # IO::WaitReadable is only available on Ruby 1.9+
178
+
179
+ # An IO::WaitReadable means there may be more IO but this
180
+ # IO object is not ready to be read from yet. No problem,
181
+ # we read as much as we can, so we break.
182
+ breakable = true
183
+ elsif e.is_a?(Errno::EAGAIN)
184
+ # Otherwise, we just look for the EAGAIN error which should be
185
+ # all that IO::WaitReadable does in Ruby 1.9.
186
+ breakable = true
187
+ end
188
+
189
+ # Break out if we're supposed to. Otherwise re-raise the error
190
+ # because it is a real problem.
191
+ break if breakable
192
+ raise
193
+ end
194
+ end
195
+
196
+ data
197
+ end
198
+
199
+ # An error which raises when a process fails to start
200
+ class LaunchError < StandardError; end
201
+
202
+ # An error which occurs when the process doesn't end within
203
+ # the given timeout.
204
+ class TimeoutExceeded < StandardError
205
+ attr_reader :pid
206
+
207
+ def initialize(pid)
208
+ super()
209
+ @pid = pid
210
+ end
211
+ end
212
+
213
+ # Container class to store the results of executing a subprocess.
214
+ class Result
215
+ attr_reader :exit_code
216
+ attr_reader :stdout
217
+ attr_reader :stderr
218
+
219
+ def initialize(exit_code, stdout, stderr)
220
+ @exit_code = exit_code
221
+ @stdout = stdout
222
+ @stderr = stderr
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end