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
@@ -5,8 +5,6 @@ module Vagrant
5
5
  end
6
6
 
7
7
  class PuppetServer < Base
8
- register :puppet_server
9
-
10
8
  class Config < Vagrant::Config::Base
11
9
  attr_accessor :puppet_server
12
10
  attr_accessor :puppet_node
@@ -19,15 +17,20 @@ module Vagrant
19
17
  end
20
18
  end
21
19
 
20
+ def self.config_class
21
+ Config
22
+ end
23
+
22
24
  def provision!
23
25
  verify_binary("puppetd")
24
26
  run_puppetd_client
25
27
  end
26
28
 
27
29
  def verify_binary(binary)
28
- vm.ssh.execute do |ssh|
29
- ssh.sudo!("which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary)
30
- end
30
+ env[:vm].channel.sudo("which #{binary}",
31
+ :error_class => PuppetServerError,
32
+ :error_key => :puppetd_not_detected,
33
+ :binary => binary)
31
34
  end
32
35
 
33
36
  def run_puppetd_client
@@ -36,18 +39,14 @@ module Vagrant
36
39
  if config.puppet_node
37
40
  cn = config.puppet_node
38
41
  else
39
- cn = env.config.vm.box
42
+ cn = env[:vm].config.vm.box
40
43
  end
41
44
 
42
- commands = "puppetd #{options} --server #{config.puppet_server} --certname #{cn}"
45
+ command = "puppetd #{options} --server #{config.puppet_server} --certname #{cn}"
43
46
 
44
47
  env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd")
45
-
46
- vm.ssh.execute do |ssh|
47
- ssh.sudo!(commands) do |channel, type, data|
48
- ssh.check_exit_status(data, commands) if type == :exit_status
49
- env.ui.info(data) if type != :exit_status
50
- end
48
+ env[:vm].channel.sudo(command) do |type, data|
49
+ env.ui.info(data)
51
50
  end
52
51
  end
53
52
  end
@@ -1,8 +1,8 @@
1
+ require 'tempfile'
2
+
1
3
  module Vagrant
2
4
  module Provisioners
3
5
  class Shell < Base
4
- register :shell
5
-
6
6
  class Config < Vagrant::Config::Base
7
7
  attr_accessor :inline
8
8
  attr_accessor :path
@@ -10,19 +10,10 @@ module Vagrant
10
10
  attr_accessor :args
11
11
 
12
12
  def initialize
13
- @inline = nil
14
- @path = nil
15
13
  @upload_path = "/tmp/vagrant-shell"
16
- @args = nil
17
14
  end
18
15
 
19
- def expanded_path
20
- Pathname.new(path).expand_path(env.root_path) if path
21
- end
22
-
23
- def validate(errors)
24
- super
25
-
16
+ def validate(env, errors)
26
17
  # Validate that the parameters are properly set
27
18
  if path && inline
28
19
  errors.add(I18n.t("vagrant.provisioners.shell.path_and_inline_set"))
@@ -31,8 +22,12 @@ module Vagrant
31
22
  end
32
23
 
33
24
  # Validate the existence of a script to upload
34
- if path && !expanded_path.file?
35
- errors.add(I18n.t("vagrant.provisioners.shell.path_invalid", :path => expanded_path))
25
+ if path
26
+ expanded_path = Pathname.new(path).expand_path(env.root_path)
27
+ if !expanded_path.file?
28
+ errors.add(I18n.t("vagrant.provisioners.shell.path_invalid",
29
+ :path => expanded_path))
30
+ end
36
31
  end
37
32
 
38
33
  # There needs to be a path to upload the script to
@@ -47,13 +42,17 @@ module Vagrant
47
42
  end
48
43
  end
49
44
 
45
+ def self.config_class
46
+ Config
47
+ end
48
+
50
49
  # This method yields the path to a script to upload and execute
51
50
  # on the remote server. This method will properly clean up the
52
51
  # script file if needed.
53
52
  def with_script_file
54
53
  if config.path
55
54
  # Just yield the path to that file...
56
- yield config.expanded_path
55
+ yield Pathname.new(config.path).expand_path(env[:root_path])
57
56
  return
58
57
  end
59
58
 
@@ -73,20 +72,21 @@ module Vagrant
73
72
  def provision!
74
73
  args = ""
75
74
  args = " #{config.args}" if config.args
76
- commands = ["chmod +x #{config.upload_path}", "#{config.upload_path}#{args}"]
75
+ command = "chmod +x #{config.upload_path} && #{config.upload_path}#{args}"
77
76
 
78
77
  with_script_file do |path|
79
78
  # Upload the script to the VM
80
- vm.ssh.upload!(path.to_s, config.upload_path)
79
+ env[:vm].channel.upload(path.to_s, config.upload_path)
81
80
 
82
81
  # Execute it with sudo
83
- vm.ssh.execute do |ssh|
84
- ssh.sudo!(commands) do |ch, type, data|
85
- if type == :exit_status
86
- ssh.check_exit_status(data, commands)
87
- else
88
- env.ui.info(data)
89
- end
82
+ env[:vm].channel.sudo(command) do |type, data|
83
+ if [:stderr, :stdout].include?(type)
84
+ # Output the data with the proper color based on the stream.
85
+ color = type == :stdout ? :green : :red
86
+
87
+ # Note: Be sure to chomp the data to avoid the newlines that the
88
+ # Chef outputs.
89
+ env[:ui].info(data.chomp, :color => color, :prefix => false)
90
90
  end
91
91
  end
92
92
  end
@@ -0,0 +1,49 @@
1
+ module Vagrant
2
+ # Register components in a single location that can be queried.
3
+ #
4
+ # This allows certain components (such as guest systems, configuration
5
+ # pieces, etc.) to be registered and queried.
6
+ class Registry
7
+ def initialize
8
+ @actions = {}
9
+ end
10
+
11
+ # Register a callable by key.
12
+ #
13
+ # The callable should be given in a block which will be lazily evaluated
14
+ # when the action is needed.
15
+ #
16
+ # If an action by the given name already exists then it will be
17
+ # overwritten.
18
+ def register(key, value=nil, &block)
19
+ block = lambda { value } if value
20
+ @actions[key] = block
21
+ end
22
+
23
+ # Get an action by the given key.
24
+ #
25
+ # This will evaluate the block given to `register` and return the resulting
26
+ # action stack.
27
+ def get(key)
28
+ return nil if !@actions.has_key?(key)
29
+ @actions[key].call
30
+ end
31
+
32
+ # Iterate over the keyspace.
33
+ def each(&block)
34
+ @actions.each do |key, _|
35
+ yield key, get(key)
36
+ end
37
+ end
38
+
39
+ # Converts this registry to a hash
40
+ def to_hash
41
+ result = {}
42
+ self.each do |key, value|
43
+ result[key] = value
44
+ end
45
+
46
+ result
47
+ end
48
+ end
49
+ end
@@ -1,194 +1,123 @@
1
- require 'net/ssh'
2
- require 'net/scp'
1
+ require 'log4r'
2
+
3
+ require 'vagrant/util/file_mode'
4
+ require 'vagrant/util/platform'
5
+ require 'vagrant/util/safe_exec'
3
6
 
4
7
  module Vagrant
5
- # Manages SSH access to a specific environment. Allows an environment to
6
- # replace the process with SSH itself, run a specific set of commands,
7
- # upload files, or even check if a host is up.
8
+ # Manages SSH connection information as well as allows opening an
9
+ # SSH connection.
8
10
  class SSH
9
- # Autoload this guy because he is really only used in one location
10
- # and not for every Vagrant command.
11
- autoload :Session, 'vagrant/ssh/session'
12
-
13
- include Util::Retryable
14
11
  include Util::SafeExec
15
12
 
16
- # Reference back up to the environment which this SSH object belongs
17
- # to
18
- attr_accessor :env
13
+ def initialize(vm)
14
+ @vm = vm
15
+ @logger = Log4r::Logger.new("vagrant::ssh")
16
+ end
19
17
 
20
- def initialize(environment)
21
- @env = environment
18
+ # Returns a hash of information necessary for accessing this
19
+ # virtual machine via SSH.
20
+ #
21
+ # @return [Hash]
22
+ def info
23
+ results = {
24
+ :host => @vm.config.ssh.host,
25
+ :port => @vm.config.ssh.port || @vm.driver.ssh_port(@vm.config.ssh.guest_port),
26
+ :username => @vm.config.ssh.username,
27
+ :forward_agent => @vm.config.ssh.forward_agent,
28
+ :forward_x11 => @vm.config.ssh.forward_x11
29
+ }
30
+
31
+ # This can happen if no port is set and for some reason Vagrant
32
+ # can't detect an SSH port.
33
+ raise Errors::SSHPortNotDetected if !results[:port]
34
+
35
+ # Determine the private key path, which is either set by the
36
+ # configuration or uses just the built-in insecure key.
37
+ pk_path = @vm.config.ssh.private_key_path || @vm.env.default_private_key_path
38
+ results[:private_key_path] = File.expand_path(pk_path, @vm.env.root_path)
39
+
40
+ # We need to check and fix the private key permissions
41
+ # to make sure that SSH gets a key with 0600 perms.
42
+ check_key_permissions(results[:private_key_path])
43
+
44
+ # Return the results
45
+ return results
22
46
  end
23
47
 
24
48
  # Connects to the environment's virtual machine, replacing the ruby
25
- # process with an SSH process. This method optionally takes a hash
26
- # of options which override the configuration values.
27
- def connect(opts={})
49
+ # process with an SSH process.
50
+ #
51
+ # @param [Hash] opts Options hash
52
+ # @options opts [Boolean] :plain_mode If True, doesn't authenticate with
53
+ # the machine, only connects, allowing the user to connect.
54
+ def exec(opts={})
55
+ # Get the SSH information and cache it here
56
+ ssh_info = info
57
+
28
58
  if Util::Platform.windows?
29
- raise Errors::SSHUnavailableWindows, :key_path => env.config.ssh.private_key_path,
30
- :ssh_port => port(opts)
59
+ raise Errors::SSHUnavailableWindows, :host => ssh_info[:host],
60
+ :port => ssh_info[:port],
61
+ :username => ssh_info[:username],
62
+ :key_path => ssh_info[:private_key_path]
31
63
  end
32
64
 
33
65
  raise Errors::SSHUnavailable if !Kernel.system("which ssh > /dev/null 2>&1")
34
66
 
35
- options = {}
36
- options[:port] = port(opts)
37
- [:host, :username, :private_key_path].each do |param|
38
- options[param] = opts[param] || env.config.ssh.send(param)
39
- end
67
+ # If plain mode is enabled then we don't do any authentication (we don't
68
+ # set a user or an identity file)
69
+ plain_mode = opts[:plain_mode]
40
70
 
41
- check_key_permissions(options[:private_key_path])
71
+ options = {}
72
+ options[:host] = ssh_info[:host]
73
+ options[:port] = ssh_info[:port]
74
+ options[:username] = ssh_info[:username]
75
+ options[:private_key_path] = ssh_info[:private_key_path]
42
76
 
43
77
  # Command line options
44
78
  command_options = ["-p #{options[:port]}", "-o UserKnownHostsFile=/dev/null",
45
79
  "-o StrictHostKeyChecking=no", "-o IdentitiesOnly=yes",
46
- "-i #{options[:private_key_path]}", "-o LogLevel=ERROR"]
47
- command_options << "-o ForwardAgent=yes" if env.config.ssh.forward_agent
80
+ "-o LogLevel=ERROR"]
81
+ command_options << "-i #{options[:private_key_path]}" if !plain_mode
82
+ command_options << "-o ForwardAgent=yes" if ssh_info[:forward_agent]
83
+
84
+ # If there are extra options, then we append those
85
+ command_options.concat(opts[:extra_args]) if opts[:extra_args]
48
86
 
