fixed-vagrant 0.7.4.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +272 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/Rakefile +22 -0
- data/bin/vagrant +22 -0
- data/config/default.rb +39 -0
- data/contrib/README.md +12 -0
- data/contrib/emacs/vagrant.el +8 -0
- data/contrib/vim/vagrantfile.vim +9 -0
- data/keys/README.md +17 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.ppk +26 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +42 -0
- data/lib/vagrant/action.rb +134 -0
- data/lib/vagrant/action/box.rb +11 -0
- data/lib/vagrant/action/box/destroy.rb +21 -0
- data/lib/vagrant/action/box/download.rb +72 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +55 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +124 -0
- data/lib/vagrant/action/builtin.rb +104 -0
- data/lib/vagrant/action/env.rb +7 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +50 -0
- data/lib/vagrant/action/general.rb +8 -0
- data/lib/vagrant/action/general/package.rb +109 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +31 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +30 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
- data/lib/vagrant/action/vm/customize.rb +21 -0
- data/lib/vagrant/action/vm/destroy.rb +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +30 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +52 -0
- data/lib/vagrant/action/vm/forward_ports.rb +134 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +29 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +35 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
- data/lib/vagrant/action/vm/network.rb +139 -0
- data/lib/vagrant/action/vm/nfs.rb +159 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +33 -0
- data/lib/vagrant/action/vm/provision.rb +41 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +70 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +79 -0
- data/lib/vagrant/box.rb +90 -0
- data/lib/vagrant/box_collection.rb +53 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command.rb +25 -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 +107 -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 +42 -0
- data/lib/vagrant/command/ssh_config.rb +26 -0
- data/lib/vagrant/command/status.rb +22 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +19 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +123 -0
- data/lib/vagrant/config/base.rb +85 -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 +33 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +16 -0
- data/lib/vagrant/config/vm.rb +137 -0
- data/lib/vagrant/config/vm/provisioner.rb +56 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +70 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +23 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +64 -0
- data/lib/vagrant/environment.rb +392 -0
- data/lib/vagrant/errors.rb +332 -0
- data/lib/vagrant/hosts.rb +8 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +78 -0
- data/lib/vagrant/hosts/bsd.rb +52 -0
- data/lib/vagrant/hosts/linux.rb +47 -0
- data/lib/vagrant/plugin.rb +57 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +63 -0
- data/lib/vagrant/provisioners/chef.rb +130 -0
- data/lib/vagrant/provisioners/chef_server.rb +103 -0
- data/lib/vagrant/provisioners/chef_solo.rb +142 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +52 -0
- data/lib/vagrant/ssh.rb +173 -0
- data/lib/vagrant/ssh/session.rb +125 -0
- data/lib/vagrant/systems.rb +11 -0
- data/lib/vagrant/systems/base.rb +87 -0
- data/lib/vagrant/systems/debian.rb +36 -0
- data/lib/vagrant/systems/freebsd.rb +84 -0
- data/lib/vagrant/systems/gentoo.rb +27 -0
- data/lib/vagrant/systems/linux.rb +83 -0
- data/lib/vagrant/systems/linux/config.rb +21 -0
- data/lib/vagrant/systems/linux/error.rb +9 -0
- data/lib/vagrant/systems/redhat.rb +39 -0
- data/lib/vagrant/systems/solaris.rb +62 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +69 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/plain_logger.rb +25 -0
- data/lib/vagrant/util/platform.rb +65 -0
- data/lib/vagrant/util/resource_logger.rb +63 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +177 -0
- data/templates/chef_server_client.erb +18 -0
- data/templates/chef_solo_solo.erb +19 -0
- data/templates/commands/init/Vagrantfile.erb +82 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +535 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +8 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +9 -0
- data/test/locales/en.yml +8 -0
- data/test/test_helper.rb +26 -0
- data/test/vagrant/action/box/destroy_test.rb +18 -0
- data/test/vagrant/action/box/download_test.rb +125 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/vagrant/action/box/verify_test.rb +30 -0
- data/test/vagrant/action/builder_test.rb +203 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +27 -0
- data/test/vagrant/action/general/package_test.rb +268 -0
- data/test/vagrant/action/general/validate_test.rb +31 -0
- data/test/vagrant/action/vm/boot_test.rb +66 -0
- data/test/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +30 -0
- data/test/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/vagrant/action/vm/export_test.rb +107 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +194 -0
- data/test/vagrant/action/vm/halt_test.rb +79 -0
- data/test/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/vagrant/action/vm/import_test.rb +66 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +36 -0
- data/test/vagrant/action/vm/network_test.rb +286 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/provision_test.rb +90 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +139 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action/warden_test.rb +119 -0
- data/test/vagrant/action_test.rb +89 -0
- data/test/vagrant/box_collection_test.rb +45 -0
- data/test/vagrant/box_test.rb +74 -0
- 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/command/package_test.rb +27 -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 +35 -0
- data/test/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/vagrant/config/vm_test.rb +86 -0
- data/test/vagrant/config_test.rb +162 -0
- data/test/vagrant/data_store_test.rb +77 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +48 -0
- data/test/vagrant/downloaders/http_test.rb +80 -0
- data/test/vagrant/environment_test.rb +508 -0
- data/test/vagrant/errors_test.rb +42 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +53 -0
- data/test/vagrant/hosts/linux_test.rb +54 -0
- data/test/vagrant/plugin_test.rb +9 -0
- data/test/vagrant/provisioners/base_test.rb +63 -0
- data/test/vagrant/provisioners/chef_server_test.rb +188 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +219 -0
- data/test/vagrant/provisioners/chef_test.rb +179 -0
- data/test/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/vagrant/provisioners/shell_test.rb +68 -0
- data/test/vagrant/ssh/session_test.rb +40 -0
- data/test/vagrant/ssh_test.rb +342 -0
- data/test/vagrant/systems/base_test.rb +18 -0
- data/test/vagrant/systems/linux_test.rb +114 -0
- data/test/vagrant/ui_test.rb +29 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +78 -0
- data/test/vagrant/util/retryable_test.rb +50 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/vm_test.rb +291 -0
- data/vagrant.gemspec +36 -0
- metadata +514 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'vagrant/systems/debian'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Systems
|
5
|
+
class Ubuntu < Debian
|
6
|
+
def change_host_name(name)
|
7
|
+
vm.ssh.execute do |ssh|
|
8
|
+
if !ssh.test?("sudo hostname | grep '#{name}'")
|
9
|
+
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
|
10
|
+
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
11
|
+
ssh.exec!("sudo service hostname start")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Vagrant
|
2
|
+
# Test helpers provided by Vagrant to allow for plugin developers
|
3
|
+
# to write automated tests for their code. This module simply provides
|
4
|
+
# methods which can be included into any test framework (`test/unit`,
|
5
|
+
# RSpec, Shoulda, etc.)
|
6
|
+
module TestHelpers
|
7
|
+
#------------------------------------------------------------
|
8
|
+
# Environment creation helpers
|
9
|
+
#------------------------------------------------------------
|
10
|
+
# Creates a "vagrant_app" directory in the test tmp folder
|
11
|
+
# which can be used for creating test Vagrant environments.
|
12
|
+
# Returns the root directory of the app. This typically doesn't need
|
13
|
+
# to be called directly unless you're setting up a custom application.
|
14
|
+
# See the examples for common use cases.
|
15
|
+
def vagrant_app(*path)
|
16
|
+
root = tmp_path.join("vagrant_app")
|
17
|
+
FileUtils.rm_rf(root)
|
18
|
+
FileUtils.mkdir_p(root)
|
19
|
+
root.join(*path)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a Vagrantfile with the given contents in the given
|
23
|
+
# app directory. If no app directory is specified, then a default
|
24
|
+
# Vagrant app is used.
|
25
|
+
def vagrantfile(*args)
|
26
|
+
path = args.shift.join("Vagrantfile") if Pathname === args.first
|
27
|
+
path ||= vagrant_app("Vagrantfile")
|
28
|
+
|
29
|
+
# Create this box so that it exists
|
30
|
+
vagrant_box("base")
|
31
|
+
|
32
|
+
str = args.shift || ""
|
33
|
+
File.open(path.to_s, "w") do |f|
|
34
|
+
f.puts "ENV['VAGRANT_HOME'] = '#{home_path}'"
|
35
|
+
f.puts "Vagrant::Config.run do |config|"
|
36
|
+
f.puts "config.vm.base_mac = 'foo' if !config.vm.base_mac"
|
37
|
+
f.puts "config.vm.box = 'base'"
|
38
|
+
f.puts str
|
39
|
+
f.puts "end"
|
40
|
+
end
|
41
|
+
|
42
|
+
path.parent
|
43
|
+
end
|
44
|
+
|
45
|
+
# Creates and _loads_ a Vagrant environment at the given path.
|
46
|
+
# If no path is given, then a default {#vagrantfile} is used.
|
47
|
+
def vagrant_env(*args)
|
48
|
+
path = args.shift if Pathname === args.first
|
49
|
+
path ||= vagrantfile
|
50
|
+
Vagrant::Environment.new(:cwd => path).load!
|
51
|
+
end
|
52
|
+
|
53
|
+
# Creates the folder to contain a vagrant box. This allows for
|
54
|
+
# "fake" boxes to be made with the specified name.
|
55
|
+
#
|
56
|
+
# @param [String] name
|
57
|
+
# @return [Pathname]
|
58
|
+
def vagrant_box(name)
|
59
|
+
result = boxes_path.join(name)
|
60
|
+
FileUtils.mkdir_p(result)
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns an instantiated downloader with a mocked tempfile
|
65
|
+
# which can be passed into it.
|
66
|
+
#
|
67
|
+
# @param [Class] klass The downloader class
|
68
|
+
# @return [Array] Returns an array of `downloader` `tempfile`
|
69
|
+
def vagrant_mock_downloader(klass)
|
70
|
+
tempfile = mock("tempfile")
|
71
|
+
tempfile.stubs(:write)
|
72
|
+
|
73
|
+
_, env = action_env
|
74
|
+
[klass.new(env), tempfile]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns a blank app (callable) and action environment with the
|
78
|
+
# given vagrant environment. This allows for testing of middlewares.
|
79
|
+
def action_env(v_env = nil)
|
80
|
+
v_env ||= vagrant_env
|
81
|
+
app = lambda { |env| }
|
82
|
+
env = Vagrant::Action::Environment.new(v_env)
|
83
|
+
env["vagrant.test"] = true
|
84
|
+
[app, env]
|
85
|
+
end
|
86
|
+
|
87
|
+
#------------------------------------------------------------
|
88
|
+
# Path helpers
|
89
|
+
#------------------------------------------------------------
|
90
|
+
# Path to the tmp directory for the tests.
|
91
|
+
#
|
92
|
+
# @return [Pathname]
|
93
|
+
def tmp_path
|
94
|
+
result = Vagrant.source_root.join("test", "tmp")
|
95
|
+
FileUtils.mkdir_p(result)
|
96
|
+
result
|
97
|
+
end
|
98
|
+
|
99
|
+
# Path to the "home" directory for the tests
|
100
|
+
#
|
101
|
+
# @return [Pathname]
|
102
|
+
def home_path
|
103
|
+
result = tmp_path.join("home")
|
104
|
+
FileUtils.mkdir_p(result)
|
105
|
+
result
|
106
|
+
end
|
107
|
+
|
108
|
+
# Path to the boxes directory in the home directory
|
109
|
+
#
|
110
|
+
# @return [Pathname]
|
111
|
+
def boxes_path
|
112
|
+
result = home_path.join("boxes")
|
113
|
+
FileUtils.mkdir_p(result)
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
# Cleans all the test temp paths, which includes the boxes path,
|
118
|
+
# home path, etc. This allows for cleaning between tests.
|
119
|
+
def clean_paths
|
120
|
+
FileUtils.rm_rf(tmp_path)
|
121
|
+
|
122
|
+
# Call these methods only to rebuild the directories
|
123
|
+
tmp_path
|
124
|
+
home_path
|
125
|
+
boxes_path
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/vagrant/ui.rb
ADDED
@@ -0,0 +1,69 @@
|
|
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
|
+
class_eval <<-CODE
|
30
|
+
def #{method}(message, opts=nil)
|
31
|
+
@shell.say("\#{line_reset}\#{format_message(message, opts)}", #{color.inspect})
|
32
|
+
end
|
33
|
+
CODE
|
34
|
+
end
|
35
|
+
|
36
|
+
[:ask, :no?, :yes?].each do |method|
|
37
|
+
class_eval <<-CODE
|
38
|
+
def #{method}(message, opts=nil)
|
39
|
+
opts ||= {}
|
40
|
+
@shell.send(#{method.inspect}, format_message(message, opts), opts[:color])
|
41
|
+
end
|
42
|
+
CODE
|
43
|
+
end
|
44
|
+
|
45
|
+
def report_progress(progress, total, show_parts=true)
|
46
|
+
percent = (progress.to_f / total.to_f) * 100
|
47
|
+
line = "Progress: #{percent.to_i}%"
|
48
|
+
line << " (#{progress} / #{total})" if show_parts
|
49
|
+
line = "#{line_reset}#{line}"
|
50
|
+
|
51
|
+
@shell.say(line, nil, false)
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
def format_message(message, opts=nil)
|
57
|
+
opts = { :prefix => true }.merge(opts || {})
|
58
|
+
message = "[#{env.resource}] #{message}" if opts[:prefix]
|
59
|
+
message
|
60
|
+
end
|
61
|
+
|
62
|
+
def line_reset
|
63
|
+
reset = "\r"
|
64
|
+
reset += "\e[0K" unless Mario::Platform.windows?
|
65
|
+
reset
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/vagrant/util.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Util
|
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'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Util
|
3
|
+
# Utility class which allows blocks of code to be marked as "busy"
|
4
|
+
# with a specified interrupt handler. During busy areas of code, it
|
5
|
+
# is often undesirable for SIGINTs to immediately kill the application.
|
6
|
+
# This class is a helper to cleanly register callbacks to handle this
|
7
|
+
# situation.
|
8
|
+
class Busy
|
9
|
+
@@registered = []
|
10
|
+
@@mutex = Mutex.new
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Mark a given block of code as a "busy" block of code, which will
|
14
|
+
# register a SIGINT handler for the duration of the block. When a
|
15
|
+
# SIGINT occurs, the `sig_callback` proc will be called. It is up
|
16
|
+
# to the callback to behave properly and exit the application.
|
17
|
+
def busy(sig_callback)
|
18
|
+
register(sig_callback)
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
unregister(sig_callback)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Registers a SIGINT handler. This typically is called from {busy}.
|
25
|
+
# Callbacks are only registered once, so calling this multiple times
|
26
|
+
# with the same callback has no consequence.
|
27
|
+
def register(sig_callback)
|
28
|
+
@@mutex.synchronize do
|
29
|
+
registered << sig_callback
|
30
|
+
registered.uniq!
|
31
|
+
|
32
|
+
# Register the handler if this is our first callback.
|
33
|
+
Signal.trap("INT") { fire_callbacks } if registered.length == 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Unregisters a SIGINT handler.
|
38
|
+
def unregister(sig_callback)
|
39
|
+
@@mutex.synchronize do
|
40
|
+
registered.delete(sig_callback)
|
41
|
+
|
42
|
+
# Remove the signal trap if no more registered callbacks exist
|
43
|
+
Signal.trap("INT", "DEFAULT") if registered.empty?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Fires all the registered callbacks.
|
48
|
+
def fire_callbacks
|
49
|
+
registered.each { |r| r.call }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Helper method to get access to the class variable. This is mostly
|
53
|
+
# exposed for tests. This shouldn't be mucked with directly, since it's
|
54
|
+
# structure may change at any time.
|
55
|
+
def registered; @@registered; end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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 since 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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Util
|
5
|
+
# Subclass of the standard library logger which has no format on
|
6
|
+
# its own. The message sent to the logger is outputted as-is.
|
7
|
+
class PlainLogger < ::Logger
|
8
|
+
# This is the method which is called for all debug, info, error,
|
9
|
+
# etc. methods by the logger. This is overriden to verify that
|
10
|
+
# the output is always flushed.
|
11
|
+
#
|
12
|
+
# Logger by default syncs all log devices but this just verifies
|
13
|
+
# it is truly flushed.
|
14
|
+
def add(*args)
|
15
|
+
super
|
16
|
+
@logdev.dev.flush if @logdev
|
17
|
+
end
|
18
|
+
|
19
|
+
def format_message(level, time, progname, msg)
|
20
|
+
# We do no formatting, its up to the user
|
21
|
+
"#{msg}\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'mario'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
module Util
|
6
|
+
# This class just contains some platform checking code.
|
7
|
+
class Platform
|
8
|
+
class << self
|
9
|
+
def tiger?
|
10
|
+
platform.include?("darwin8")
|
11
|
+
end
|
12
|
+
|
13
|
+
def leopard?
|
14
|
+
platform.include?("darwin9")
|
15
|
+
end
|
16
|
+
|
17
|
+
[:darwin, :bsd, :linux].each do |type|
|
18
|
+
define_method("#{type}?") do
|
19
|
+
platform.include?(type.to_s)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def windows?
|
24
|
+
%W[mingw mswin].each do |text|
|
25
|
+
return true if platform.include?(text)
|
26
|
+
end
|
27
|
+
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def arch?
|
32
|
+
linux? &&
|
33
|
+
File.exist?('/etc/rc.conf') &&
|
34
|
+
File.exist?('/etc/pacman.conf') &&
|
35
|
+
File.exist?('/etc/rc.d/')
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns boolean noting whether this is a 64-bit CPU. This
|
39
|
+
# is not 100% accurate and there could easily be false negatives.
|
40
|
+
#
|
41
|
+
# @return [Boolean]
|
42
|
+
def bit64?
|
43
|
+
["x86_64", "amd64"].include?(RbConfig::CONFIG["host_cpu"])
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns boolean noting whether this is a 32-bit CPU. This
|
47
|
+
# can easily throw false positives since it relies on {#bit64?}.
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
def bit32?
|
51
|
+
!bit64?
|
52
|
+
end
|
53
|
+
|
54
|
+
def tar_file_options
|
55
|
+
# create, write only, fail if the file exists, binary if windows
|
56
|
+
File::WRONLY|File::EXCL|File::CREAT|(Mario::Platform.windows? ? File::BINARY : 0)
|
57
|
+
end
|
58
|
+
|
59
|
+
def platform
|
60
|
+
RbConfig::CONFIG["host_os"].downcase
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|