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