49
- if env.config.ssh.forward_x11
87
+ if ssh_info[:forward_x11]
50
88
  # Both are required so that no warnings are shown regarding X11
51
89
  command_options << "-o ForwardX11=yes"
52
90
  command_options << "-o ForwardX11Trusted=yes"
53
91
  end
54
92
 
55
- command = "ssh #{command_options.join(" ")} #{options[:username]}@#{options[:host]}".strip
56
- env.logger.info("ssh") { "Invoking SSH: #{command}" }
93
+ host_string = options[:host]
94
+ host_string = "#{options[:username]}@#{host_string}" if !plain_mode
95
+ command = "ssh #{command_options.join(" ")} #{host_string}".strip
96
+ @logger.info("Invoking SSH: #{command}")
57
97
  safe_exec(command)
58
98
  end
59
99
 
60
- # Opens an SSH connection to this environment's virtual machine and yields
61
- # a Net::SSH object which can be used to execute remote commands.
62
- def execute(opts={})
63
- # Check the key permissions to avoid SSH hangs
64
- check_key_permissions(env.config.ssh.private_key_path)
65
-
66
- # Merge in any additional options
67
- opts = opts.dup
68
- opts[:forward_agent] = true if env.config.ssh.forward_agent
69
- opts[:port] ||= port
70
-
71
- env.logger.info("ssh") { "Connecting to SSH: #{env.config.ssh.host} #{opts[:port]}" }
72
-
73
- # The exceptions which are acceptable to retry on during
74
- # attempts to connect to SSH
75
- exceptions = [Errno::ECONNREFUSED, Net::SSH::Disconnect]
76
-
77
- # Connect to SSH and gather the session
78
- session = retryable(:tries => env.config.ssh.max_tries, :on => exceptions) do
79
- connection = Net::SSH.start(env.config.ssh.host,
80
- env.config.ssh.username,
81
- opts.merge( :keys => [env.config.ssh.private_key_path],
82
- :keys_only => true,
83
- :user_known_hosts_file => [],
84
- :paranoid => false,
85
- :config => false))
86
- SSH::Session.new(connection, env)
87
- end
88
-
89
- # Yield our session for executing
90
- return yield session if block_given?
91
- rescue Errno::ECONNREFUSED
92
- raise Errors::SSHConnectionRefused
93
- end
94
-
95
- # Uploads a file from `from` to `to`. `from` is expected to be a filename
96
- # or StringIO, and `to` is expected to be a path. This method simply forwards
97
- # the arguments to `Net::SCP#upload!` so view that for more information.
98
- def upload!(from, to)
99
- retryable(:tries => 5, :on => IOError) do
100
- execute do |ssh|
101
- scp = Net::SCP.new(ssh.session)
102
- scp.upload!(from, to)
103
- end
104
- end
105
- end
106
-
107
- # Checks if this environment's machine is up (i.e. responding to SSH).
108
- #
109
- # @return [Boolean]
110
- def up?
111
- # We have to determine the port outside of the block since it uses
112
- # API calls which can only be used from the main thread in JRuby on
113
- # Windows
114
- ssh_port = port
115
-
116
- require 'timeout'
117
- Timeout.timeout(env.config.ssh.timeout) do
118
- execute(:timeout => env.config.ssh.timeout, :port => ssh_port) { |ssh| }
119
- end
120
-
121
- true
122
- rescue Net::SSH::AuthenticationFailed
123
- raise Errors::SSHAuthenticationFailed
124
- rescue Timeout::Error, Errno::ECONNREFUSED, Net::SSH::Disconnect,
125
- Errors::SSHConnectionRefused
126
- return false
127
- end
128
-
129
- # Checks the file permissions for the private key, resetting them
130
- # if needed, or on failure erroring.
100
+ # Checks the file permissions for a private key, resetting them
101
+ # if needed.
131
102
  def check_key_permissions(key_path)
