rvagrant 0.8.7.dev
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 +25 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +386 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +61 -0
- data/Rakefile +11 -0
- data/bin/vagrant +28 -0
- data/config/default.rb +38 -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 +44 -0
- data/lib/vagrant/action.rb +138 -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 +108 -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 +113 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +34 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_accessible.rb +23 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +35 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +26 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +27 -0
- data/lib/vagrant/action/vm/customize.rb +26 -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 +133 -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 +40 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +26 -0
- data/lib/vagrant/action/vm/modify.rb +37 -0
- data/lib/vagrant/action/vm/network.rb +146 -0
- data/lib/vagrant/action/vm/nfs.rb +160 -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 +34 -0
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +78 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +85 -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 +23 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +49 -0
- data/lib/vagrant/command/ssh_config.rb +29 -0
- data/lib/vagrant/command/status.rb +31 -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 +38 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +17 -0
- data/lib/vagrant/config/vm.rb +148 -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 +70 -0
- data/lib/vagrant/environment.rb +516 -0
- data/lib/vagrant/errors.rb +352 -0
- data/lib/vagrant/hosts.rb +9 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +76 -0
- data/lib/vagrant/hosts/bsd.rb +58 -0
- data/lib/vagrant/hosts/fedora.rb +11 -0
- data/lib/vagrant/hosts/linux.rb +69 -0
- data/lib/vagrant/plugin.rb +79 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +67 -0
- data/lib/vagrant/provisioners/chef.rb +155 -0
- data/lib/vagrant/provisioners/chef_client.rb +120 -0
- data/lib/vagrant/provisioners/chef_solo.rb +135 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +96 -0
- data/lib/vagrant/ssh.rb +224 -0
- data/lib/vagrant/ssh/session.rb +136 -0
- data/lib/vagrant/systems.rb +13 -0
- data/lib/vagrant/systems/arch.rb +34 -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 +82 -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 +48 -0
- data/lib/vagrant/systems/solaris.rb +67 -0
- data/lib/vagrant/systems/suse.rb +9 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +81 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/counter.rb +24 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/platform.rb +57 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/safe_exec.rb +35 -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 +181 -0
- data/templates/chef_server_client.erb +32 -0
- data/templates/chef_solo_solo.erb +23 -0
- data/templates/commands/init/Vagrantfile.erb +86 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +556 -0
- data/templates/network_entry_arch.erb +9 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +9 -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 +15 -0
- data/test/unit/locales/en.yml +8 -0
- data/test/unit/test_helper.rb +28 -0
- data/test/unit/vagrant/action/box/destroy_test.rb +18 -0
- data/test/unit/vagrant/action/box/download_test.rb +125 -0
- data/test/unit/vagrant/action/box/package_test.rb +25 -0
- data/test/unit/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/unit/vagrant/action/box/verify_test.rb +30 -0
- data/test/unit/vagrant/action/builder_test.rb +207 -0
- data/test/unit/vagrant/action/env/set_test.rb +24 -0
- data/test/unit/vagrant/action/environment_test.rb +27 -0
- data/test/unit/vagrant/action/general/package_test.rb +268 -0
- data/test/unit/vagrant/action/general/validate_test.rb +31 -0
- data/test/unit/vagrant/action/vm/boot_test.rb +66 -0
- data/test/unit/vagrant/action/vm/check_accessible_test.rb +61 -0
- data/test/unit/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/unit/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/unit/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/unit/vagrant/action/vm/clear_forwarded_ports_test.rb +52 -0
- data/test/unit/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/unit/vagrant/action/vm/clear_shared_folders_test.rb +40 -0
- data/test/unit/vagrant/action/vm/customize_test.rb +37 -0
- data/test/unit/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/unit/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/unit/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/unit/vagrant/action/vm/export_test.rb +107 -0
- data/test/unit/vagrant/action/vm/forward_ports_helpers_test.rb +77 -0
- data/test/unit/vagrant/action/vm/forward_ports_test.rb +213 -0
- data/test/unit/vagrant/action/vm/halt_test.rb +79 -0
- data/test/unit/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/unit/vagrant/action/vm/import_test.rb +66 -0
- data/test/unit/vagrant/action/vm/match_mac_address_test.rb +40 -0
- data/test/unit/vagrant/action/vm/modify_test.rb +38 -0
- data/test/unit/vagrant/action/vm/network_test.rb +286 -0
- data/test/unit/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/unit/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/unit/vagrant/action/vm/package_test.rb +25 -0
- data/test/unit/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/unit/vagrant/action/vm/provision_test.rb +65 -0
- data/test/unit/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
- data/test/unit/vagrant/action/vm/resume_test.rb +35 -0
- data/test/unit/vagrant/action/vm/share_folders_test.rb +144 -0
- data/test/unit/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/unit/vagrant/action/warden_test.rb +125 -0
- data/test/unit/vagrant/action_test.rb +89 -0
- data/test/unit/vagrant/box_collection_test.rb +45 -0
- data/test/unit/vagrant/box_test.rb +74 -0
- data/test/unit/vagrant/cli_test.rb +35 -0
- data/test/unit/vagrant/command/base_test.rb +23 -0
- data/test/unit/vagrant/command/group_base_test.rb +15 -0
- data/test/unit/vagrant/command/helpers_test.rb +88 -0
- data/test/unit/vagrant/command/package_test.rb +27 -0
- data/test/unit/vagrant/config/base_test.rb +52 -0
- data/test/unit/vagrant/config/error_recorder_test.rb +18 -0
- data/test/unit/vagrant/config/ssh_test.rb +12 -0
- data/test/unit/vagrant/config/vagrant_test.rb +35 -0
- data/test/unit/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/unit/vagrant/config/vm_test.rb +56 -0
- data/test/unit/vagrant/config_test.rb +162 -0
- data/test/unit/vagrant/data_store_test.rb +77 -0
- data/test/unit/vagrant/downloaders/base_test.rb +28 -0
- data/test/unit/vagrant/downloaders/file_test.rb +48 -0
- data/test/unit/vagrant/downloaders/http_test.rb +82 -0
- data/test/unit/vagrant/environment_test.rb +598 -0
- data/test/unit/vagrant/errors_test.rb +42 -0
- data/test/unit/vagrant/hosts/base_test.rb +46 -0
- data/test/unit/vagrant/hosts/bsd_test.rb +53 -0
- data/test/unit/vagrant/hosts/linux_test.rb +54 -0
- data/test/unit/vagrant/plugin_test.rb +9 -0
- data/test/unit/vagrant/provisioners/base_test.rb +63 -0
- data/test/unit/vagrant/provisioners/chef_client_test.rb +190 -0
- data/test/unit/vagrant/provisioners/chef_solo_test.rb +114 -0
- data/test/unit/vagrant/provisioners/chef_test.rb +202 -0
- data/test/unit/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/unit/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/unit/vagrant/provisioners/shell_test.rb +79 -0
- data/test/unit/vagrant/ssh/session_test.rb +40 -0
- data/test/unit/vagrant/ssh_test.rb +307 -0
- data/test/unit/vagrant/systems/base_test.rb +18 -0
- data/test/unit/vagrant/systems/linux_test.rb +104 -0
- data/test/unit/vagrant/ui_test.rb +29 -0
- data/test/unit/vagrant/util/busy_test.rb +106 -0
- data/test/unit/vagrant/util/counter_test.rb +29 -0
- data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/unit/vagrant/util/platform_test.rb +18 -0
- data/test/unit/vagrant/util/retryable_test.rb +50 -0
- data/test/unit/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/unit/vagrant/util/template_renderer_test.rb +145 -0
- data/test/unit/vagrant/vm_test.rb +300 -0
- data/vagrant.gemspec +35 -0
- metadata +431 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'vagrant/util/platform'
|
|
2
|
+
|
|
3
|
+
module Vagrant
|
|
4
|
+
module Hosts
|
|
5
|
+
# Represents a BSD host, such as FreeBSD and Darwin (Mac OS X).
|
|
6
|
+
class BSD < Base
|
|
7
|
+
include Util
|
|
8
|
+
include Util::Retryable
|
|
9
|
+
|
|
10
|
+
def self.distro_dispatch
|
|
11
|
+
return self if Util::Platform.darwin? || Util::Platform.bsd?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def nfs?
|
|
15
|
+
retryable(:tries => 10, :on => TypeError) do
|
|
16
|
+
system("which nfsd > /dev/null 2>&1")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def nfs_export(ip, folders)
|
|
21
|
+
output = TemplateRenderer.render('nfs/exports',
|
|
22
|
+
:uuid => env.vm.uuid,
|
|
23
|
+
:ip => ip,
|
|
24
|
+
:folders => folders)
|
|
25
|
+
|
|
26
|
+
# The sleep ensures that the output is truly flushed before any `sudo`
|
|
27
|
+
# commands are issued.
|
|
28
|
+
env.ui.info I18n.t("vagrant.hosts.bsd.nfs_export.prepare")
|
|
29
|
+
sleep 0.5
|
|
30
|
+
|
|
31
|
+
output.split("\n").each do |line|
|
|
32
|
+
# This should only ask for administrative permission once, even
|
|
33
|
+
# though its executed in multiple subshells.
|
|
34
|
+
line = line.gsub('"', '\"')
|
|
35
|
+
system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# We run restart here instead of "update" just in case nfsd
|
|
39
|
+
# is not starting
|
|
40
|
+
system("sudo nfsd restart")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def nfs_cleanup
|
|
44
|
+
return if !File.exist?("/etc/exports")
|
|
45
|
+
|
|
46
|
+
retryable(:tries => 10, :on => TypeError) do
|
|
47
|
+
system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")
|
|
48
|
+
|
|
49
|
+
if $?.to_i == 0
|
|
50
|
+
# Use sed to just strip out the block of code which was inserted
|
|
51
|
+
# by Vagrant
|
|
52
|
+
system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -ibak /etc/exports")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'vagrant/util/platform'
|
|
2
|
+
|
|
3
|
+
module Vagrant
|
|
4
|
+
module Hosts
|
|
5
|
+
# Represents a Linux based host, such as Ubuntu.
|
|
6
|
+
class Linux < Base
|
|
7
|
+
include Util
|
|
8
|
+
include Util::Retryable
|
|
9
|
+
|
|
10
|
+
def self.distro_dispatch
|
|
11
|
+
return nil if !Util::Platform.linux?
|
|
12
|
+
return Arch if File.exist?("/etc/rc.conf") && File.exist?("/etc/pacman.conf")
|
|
13
|
+
|
|
14
|
+
if File.exist?("/etc/redhat-release")
|
|
15
|
+
# Check if we have a known redhat release
|
|
16
|
+
File.open("/etc/redhat-release") do |f|
|
|
17
|
+
return Fedora if f.gets =~ /^Fedora/
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
return self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def initialize(*args)
|
|
25
|
+
super
|
|
26
|
+
|
|
27
|
+
@nfs_server_binary = "/etc/init.d/nfs-kernel-server"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def nfs?
|
|
31
|
+
retryable(:tries => 10, :on => TypeError) do
|
|
32
|
+
# Check procfs to see if NFSd is a supported filesystem
|
|
33
|
+
system("cat /proc/filesystems | grep nfsd > /dev/null 2>&1")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def nfs_export(ip, folders)
|
|
38
|
+
output = TemplateRenderer.render('nfs/exports_linux',
|
|
39
|
+
:uuid => env.vm.uuid,
|
|
40
|
+
:ip => ip,
|
|
41
|
+
:folders => folders)
|
|
42
|
+
|
|
43
|
+
env.ui.info I18n.t("vagrant.hosts.linux.nfs_export.prepare")
|
|
44
|
+
sleep 0.5
|
|
45
|
+
|
|
46
|
+
output.split("\n").each do |line|
|
|
47
|
+
# This should only ask for administrative permission once, even
|
|
48
|
+
# though its executed in multiple subshells.
|
|
49
|
+
system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# We run restart here instead of "update" just in case nfsd
|
|
53
|
+
# is not starting
|
|
54
|
+
system("sudo #{@nfs_server_binary} restart")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def nfs_cleanup
|
|
58
|
+
return if !File.exist?("/etc/exports")
|
|
59
|
+
system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")
|
|
60
|
+
|
|
61
|
+
if $?.to_i == 0
|
|
62
|
+
# Use sed to just strip out the block of code which was inserted
|
|
63
|
+
# by Vagrant
|
|
64
|
+
system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -ibak /etc/exports")
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
|
|
3
|
+
module Vagrant
|
|
4
|
+
# Represents a single plugin and also manages loading plugins from
|
|
5
|
+
# RubyGems. If a plugin has a `vagrant_init.rb` file somewhere on its
|
|
6
|
+
# load path, then this class will find it and load it. For logging purposes
|
|
7
|
+
# (for debugging), the list of loaded plugins is stored in the {plugins}
|
|
8
|
+
# array.
|
|
9
|
+
class Plugin
|
|
10
|
+
# The array of loaded plugins.
|
|
11
|
+
@@plugins = []
|
|
12
|
+
|
|
13
|
+
# The gemspec of this plugin. This is an actual gemspec object.
|
|
14
|
+
attr_reader :gemspec
|
|
15
|
+
|
|
16
|
+
# The path to the `vagrant_init.rb` file which was loaded for this plugin.
|
|
17
|
+
attr_reader :file
|
|
18
|
+
|
|
19
|
+
# Loads all the plugins for Vagrant. Plugins are currently
|
|
20
|
+
# gems which have a "vagrant_init.rb" somewhere on their
|
|
21
|
+
# load path. This file is loaded to kick off the load sequence
|
|
22
|
+
# for that plugin.
|
|
23
|
+
def self.load!
|
|
24
|
+
# Our version is used for checking dependencies
|
|
25
|
+
our_version = Gem::Version.create(Vagrant::VERSION)
|
|
26
|
+
|
|
27
|
+
# RubyGems 1.8.0 deprecated `source_index`. Gem::Specification is the
|
|
28
|
+
# new replacement. For now, we support both, but special-case 1.8.x
|
|
29
|
+
# so that we avoid deprecation messages.
|
|
30
|
+
index = Gem::VERSION >= "1.8.0" ? Gem::Specification : Gem.source_index
|
|
31
|
+
|
|
32
|
+
# Stupid hack since Rails 2.3.x overrides Gem.source_index with their
|
|
33
|
+
# own incomplete replacement which causes issues.
|
|
34
|
+
index = [index.installed_source_index, index.vendor_source_index] if defined?(Rails::VendorGemSourceIndex) && index.is_a?(Rails::VendorGemSourceIndex)
|
|
35
|
+
|
|
36
|
+
# Look for a vagrant_init.rb in all the gems, but only the
|
|
37
|
+
# latest version of the gems.
|
|
38
|
+
[index].flatten.each do |source|
|
|
39
|
+
# In 1.6.0, added the option of including prerelease gems, which is
|
|
40
|
+
# useful for developers.
|
|
41
|
+
specs = Gem::VERSION >= "1.6.0" ? source.latest_specs(true) : source.latest_specs
|
|
42
|
+
|
|
43
|
+
specs.each do |spec|
|
|
44
|
+
# If this gem depends on Vagrant, verify this is a valid release of
|
|
45
|
+
# Vagrant for this gem to load into.
|
|
46
|
+
vagrant_dep = spec.dependencies.find { |d| d.name == "vagrant" }
|
|
47
|
+
next if vagrant_dep && !vagrant_dep.requirement.satisfied_by?(our_version)
|
|
48
|
+
|
|
49
|
+
# Find a vagrant_init.rb to verify if this is a plugin
|
|
50
|
+
file = nil
|
|
51
|
+
if Gem::VERSION >= "1.8.0"
|
|
52
|
+
file = spec.matches_for_glob("**/vagrant_init.rb").first
|
|
53
|
+
else
|
|
54
|
+
file = Gem.searcher.matching_files(spec, "vagrant_init.rb").first
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
next if !file
|
|
58
|
+
@@plugins << new(spec, file)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns the array of plugins which are currently loaded by
|
|
64
|
+
# Vagrant.
|
|
65
|
+
#
|
|
66
|
+
# @return [Array]
|
|
67
|
+
def self.plugins; @@plugins; end
|
|
68
|
+
|
|
69
|
+
# Initializes a new plugin, given a Gemspec and the path to the
|
|
70
|
+
# gem's `vagrant_init.rb` file. This should never be called manually.
|
|
71
|
+
# Instead {load!} creates all the instances.
|
|
72
|
+
def initialize(spec, file)
|
|
73
|
+
@gemspec = spec
|
|
74
|
+
@file = file
|
|
75
|
+
|
|
76
|
+
load file
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# These aren't autoloaded because they have to register things such
|
|
2
|
+
# as configuration classes right away with Vagrant.
|
|
3
|
+
require 'vagrant/provisioners/base'
|
|
4
|
+
require 'vagrant/provisioners/chef'
|
|
5
|
+
require 'vagrant/provisioners/chef_client'
|
|
6
|
+
require 'vagrant/provisioners/chef_solo'
|
|
7
|
+
require 'vagrant/provisioners/puppet'
|
|
8
|
+
require 'vagrant/provisioners/puppet_server'
|
|
9
|
+
require 'vagrant/provisioners/shell'
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
module Provisioners
|
|
3
|
+
# The base class for a "provisioner." A provisioner is responsible for
|
|
4
|
+
# provisioning a Vagrant system. This has been abstracted out to provide
|
|
5
|
+
# support for multiple solutions such as Chef Solo, Chef Client, and
|
|
6
|
+
# Puppet.
|
|
7
|
+
class Base
|
|
8
|
+
include Vagrant::Util
|
|
9
|
+
|
|
10
|
+
# The environment which provisioner is running in. This is a
|
|
11
|
+
# {Vagrant::Action::Environment}
|
|
12
|
+
attr_reader :action_env
|
|
13
|
+
|
|
14
|
+
# The configuration for this provisioner. This will be an instance of
|
|
15
|
+
# the `Config` class which is part of the provisioner.
|
|
16
|
+
attr_reader :config
|
|
17
|
+
|
|
18
|
+
# Registers a provisioner with a given shortcut. This allows that provisioner
|
|
19
|
+
# to be referenced with the shortcut.
|
|
20
|
+
#
|
|
21
|
+
# @param [Symbol] shortcut
|
|
22
|
+
def self.register(shortcut)
|
|
23
|
+
registered[shortcut] = self
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the provisioner associated with the given shortcut.
|
|
27
|
+
def self.registered
|
|
28
|
+
@@registered ||= {}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def initialize(env, config)
|
|
32
|
+
@action_env = env
|
|
33
|
+
@config = config
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Returns the actual {Vagrant::Environment} which this provisioner
|
|
37
|
+
# represents.
|
|
38
|
+
#
|
|
39
|
+
# @return [Vagrant::Environment]
|
|
40
|
+
def env
|
|
41
|
+
action_env.env
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Returns the VM which this provisioner is working on.
|
|
45
|
+
#
|
|
46
|
+
# @return [Vagrant::VM]
|
|
47
|
+
def vm
|
|
48
|
+
env.vm
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# This is the method called to "prepare" the provisioner. This is called
|
|
52
|
+
# before any actions are run by the action runner (see {Vagrant::Actions::Runner}).
|
|
53
|
+
# This can be used to setup shared folders, forward ports, etc. Whatever is
|
|
54
|
+
# necessary on a "meta" level.
|
|
55
|
+
def prepare; end
|
|
56
|
+
|
|
57
|
+
# This is the method called to provision the system. This method
|
|
58
|
+
# is expected to do whatever necessary to provision the system (create files,
|
|
59
|
+
# SSH, etc.)
|
|
60
|
+
def provision!; end
|
|
61
|
+
|
|
62
|
+
# This is the method called to when the system is being destroyed
|
|
63
|
+
# and allows the provisioners to engage in any cleanup tasks necessary.
|
|
64
|
+
def cleanup; end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
module Provisioners
|
|
3
|
+
# This class is a base class where the common functionality shared between
|
|
4
|
+
# chef-solo and chef-client provisioning are stored. This is **not an actual
|
|
5
|
+
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
|
|
6
|
+
class Chef < Base
|
|
7
|
+
include Util::Counter
|
|
8
|
+
|
|
9
|
+
def initialize(env, config)
|
|
10
|
+
super
|
|
11
|
+
|
|
12
|
+
config.provisioning_path ||= "/tmp/vagrant-chef-#{get_and_update_counter(:provisioning_path)}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def prepare
|
|
16
|
+
raise ChefError, :invalid_provisioner
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def verify_binary(binary)
|
|
20
|
+
vm.ssh.execute do |ssh|
|
|
21
|
+
# Checks for the existence of chef binary and error if it
|
|
22
|
+
# doesn't exist.
|
|
23
|
+
ssh.sudo!("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Returns the path to the Chef binary, taking into account the
|
|
28
|
+
# `binary_path` configuration option.
|
|
29
|
+
def chef_binary_path(binary)
|
|
30
|
+
return binary if !config.binary_path
|
|
31
|
+
return File.join(config.binary_path, binary)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def chown_provisioning_folder
|
|
35
|
+
vm.ssh.execute do |ssh|
|
|
36
|
+
ssh.sudo!("mkdir -p #{config.provisioning_path}")
|
|
37
|
+
ssh.sudo!("chown #{env.config.ssh.username} #{config.provisioning_path}")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def setup_config(template, filename, template_vars)
|
|
42
|
+
config_file = TemplateRenderer.render(template, {
|
|
43
|
+
:log_level => config.log_level.to_sym,
|
|
44
|
+
:http_proxy => config.http_proxy,
|
|
45
|
+
:http_proxy_user => config.http_proxy_user,
|
|
46
|
+
:http_proxy_pass => config.http_proxy_pass,
|
|
47
|
+
:https_proxy => config.https_proxy,
|
|
48
|
+
:https_proxy_user => config.https_proxy_user,
|
|
49
|
+
:https_proxy_pass => config.https_proxy_pass,
|
|
50
|
+
:no_proxy => config.no_proxy
|
|
51
|
+
}.merge(template_vars))
|
|
52
|
+
|
|
53
|
+
vm.ssh.upload!(StringIO.new(config_file), File.join(config.provisioning_path, filename))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def setup_json
|
|
57
|
+
env.ui.info I18n.t("vagrant.provisioners.chef.json")
|
|
58
|
+
|
|
59
|
+
# Set up initial configuration
|
|
60
|
+
data = {
|
|
61
|
+
:config => env.config.to_hash,
|
|
62
|
+
:directory => env.config.vm.shared_folders["v-root"][:guestpath],
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# And wrap it under the "vagrant" namespace
|
|
66
|
+
data = { :vagrant => data }
|
|
67
|
+
|
|
68
|
+
# Merge with the "extra data" which isn't put under the
|
|
69
|
+
# vagrant namespace by default
|
|
70
|
+
data.merge!(config.merged_json)
|
|
71
|
+
|
|
72
|
+
json = data.to_json
|
|
73
|
+
|
|
74
|
+
vm.ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json"))
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class Chef < Base
|
|
79
|
+
class ChefError < Errors::VagrantError
|
|
80
|
+
error_namespace("vagrant.provisioners.chef")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
class Chef < Base
|
|
85
|
+
# This is the configuration which is available through `config.chef`
|
|
86
|
+
class Config < Vagrant::Config::Base
|
|
87
|
+
# Shared config
|
|
88
|
+
attr_accessor :node_name
|
|
89
|
+
attr_accessor :provisioning_path
|
|
90
|
+
attr_accessor :log_level
|
|
91
|
+
attr_accessor :json
|
|
92
|
+
attr_accessor :http_proxy
|
|
93
|
+
attr_accessor :http_proxy_user
|
|
94
|
+
attr_accessor :http_proxy_pass
|
|
95
|
+
attr_accessor :https_proxy
|
|
96
|
+
attr_accessor :https_proxy_user
|
|
97
|
+
attr_accessor :https_proxy_pass
|
|
98
|
+
attr_accessor :no_proxy
|
|
99
|
+
attr_accessor :binary_path
|
|
100
|
+
attr_accessor :binary_env
|
|
101
|
+
attr_writer :run_list
|
|
102
|
+
|
|
103
|
+
def initialize
|
|
104
|
+
@provisioning_path = nil
|
|
105
|
+
@log_level = :info
|
|
106
|
+
@json = {}
|
|
107
|
+
@http_proxy = nil
|
|
108
|
+
@http_proxy_user = nil
|
|
109
|
+
@http_proxy_pass = nil
|
|
110
|
+
@https_proxy = nil
|
|
111
|
+
@https_proxy_user = nil
|
|
112
|
+
@https_proxy_pass = nil
|
|
113
|
+
@no_proxy = nil
|
|
114
|
+
@binary_path = nil
|
|
115
|
+
@binary_env = nil
|
|
116
|
+
@run_list = nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# This returns the json that is merged with the defaults and the
|
|
120
|
+
# user set data.
|
|
121
|
+
def merged_json
|
|
122
|
+
original = { :instance_role => "vagrant" }
|
|
123
|
+
original[:run_list] = @run_list if @run_list
|
|
124
|
+
original.merge(json || {})
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Returns the run list, but also sets it up to be empty if it
|
|
128
|
+
# hasn't been defined already.
|
|
129
|
+
def run_list
|
|
130
|
+
@run_list ||= []
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Adds a recipe to the run list
|
|
134
|
+
def add_recipe(name)
|
|
135
|
+
name = "recipe[#{name}]" unless name =~ /^recipe\[(.+?)\]$/
|
|
136
|
+
run_list << name
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Adds a role to the run list
|
|
140
|
+
def add_role(name)
|
|
141
|
+
name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/
|
|
142
|
+
run_list << name
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def instance_variables_hash
|
|
146
|
+
# Overridden so that the 'json' key could be removed, since its just
|
|
147
|
+
# merged into the config anyways
|
|
148
|
+
result = super
|
|
149
|
+
result.delete("json")
|
|
150
|
+
result
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|