vagrant 0.8.10 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +77 -1
- data/Gemfile +0 -14
- data/LICENSE +1 -1
- data/bin/vagrant +47 -20
- data/config/default.rb +6 -14
- data/lib/vagrant.rb +132 -5
- data/lib/vagrant/action.rb +45 -123
- data/lib/vagrant/action/box/destroy.rb +7 -3
- data/lib/vagrant/action/box/download.rb +8 -8
- data/lib/vagrant/action/box/package.rb +2 -2
- data/lib/vagrant/action/box/unpackage.rb +13 -7
- data/lib/vagrant/action/box/verify.rb +5 -5
- data/lib/vagrant/action/builder.rb +23 -19
- data/lib/vagrant/action/builtin.rb +117 -79
- data/lib/vagrant/action/env/set.rb +7 -4
- data/lib/vagrant/action/environment.rb +3 -41
- data/lib/vagrant/action/general/package.rb +14 -29
- data/lib/vagrant/action/general/validate.rb +2 -2
- data/lib/vagrant/action/runner.rb +53 -0
- data/lib/vagrant/action/vm/boot.rb +9 -9
- data/lib/vagrant/action/vm/check_accessible.rb +2 -2
- data/lib/vagrant/action/vm/check_box.rb +10 -12
- data/lib/vagrant/action/vm/check_guest_additions.rb +8 -8
- data/lib/vagrant/action/vm/check_port_collisions.rb +85 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +4 -4
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +3 -11
- data/lib/vagrant/action/vm/clear_network_interfaces.rb +31 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +2 -11
- data/lib/vagrant/action/vm/customize.rb +19 -9
- data/lib/vagrant/action/vm/destroy.rb +4 -4
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +2 -12
- data/lib/vagrant/action/vm/discard_state.rb +4 -4
- data/lib/vagrant/action/vm/export.rb +13 -8
- data/lib/vagrant/action/vm/forward_ports.rb +55 -102
- data/lib/vagrant/action/vm/halt.rb +9 -6
- data/lib/vagrant/action/vm/host_name.rb +4 -4
- data/lib/vagrant/action/vm/import.rb +19 -10
- data/lib/vagrant/action/vm/match_mac_address.rb +4 -9
- data/lib/vagrant/action/vm/network.rb +300 -94
- data/lib/vagrant/action/vm/nfs.rb +41 -26
- data/lib/vagrant/action/vm/package.rb +1 -1
- data/lib/vagrant/action/vm/package_vagrantfile.rb +5 -2
- data/lib/vagrant/action/vm/provision.rb +42 -13
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +2 -2
- data/lib/vagrant/action/vm/{clear_nfs_exports.rb → prune_nfs_exports.rb} +7 -7
- data/lib/vagrant/action/vm/resume.rb +4 -4
- data/lib/vagrant/action/vm/setup_package_files.rb +54 -0
- data/lib/vagrant/action/vm/share_folders.rb +63 -39
- data/lib/vagrant/action/vm/suspend.rb +4 -4
- data/lib/vagrant/action/warden.rb +13 -6
- data/lib/vagrant/box.rb +9 -55
- data/lib/vagrant/box_collection.rb +22 -17
- data/lib/vagrant/cli.rb +62 -47
- data/lib/vagrant/command.rb +18 -20
- data/lib/vagrant/command/base.rb +135 -90
- data/lib/vagrant/command/box.rb +46 -21
- data/lib/vagrant/command/box_add.rb +33 -0
- data/lib/vagrant/command/box_list.rb +25 -0
- data/lib/vagrant/command/box_remove.rb +23 -0
- data/lib/vagrant/command/box_repackage.rb +23 -0
- data/lib/vagrant/command/destroy.rb +16 -5
- data/lib/vagrant/command/halt.rb +25 -7
- data/lib/vagrant/command/init.rb +30 -7
- data/lib/vagrant/command/package.rb +49 -18
- data/lib/vagrant/command/provision.rb +22 -9
- data/lib/vagrant/command/reload.rb +18 -5
- data/lib/vagrant/command/resume.rb +18 -5
- data/lib/vagrant/command/ssh.rb +69 -31
- data/lib/vagrant/command/ssh_config.rb +37 -22
- data/lib/vagrant/command/status.rb +22 -20
- data/lib/vagrant/command/suspend.rb +18 -5
- data/lib/vagrant/command/up.rb +41 -8
- data/lib/vagrant/communication.rb +7 -0
- data/lib/vagrant/communication/base.rb +56 -0
- data/lib/vagrant/communication/ssh.rb +200 -0
- data/lib/vagrant/config.rb +29 -103
- data/lib/vagrant/config/base.rb +18 -26
- data/lib/vagrant/config/container.rb +37 -0
- data/lib/vagrant/config/error_recorder.rb +1 -1
- data/lib/vagrant/config/loader.rb +125 -0
- data/lib/vagrant/config/nfs.rb +1 -3
- data/lib/vagrant/config/package.rb +1 -3
- data/lib/vagrant/config/ssh.rb +31 -16
- data/lib/vagrant/config/top.rb +36 -25
- data/lib/vagrant/config/vagrant.rb +2 -5
- data/lib/vagrant/config/vm.rb +115 -56
- data/lib/vagrant/config/vm/provisioner.rb +16 -20
- data/lib/vagrant/config/vm/sub_vm.rb +1 -1
- data/lib/vagrant/data_store.rb +23 -15
- data/lib/vagrant/downloaders/base.rb +7 -5
- data/lib/vagrant/downloaders/file.rb +4 -4
- data/lib/vagrant/downloaders/http.rb +4 -5
- data/lib/vagrant/driver.rb +7 -0
- data/lib/vagrant/driver/virtualbox.rb +121 -0
- data/lib/vagrant/driver/virtualbox_4_0.rb +411 -0
- data/lib/vagrant/driver/virtualbox_4_1.rb +411 -0
- data/lib/vagrant/driver/virtualbox_base.rb +284 -0
- data/lib/vagrant/environment.rb +221 -240
- data/lib/vagrant/errors.rb +74 -25
- data/lib/vagrant/guest.rb +16 -0
- data/lib/vagrant/guest/arch.rb +48 -0
- data/lib/vagrant/{systems → guest}/base.rb +30 -18
- data/lib/vagrant/guest/debian.rb +61 -0
- data/lib/vagrant/{systems → guest}/freebsd.rb +11 -18
- data/lib/vagrant/guest/gentoo.rb +32 -0
- data/lib/vagrant/guest/linux.rb +78 -0
- data/lib/vagrant/{systems → guest}/linux/config.rb +2 -4
- data/lib/vagrant/guest/linux/error.rb +9 -0
- data/lib/vagrant/guest/redhat.rb +66 -0
- data/lib/vagrant/guest/solaris.rb +114 -0
- data/lib/vagrant/{systems → guest}/suse.rb +2 -2
- data/lib/vagrant/guest/ubuntu.rb +23 -0
- data/lib/vagrant/hosts.rb +23 -6
- data/lib/vagrant/hosts/arch.rb +7 -3
- data/lib/vagrant/hosts/base.rb +36 -46
- data/lib/vagrant/hosts/bsd.rb +53 -16
- data/lib/vagrant/hosts/fedora.rb +14 -0
- data/lib/vagrant/hosts/freebsd.rb +6 -36
- data/lib/vagrant/hosts/linux.rb +45 -20
- data/lib/vagrant/hosts/windows.rb +16 -0
- data/lib/vagrant/provisioners.rb +10 -7
- data/lib/vagrant/provisioners/base.rb +11 -34
- data/lib/vagrant/provisioners/chef.rb +30 -26
- data/lib/vagrant/provisioners/chef_client.rb +37 -23
- data/lib/vagrant/provisioners/chef_solo.rb +61 -16
- data/lib/vagrant/provisioners/puppet.rb +70 -38
- data/lib/vagrant/provisioners/puppet_server.rb +12 -13
- data/lib/vagrant/provisioners/shell.rb +24 -24
- data/lib/vagrant/registry.rb +49 -0
- data/lib/vagrant/ssh.rb +82 -153
- data/lib/vagrant/ui.rb +118 -50
- data/lib/vagrant/util/busy.rb +1 -1
- data/lib/vagrant/util/file_mode.rb +12 -0
- data/lib/vagrant/util/network_ip.rb +28 -0
- data/lib/vagrant/util/platform.rb +1 -0
- data/lib/vagrant/util/subprocess.rb +227 -0
- data/lib/vagrant/version.rb +1 -1
- data/lib/vagrant/vm.rb +111 -97
- data/tasks/acceptance.rake +3 -3
- data/tasks/test.rake +7 -2
- data/templates/commands/init/Vagrantfile.erb +11 -4
- data/templates/{ssh_config.erb → commands/ssh_config/config.erb} +0 -0
- data/templates/guests/arch/network_dhcp.erb +7 -0
- data/templates/guests/arch/network_static.erb +7 -0
- data/templates/guests/debian/network_dhcp.erb +6 -0
- data/templates/guests/debian/network_static.erb +7 -0
- data/templates/guests/gentoo/network_dhcp.erb +4 -0
- data/templates/guests/gentoo/network_static.erb +4 -0
- data/templates/guests/redhat/network_dhcp.erb +6 -0
- data/templates/guests/redhat/network_static.erb +7 -0
- data/templates/locales/en.yml +241 -122
- data/templates/{chef_server_client.erb → provisioners/chef_client/client.erb} +0 -0
- data/templates/{chef_solo_solo.erb → provisioners/chef_solo/solo.erb} +0 -0
- data/test/acceptance/base.rb +10 -10
- data/test/acceptance/box_test.rb +28 -6
- data/test/acceptance/destroy_test.rb +1 -1
- data/test/acceptance/halt_test.rb +4 -4
- data/test/acceptance/init_test.rb +3 -3
- data/test/acceptance/networking/host_only_test.rb +37 -0
- data/test/acceptance/networking/port_forward_test.rb +125 -0
- data/test/acceptance/package_test.rb +46 -0
- data/test/acceptance/provisioning/basic_test.rb +61 -0
- data/test/acceptance/provisioning/chef_solo_test.rb +37 -0
- data/test/acceptance/provisioning/shell_test.rb +53 -0
- data/test/acceptance/resume_test.rb +1 -1
- data/test/acceptance/skeletons/chef_solo_basic/README.md +3 -0
- data/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb +5 -0
- data/test/acceptance/skeletons/chef_solo_json/README.md +3 -0
- data/test/acceptance/skeletons/chef_solo_json/cookbooks/basic/recipes/default.rb +6 -0
- data/test/acceptance/skeletons/provisioner_multi/README.md +3 -0
- data/test/acceptance/skeletons/provisioner_multi/cookbooks/basic/recipes/default.rb +5 -0
- data/test/acceptance/ssh_test.rb +7 -2
- data/test/acceptance/support/config.rb +1 -1
- data/test/acceptance/support/isolated_environment.rb +41 -150
- data/test/acceptance/support/matchers/match_output.rb +1 -1
- data/test/acceptance/support/matchers/succeed.rb +14 -0
- data/test/acceptance/support/network_tests.rb +29 -0
- data/test/acceptance/support/output.rb +9 -1
- data/test/acceptance/support/shared/base_context.rb +16 -9
- data/test/acceptance/support/shared/command_examples.rb +4 -4
- data/test/acceptance/suspend_test.rb +1 -1
- data/test/acceptance/up_basic_test.rb +26 -7
- data/test/acceptance/up_with_box_url.rb +1 -1
- data/test/acceptance/vagrant_test.rb +1 -1
- data/test/acceptance/version_test.rb +0 -5
- data/test/support/isolated_environment.rb +46 -0
- data/test/{acceptance/support → support}/tempdir.rb +0 -0
- data/test/unit/base.rb +21 -0
- data/test/unit/support/isolated_environment.rb +39 -0
- data/test/unit/support/shared/base_context.rb +30 -0
- data/test/unit/vagrant/action/builder_test.rb +126 -177
- data/test/unit/vagrant/action/environment_test.rb +10 -21
- data/test/unit/vagrant/action/runner_test.rb +65 -0
- data/test/unit/vagrant/action/warden_test.rb +64 -97
- data/test/unit/vagrant/box_collection_test.rb +44 -33
- data/test/unit/vagrant/box_test.rb +25 -65
- data/test/unit/vagrant/command/base_test.rb +141 -14
- data/test/unit/vagrant/config/base_test.rb +16 -43
- data/test/unit/vagrant/config/loader_test.rb +79 -0
- data/test/unit/vagrant/config/top_test.rb +69 -0
- data/test/unit/vagrant/config/vm_test.rb +62 -47
- data/test/unit/vagrant/config_test.rb +16 -151
- data/test/unit/vagrant/data_store_test.rb +43 -61
- data/test/unit/vagrant/downloaders/base_test.rb +12 -22
- data/test/unit/vagrant/downloaders/file_test.rb +58 -31
- data/test/unit/vagrant/downloaders/http_test.rb +12 -86
- data/test/unit/vagrant/environment_test.rb +107 -536
- data/test/unit/vagrant/hosts_test.rb +36 -0
- data/test/unit/vagrant/registry_test.rb +56 -0
- data/test/unit/vagrant/util/file_checksum_test.rb +23 -0
- data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +23 -24
- data/test/unit/vagrant/util/network_ip_test.rb +17 -0
- data/test/unit/vagrant/util/retryable_test.rb +90 -34
- data/test/unit/vagrant_test.rb +27 -0
- data/test/{unit → unit_legacy}/locales/en.yml +0 -0
- data/test/{unit → unit_legacy}/test_helper.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/box/destroy_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/box/download_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/box/package_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/box/unpackage_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/box/verify_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/env/set_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/general/package_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/general/validate_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/boot_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/check_accessible_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/check_box_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/check_guest_additions_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/clean_machine_folder_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/clear_forwarded_ports_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/clear_nfs_exports_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/clear_shared_folders_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/customize_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/destroy_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/discard_state_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/export_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/forward_ports_helpers_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/forward_ports_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/halt_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/host_name_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/import_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/match_mac_address_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/modify_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/network_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/nfs_helpers_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/nfs_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/package_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/package_vagrantfile_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/provision_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/provisioner_cleanup_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/resume_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/share_folders_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action/vm/suspend_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/action_test.rb +0 -0
- data/test/unit_legacy/vagrant/box_collection_test.rb +45 -0
- data/test/unit_legacy/vagrant/box_test.rb +74 -0
- data/test/{unit → unit_legacy}/vagrant/cli_test.rb +0 -0
- data/test/unit_legacy/vagrant/command/base_test.rb +23 -0
- data/test/{unit → unit_legacy}/vagrant/command/group_base_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/command/helpers_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/command/init_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/command/package_test.rb +0 -0
- data/test/unit_legacy/vagrant/config/base_test.rb +52 -0
- data/test/{unit → unit_legacy}/vagrant/config/error_recorder_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/config/ssh_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/config/vagrant_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/config/vm/provisioner_test.rb +0 -0
- data/test/unit_legacy/vagrant/config/vm_test.rb +47 -0
- data/test/unit_legacy/vagrant/config_test.rb +148 -0
- data/test/unit_legacy/vagrant/downloaders/http_test.rb +93 -0
- data/test/unit_legacy/vagrant/environment_test.rb +539 -0
- data/test/{unit → unit_legacy}/vagrant/errors_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/hosts/base_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/hosts/bsd_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/hosts/linux_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/plugin_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/base_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/chef_client_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/chef_solo_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/chef_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/puppet_server_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/puppet_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/provisioners/shell_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/ssh/session_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/ssh_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/systems/base_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/systems/linux_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/util/busy_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/util/counter_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/util/platform_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/util/stacked_proc_runner_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/util/template_renderer_test.rb +0 -0
- data/test/{unit → unit_legacy}/vagrant/vm_test.rb +0 -0
- data/vagrant.gemspec +7 -9
- metadata +214 -216
- data/keys/vagrant.ppk +0 -26
- data/lib/vagrant/action/box.rb +0 -11
- data/lib/vagrant/action/env.rb +0 -7
- data/lib/vagrant/action/general.rb +0 -8
- data/lib/vagrant/action/vm.rb +0 -34
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +0 -28
- data/lib/vagrant/action/vm/modify.rb +0 -37
- data/lib/vagrant/action/vm/nfs_helpers.rb +0 -11
- data/lib/vagrant/command/group_base.rb +0 -107
- data/lib/vagrant/command/helpers.rb +0 -33
- data/lib/vagrant/command/named_base.rb +0 -14
- data/lib/vagrant/command/upgrade_to_060.rb +0 -45
- data/lib/vagrant/command/version.rb +0 -13
- data/lib/vagrant/ssh/session.rb +0 -136
- data/lib/vagrant/systems.rb +0 -13
- data/lib/vagrant/systems/arch.rb +0 -34
- data/lib/vagrant/systems/debian.rb +0 -36
- data/lib/vagrant/systems/gentoo.rb +0 -27
- data/lib/vagrant/systems/linux.rb +0 -82
- data/lib/vagrant/systems/linux/error.rb +0 -9
- data/lib/vagrant/systems/redhat.rb +0 -48
- data/lib/vagrant/systems/solaris.rb +0 -113
- data/lib/vagrant/systems/ubuntu.rb +0 -17
- data/templates/network_entry_arch.erb +0 -9
- data/templates/network_entry_debian.erb +0 -8
- data/templates/network_entry_gentoo.erb +0 -5
- data/templates/network_entry_redhat.erb +0 -9
- data/test/unit/vagrant/ui_test.rb +0 -29
data/lib/vagrant/ui.rb
CHANGED
@@ -1,80 +1,148 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
1
3
|
module Vagrant
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
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,
|
44
|
+
def #{method}(message, *args)
|
36
45
|
super(message)
|
37
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
57
|
-
line
|
72
|
+
line = "Progress: #{percent.to_i}%"
|
73
|
+
line << " (#{progress} / #{total})" if show_parts
|
58
74
|
|
59
|
-
|
75
|
+
info(line, :new_line => false)
|
60
76
|
end
|
61
77
|
|
62
78
|
def clear_line
|
63
|
-
|
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
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
data/lib/vagrant/util/busy.rb
CHANGED
@@ -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
|
@@ -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
|