132
103
  # Windows systems don't have this issue
133
104
  return if Util::Platform.windows?
134
105
 
135
- env.logger.info("ssh") { "Checking key permissions: #{key_path}" }
136
-
106
+ @logger.debug("Checking key permissions: #{key_path}")
137
107
  stat = File.stat(key_path)
138
108
 
139
- if stat.owned? && file_perms(key_path) != "600"
140
- env.logger.info("ssh") { "Attempting to correct key permissions to 0600" }
141
-
109
+ if stat.owned? && Util::FileMode.from_octal(stat.mode) != "600"
110
+ @logger.info("Attempting to correct key permissions to 0600")
142
111
  File.chmod(0600, key_path)
143
- raise Errors::SSHKeyBadPermissions, :key_path => key_path if file_perms(key_path) != "600"
144
- end
145
- rescue Errno::EPERM
146
- # This shouldn't happen since we verify we own the file, but just
147
- # in case.
148
- raise Errors::SSHKeyBadPermissions, :key_path => key_path
149
- end
150
112
 
151
- # Returns the file permissions of a given file. This is fairly unix specific
152
- # and probably doesn't belong in this class. Will be refactored out later.
153
- def file_perms(path)
154
- perms = sprintf("%o", File.stat(path).mode)
155
- perms.reverse[0..2].reverse
156
- end
157
-
158
- # Returns the port which is either given in the options hash or taken from
159
- # the config by finding it in the forwarded ports hash based on the
160
- # `config.ssh.forwarded_port_key`.
161
- def port(opts={})
162
- # Check if port was specified in options hash
163
- return opts[:port] if opts[:port]
164
-
165
- # Check if a port was specified in the config
166
- return env.config.ssh.port if env.config.ssh.port
167
-
168
- # Check if we have an SSH forwarded port
169
- pnum_by_name = nil
170
- pnum_by_destination = nil
171
- env.vm.vm.network_adapters.each do |na|
172
- # Look for the port number by name...
173
- pnum_by_name = na.nat_driver.forwarded_ports.detect do |fp|
174
- fp.name == env.config.ssh.forwarded_port_key
113
+ if Util::FileMode.from_octal(stat.mode) != "600"
114
+ raise Errors::SSHKeyBadPermissions, :key_path => key_path
175
115
  end
176
-
177
- # Look for the port number by destination...
178
- pnum_by_destination = na.nat_driver.forwarded_ports.detect do |fp|
179
- fp.guestport == env.config.ssh.forwarded_port_destination
180
- end
181
-
182
- # pnum_by_name is what we're looking for here, so break early
183
- # if we have it.
184
- break if pnum_by_name
185
116
  end
186
-
187
- return pnum_by_name.hostport if pnum_by_name
188
- return pnum_by_destination.hostport if pnum_by_destination
189
-
190
- # This should NEVER happen.
191
- raise Errors::SSHPortNotDetected
117
+ rescue Errno::EPERM
118
+ # This shouldn't happen since we verified we own the file, but
119
+ # it is possible in theory, so we raise an error.
120
+ raise Errors::SSHKeyBadPermissions, :key_path => key_path
192
121
  end
193
122
  end
194
123
  end