boxcar 0.10005.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +48 -0
- data/.gitsetup.yml +6 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +696 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +40 -0
- data/LICENSE +21 -0
- data/README.md +91 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/bin/_bump +126 -0
- data/bin/_jason +172 -0
- data/bin/_log4sh +3840 -0
- data/bin/_meat +172 -0
- data/bin/_prime +8 -0
- data/bin/_shflags +1012 -0
- data/bin/_shunit +1048 -0
- data/bin/_sub +37 -0
- data/bin/_treadstone +8 -0
- data/bin/_versions +174 -0
- data/bin/build +15 -0
- data/bin/bump +15 -0
- data/bin/edit +15 -0
- data/bin/publish +15 -0
- data/bin/stub +15 -0
- data/bin/vagrant +60 -0
- data/boxcar.gemspec +32 -0
- data/config/default.rb +30 -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.pub +1 -0
- data/lib/development.rb +25 -0
- data/lib/vagrant.rb +197 -0
- data/lib/vagrant/action.rb +63 -0
- data/lib/vagrant/action/box/destroy.rb +25 -0
- data/lib/vagrant/action/box/download.rb +84 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +61 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +128 -0
- data/lib/vagrant/action/builtin.rb +171 -0
- data/lib/vagrant/action/env/set.rb +21 -0
- data/lib/vagrant/action/environment.rb +12 -0
- data/lib/vagrant/action/general/check_virtualbox.rb +28 -0
- data/lib/vagrant/action/general/package.rb +101 -0
- data/lib/vagrant/action/general/validate.rb +18 -0
- data/lib/vagrant/action/runner.rb +53 -0
- data/lib/vagrant/action/vm/boot.rb +53 -0
- data/lib/vagrant/action/vm/check_accessible.rb +23 -0
- data/lib/vagrant/action/vm/check_box.rb +33 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +38 -0
- data/lib/vagrant/action/vm/check_port_collisions.rb +89 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +18 -0
- data/lib/vagrant/action/vm/clear_network_interfaces.rb +31 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +18 -0
- data/lib/vagrant/action/vm/customize.rb +36 -0
- data/lib/vagrant/action/vm/default_name.rb +22 -0
- data/lib/vagrant/action/vm/destroy.rb +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +20 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +57 -0
- data/lib/vagrant/action/vm/forward_ports.rb +92 -0
- data/lib/vagrant/action/vm/halt.rb +32 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +48 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
- data/lib/vagrant/action/vm/network.rb +403 -0
- data/lib/vagrant/action/vm/nfs.rb +196 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +36 -0
- data/lib/vagrant/action/vm/provision.rb +61 -0
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
- data/lib/vagrant/action/vm/prune_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/sane_defaults.rb +78 -0
- data/lib/vagrant/action/vm/setup_package_files.rb +54 -0
- data/lib/vagrant/action/vm/share_folders.rb +114 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +92 -0
- data/lib/vagrant/box.rb +44 -0
- data/lib/vagrant/box_collection.rb +58 -0
- data/lib/vagrant/cli.rb +76 -0
- data/lib/vagrant/command.rb +24 -0
- data/lib/vagrant/command/base.rb +167 -0
- data/lib/vagrant/command/box.rb +58 -0
- data/lib/vagrant/command/box_add.rb +37 -0
- data/lib/vagrant/command/box_list.rb +28 -0
- data/lib/vagrant/command/box_remove.rb +27 -0
- data/lib/vagrant/command/box_repackage.rb +27 -0
- data/lib/vagrant/command/destroy.rb +64 -0
- data/lib/vagrant/command/gem.rb +39 -0
- data/lib/vagrant/command/halt.rb +39 -0
- data/lib/vagrant/command/init.rb +40 -0
- data/lib/vagrant/command/package.rb +75 -0
- data/lib/vagrant/command/provision.rb +40 -0
- data/lib/vagrant/command/reload.rb +39 -0
- data/lib/vagrant/command/resume.rb +33 -0
- data/lib/vagrant/command/ssh.rb +90 -0
- data/lib/vagrant/command/ssh_config.rb +51 -0
- data/lib/vagrant/command/start_mixins.rb +26 -0
- data/lib/vagrant/command/status.rb +36 -0
- data/lib/vagrant/command/suspend.rb +33 -0
- data/lib/vagrant/command/up.rb +40 -0
- data/lib/vagrant/communication.rb +7 -0
- data/lib/vagrant/communication/base.rb +56 -0
- data/lib/vagrant/communication/ssh.rb +229 -0
- data/lib/vagrant/config.rb +49 -0
- data/lib/vagrant/config/base.rb +82 -0
- data/lib/vagrant/config/container.rb +37 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/loader.rb +127 -0
- data/lib/vagrant/config/nfs.rb +8 -0
- data/lib/vagrant/config/package.rb +7 -0
- data/lib/vagrant/config/ssh.rb +27 -0
- data/lib/vagrant/config/top.rb +72 -0
- data/lib/vagrant/config/vagrant.rb +14 -0
- data/lib/vagrant/config/vm.rb +168 -0
- data/lib/vagrant/config/vm/provisioner.rb +52 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +92 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +25 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +97 -0
- data/lib/vagrant/driver.rb +8 -0
- data/lib/vagrant/driver/virtualbox.rb +134 -0
- data/lib/vagrant/driver/virtualbox_4_0.rb +459 -0
- data/lib/vagrant/driver/virtualbox_4_1.rb +459 -0
- data/lib/vagrant/driver/virtualbox_4_2.rb +606 -0
- data/lib/vagrant/driver/virtualbox_base.rb +309 -0
- data/lib/vagrant/environment.rb +517 -0
- data/lib/vagrant/errors.rb +441 -0
- data/lib/vagrant/guest.rb +18 -0
- data/lib/vagrant/guest/arch.rb +56 -0
- data/lib/vagrant/guest/base.rb +99 -0
- data/lib/vagrant/guest/debian.rb +64 -0
- data/lib/vagrant/guest/fedora.rb +66 -0
- data/lib/vagrant/guest/freebsd.rb +86 -0
- data/lib/vagrant/guest/gentoo.rb +46 -0
- data/lib/vagrant/guest/linux.rb +118 -0
- data/lib/vagrant/guest/linux/config.rb +19 -0
- data/lib/vagrant/guest/linux/error.rb +9 -0
- data/lib/vagrant/guest/openbsd.rb +20 -0
- data/lib/vagrant/guest/redhat.rb +67 -0
- data/lib/vagrant/guest/solaris.rb +118 -0
- data/lib/vagrant/guest/suse.rb +9 -0
- data/lib/vagrant/guest/ubuntu.rb +23 -0
- data/lib/vagrant/hosts.rb +37 -0
- data/lib/vagrant/hosts/arch.rb +55 -0
- data/lib/vagrant/hosts/base.rb +66 -0
- data/lib/vagrant/hosts/bsd.rb +97 -0
- data/lib/vagrant/hosts/fedora.rb +47 -0
- data/lib/vagrant/hosts/freebsd.rb +41 -0
- data/lib/vagrant/hosts/gentoo.rb +20 -0
- data/lib/vagrant/hosts/linux.rb +94 -0
- data/lib/vagrant/hosts/opensuse.rb +30 -0
- data/lib/vagrant/hosts/windows.rb +16 -0
- data/lib/vagrant/plugin.rb +81 -0
- data/lib/vagrant/provisioners.rb +12 -0
- data/lib/vagrant/provisioners/base.rb +44 -0
- data/lib/vagrant/provisioners/chef.rb +168 -0
- data/lib/vagrant/provisioners/chef_client.rb +132 -0
- data/lib/vagrant/provisioners/chef_solo.rb +234 -0
- data/lib/vagrant/provisioners/puppet.rb +175 -0
- data/lib/vagrant/provisioners/puppet_server.rb +78 -0
- data/lib/vagrant/provisioners/shell.rb +96 -0
- data/lib/vagrant/registry.rb +52 -0
- data/lib/vagrant/ssh.rb +126 -0
- data/lib/vagrant/test_helpers.rb +154 -0
- data/lib/vagrant/ui.rb +168 -0
- data/lib/vagrant/util.rb +12 -0
- data/lib/vagrant/util/ansi_escape_code_remover.rb +34 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/counter.rb +24 -0
- data/lib/vagrant/util/file_checksum.rb +38 -0
- data/lib/vagrant/util/file_mode.rb +12 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/is_port_open.rb +38 -0
- data/lib/vagrant/util/line_ending_helpers.rb +14 -0
- data/lib/vagrant/util/network_ip.rb +28 -0
- data/lib/vagrant/util/platform.rb +68 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/safe_exec.rb +36 -0
- data/lib/vagrant/util/safe_puts.rb +31 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/subprocess.rb +247 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +7 -0
- data/lib/vagrant/vm.rb +195 -0
- data/libexec/build +30 -0
- data/libexec/build-gem +30 -0
- data/libexec/bump +32 -0
- data/libexec/edit-gem +81 -0
- data/libexec/publish +58 -0
- data/libexec/publish-gem +58 -0
- data/libexec/stub-prepare +37 -0
- data/tasks/acceptance.rake +113 -0
- data/tasks/bundler.rake +3 -0
- data/tasks/test.rake +20 -0
- data/templates/commands/init/Vagrantfile.erb +99 -0
- data/templates/commands/ssh_config/config.erb +15 -0
- data/templates/config/validation_failed.erb +7 -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/fedora/network_dhcp.erb +6 -0
- data/templates/guests/fedora/network_static.erb +13 -0
- data/templates/guests/freebsd/network_dhcp.erb +3 -0
- data/templates/guests/freebsd/network_static.erb +3 -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 +747 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_freebsd.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/provisioners/chef_client/client.erb +32 -0
- data/templates/provisioners/chef_solo/solo.erb +25 -0
- data/test/acceptance/base.rb +48 -0
- data/test/acceptance/box_test.rb +99 -0
- data/test/acceptance/destroy_test.rb +37 -0
- data/test/acceptance/halt_test.rb +72 -0
- data/test/acceptance/init_test.rb +33 -0
- 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 +17 -0
- data/test/acceptance/shared_folders_test.rb +84 -0
- 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 +46 -0
- data/test/acceptance/support/config.rb +42 -0
- data/test/acceptance/support/isolated_environment.rb +117 -0
- data/test/acceptance/support/matchers/have_color.rb +9 -0
- data/test/acceptance/support/matchers/match_output.rb +14 -0
- data/test/acceptance/support/matchers/succeed.rb +14 -0
- data/test/acceptance/support/network_tests.rb +29 -0
- data/test/acceptance/support/output.rb +95 -0
- data/test/acceptance/support/shared/base_context.rb +72 -0
- data/test/acceptance/support/shared/command_examples.rb +33 -0
- data/test/acceptance/support/virtualbox.rb +36 -0
- data/test/acceptance/suspend_test.rb +56 -0
- data/test/acceptance/up_basic_test.rb +33 -0
- data/test/acceptance/up_with_box_url.rb +40 -0
- data/test/acceptance/vagrant_test.rb +47 -0
- data/test/acceptance/version_test.rb +15 -0
- data/test/buildbot/README.md +72 -0
- data/test/buildbot/buildbot_config/__init__.py +0 -0
- data/test/buildbot/buildbot_config/config/__init__.py +0 -0
- data/test/buildbot/buildbot_config/config/loader.py +24 -0
- data/test/buildbot/buildbot_config/config/master.py +24 -0
- data/test/buildbot/buildbot_config/config/slave.py +22 -0
- data/test/buildbot/buildbot_config/master/__init__.py +6 -0
- data/test/buildbot/buildbot_config/master/builders.py +78 -0
- data/test/buildbot/buildbot_config/master/buildsteps.py +100 -0
- data/test/buildbot/buildbot_config/master/change_sources.py +8 -0
- data/test/buildbot/buildbot_config/master/schedulers.py +32 -0
- data/test/buildbot/buildbot_config/master/slaves.py +60 -0
- data/test/buildbot/buildbot_config/master/status.py +52 -0
- data/test/buildbot/master/Makefile.sample +28 -0
- data/test/buildbot/master/buildbot.tac +36 -0
- data/test/buildbot/master/master.cfg +67 -0
- data/test/buildbot/master/public_html/bg_gradient.jpg +0 -0
- data/test/buildbot/master/public_html/default.css +545 -0
- data/test/buildbot/master/public_html/favicon.ico +0 -0
- data/test/buildbot/master/public_html/robots.txt +10 -0
- data/test/buildbot/master/public_html/static/css/bootstrap-1.4.0.min.css +356 -0
- data/test/buildbot/master/public_html/static/css/prettify.css +97 -0
- data/test/buildbot/master/public_html/static/css/syntax.css +60 -0
- data/test/buildbot/master/public_html/static/css/vagrant.base.css +205 -0
- data/test/buildbot/master/public_html/static/images/base_box_mac.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/getting-started/success.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/icons/error.png +0 -0
- data/test/buildbot/master/public_html/static/images/vagrant_chilling.png +0 -0
- data/test/buildbot/master/public_html/static/images/vagrant_holding.png +0 -0
- data/test/buildbot/master/public_html/static/images/vagrant_looking.png +0 -0
- data/test/buildbot/master/public_html/static/images/windows/alter_path.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/edit_path.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/environment_variables_button.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/port_and_ppk_path.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/ppk_selection.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/putty_first_screen.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/save_result.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/vbox_manage_default_location.jpg +0 -0
- data/test/buildbot/master/public_html/static/js/bootstrap-tabs.js +80 -0
- data/test/buildbot/master/public_html/static/js/jquery-1.7.min.js +4 -0
- data/test/buildbot/master/templates/authfail.html +9 -0
- data/test/buildbot/master/templates/build.html +205 -0
- data/test/buildbot/master/templates/builder.html +118 -0
- data/test/buildbot/master/templates/builders.html +33 -0
- data/test/buildbot/master/templates/buildslave.html +72 -0
- data/test/buildbot/master/templates/buildslaves.html +70 -0
- data/test/buildbot/master/templates/change.html +15 -0
- data/test/buildbot/master/templates/layouts/base.html +58 -0
- data/test/buildbot/master/templates/macros/box.html +37 -0
- data/test/buildbot/master/templates/macros/build_line.html +50 -0
- data/test/buildbot/master/templates/macros/change.html +81 -0
- data/test/buildbot/master/templates/macros/forms.html +300 -0
- data/test/buildbot/master/templates/root.html +42 -0
- data/test/buildbot/master/templates/waterfall.html +53 -0
- data/test/buildbot/requirements.txt +4 -0
- data/test/buildbot/scripts/deploy.sh +38 -0
- data/test/buildbot/scripts/setup.sh +107 -0
- data/test/buildbot/slave/buildbot.tac +43 -0
- data/test/buildbot/slave/info/admin +1 -0
- data/test/buildbot/slave/info/host +1 -0
- data/test/buildbot/tests/__init__.py +0 -0
- data/test/buildbot/tests/master/__init__.py +0 -0
- data/test/buildbot/tests/master/test_slaves.py +41 -0
- data/test/buildbot/vendor/choices-0.4.0.tar.gz +0 -0
- data/test/config/acceptance_boxes.yml +7 -0
- data/test/support/isolated_environment.rb +46 -0
- data/test/support/tempdir.rb +34 -0
- data/test/unit/base.rb +21 -0
- data/test/unit/support/isolated_environment.rb +47 -0
- data/test/unit/support/shared/base_context.rb +30 -0
- data/test/unit/vagrant/action/builder_test.rb +156 -0
- data/test/unit/vagrant/action/environment_test.rb +16 -0
- data/test/unit/vagrant/action/runner_test.rb +65 -0
- data/test/unit/vagrant/action/warden_test.rb +92 -0
- data/test/unit/vagrant/box_collection_test.rb +56 -0
- data/test/unit/vagrant/box_test.rb +34 -0
- data/test/unit/vagrant/command/base_test.rb +150 -0
- data/test/unit/vagrant/config/base_test.rb +48 -0
- data/test/unit/vagrant/config/loader_test.rb +79 -0
- data/test/unit/vagrant/config/ssh_test.rb +17 -0
- data/test/unit/vagrant/config/top_test.rb +69 -0
- data/test/unit/vagrant/config/vm_test.rb +71 -0
- data/test/unit/vagrant/config_test.rb +27 -0
- data/test/unit/vagrant/data_store_test.rb +79 -0
- data/test/unit/vagrant/downloaders/base_test.rb +18 -0
- data/test/unit/vagrant/downloaders/file_test.rb +75 -0
- data/test/unit/vagrant/downloaders/http_test.rb +19 -0
- data/test/unit/vagrant/environment_test.rb +212 -0
- data/test/unit/vagrant/hosts_test.rb +36 -0
- data/test/unit/vagrant/registry_test.rb +74 -0
- data/test/unit/vagrant/util/ansi_escape_code_remover_test.rb +16 -0
- data/test/unit/vagrant/util/file_checksum_test.rb +23 -0
- data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +38 -0
- data/test/unit/vagrant/util/is_port_open_test.rb +53 -0
- data/test/unit/vagrant/util/line_endings_helper_test.rb +16 -0
- data/test/unit/vagrant/util/network_ip_test.rb +17 -0
- data/test/unit/vagrant/util/retryable_test.rb +106 -0
- data/test/unit/vagrant_test.rb +27 -0
- data/test/unit_legacy/locales/en.yml +8 -0
- data/test/unit_legacy/test_helper.rb +32 -0
- data/test/unit_legacy/vagrant/action/box/destroy_test.rb +18 -0
- data/test/unit_legacy/vagrant/action/box/download_test.rb +125 -0
- data/test/unit_legacy/vagrant/action/box/package_test.rb +25 -0
- data/test/unit_legacy/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/unit_legacy/vagrant/action/box/verify_test.rb +30 -0
- data/test/unit_legacy/vagrant/action/env/set_test.rb +24 -0
- data/test/unit_legacy/vagrant/action/general/package_test.rb +268 -0
- data/test/unit_legacy/vagrant/action/general/validate_test.rb +31 -0
- data/test/unit_legacy/vagrant/action/vm/boot_test.rb +66 -0
- data/test/unit_legacy/vagrant/action/vm/check_accessible_test.rb +61 -0
- data/test/unit_legacy/vagrant/action/vm/check_box_test.rb +61 -0
- data/test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb +52 -0
- data/test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb +40 -0
- data/test/unit_legacy/vagrant/action/vm/customize_test.rb +37 -0
- data/test/unit_legacy/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/unit_legacy/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/unit_legacy/vagrant/action/vm/export_test.rb +107 -0
- data/test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb +77 -0
- data/test/unit_legacy/vagrant/action/vm/forward_ports_test.rb +197 -0
- data/test/unit_legacy/vagrant/action/vm/halt_test.rb +79 -0
- data/test/unit_legacy/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/unit_legacy/vagrant/action/vm/import_test.rb +66 -0
- data/test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb +40 -0
- data/test/unit_legacy/vagrant/action/vm/modify_test.rb +38 -0
- data/test/unit_legacy/vagrant/action/vm/network_test.rb +286 -0
- data/test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/unit_legacy/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/unit_legacy/vagrant/action/vm/package_test.rb +25 -0
- data/test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/unit_legacy/vagrant/action/vm/provision_test.rb +65 -0
- data/test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
- data/test/unit_legacy/vagrant/action/vm/resume_test.rb +35 -0
- data/test/unit_legacy/vagrant/action/vm/share_folders_test.rb +144 -0
- data/test/unit_legacy/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/unit_legacy/vagrant/action_test.rb +89 -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_legacy/vagrant/cli_test.rb +35 -0
- data/test/unit_legacy/vagrant/command/base_test.rb +23 -0
- data/test/unit_legacy/vagrant/command/group_base_test.rb +15 -0
- data/test/unit_legacy/vagrant/command/helpers_test.rb +88 -0
- data/test/unit_legacy/vagrant/command/init_test.rb +10 -0
- data/test/unit_legacy/vagrant/command/package_test.rb +27 -0
- data/test/unit_legacy/vagrant/config/base_test.rb +52 -0
- data/test/unit_legacy/vagrant/config/error_recorder_test.rb +18 -0
- data/test/unit_legacy/vagrant/config/ssh_test.rb +12 -0
- data/test/unit_legacy/vagrant/config/vagrant_test.rb +35 -0
- data/test/unit_legacy/vagrant/config/vm/provisioner_test.rb +92 -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_legacy/vagrant/errors_test.rb +42 -0
- data/test/unit_legacy/vagrant/hosts/base_test.rb +46 -0
- data/test/unit_legacy/vagrant/hosts/bsd_test.rb +53 -0
- data/test/unit_legacy/vagrant/hosts/linux_test.rb +54 -0
- data/test/unit_legacy/vagrant/plugin_test.rb +9 -0
- data/test/unit_legacy/vagrant/provisioners/base_test.rb +63 -0
- data/test/unit_legacy/vagrant/provisioners/chef_client_test.rb +190 -0
- data/test/unit_legacy/vagrant/provisioners/chef_solo_test.rb +115 -0
- data/test/unit_legacy/vagrant/provisioners/chef_test.rb +209 -0
- data/test/unit_legacy/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/unit_legacy/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/unit_legacy/vagrant/provisioners/shell_test.rb +79 -0
- data/test/unit_legacy/vagrant/ssh/session_test.rb +40 -0
- data/test/unit_legacy/vagrant/ssh_test.rb +304 -0
- data/test/unit_legacy/vagrant/systems/base_test.rb +18 -0
- data/test/unit_legacy/vagrant/systems/linux_test.rb +104 -0
- data/test/unit_legacy/vagrant/util/busy_test.rb +106 -0
- data/test/unit_legacy/vagrant/util/counter_test.rb +29 -0
- data/test/unit_legacy/vagrant/util/platform_test.rb +18 -0
- data/test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/unit_legacy/vagrant/util/template_renderer_test.rb +145 -0
- data/test/unit_legacy/vagrant/vm_test.rb +300 -0
- data/vagrant.gemspec +39 -0
- data/vendor/cache/contest-0.1.3.gem +0 -0
- data/vendor/cache/diff-lcs-1.1.3.gem +0 -0
- data/vendor/cache/erubis-2.7.0.gem +0 -0
- data/vendor/cache/i18n-0.6.1.gem +0 -0
- data/vendor/cache/json-1.5.4.gem +0 -0
- data/vendor/cache/log4r-1.1.10.gem +0 -0
- data/vendor/cache/metaclass-0.0.1.gem +0 -0
- data/vendor/cache/minitest-2.5.1.gem +0 -0
- data/vendor/cache/mocha-0.13.1.gem +0 -0
- data/vendor/cache/rake-10.0.2.gem +0 -0
- data/vendor/cache/rspec-core-2.8.0.gem +0 -0
- data/vendor/cache/rspec-expectations-2.8.0.gem +0 -0
- data/vendor/cache/rspec-mocks-2.8.0.gem +0 -0
- metadata +676 -0
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'net/ssh'
|
5
|
+
require 'net/scp'
|
6
|
+
|
7
|
+
require 'vagrant/util/ansi_escape_code_remover'
|
8
|
+
require 'vagrant/util/file_mode'
|
9
|
+
require 'vagrant/util/platform'
|
10
|
+
require 'vagrant/util/retryable'
|
11
|
+
|
12
|
+
module Vagrant
|
13
|
+
module Communication
|
14
|
+
# Provides communication with the VM via SSH.
|
15
|
+
class SSH < Base
|
16
|
+
include Util::ANSIEscapeCodeRemover
|
17
|
+
include Util::Retryable
|
18
|
+
|
19
|
+
def initialize(vm)
|
20
|
+
@vm = vm
|
21
|
+
@logger = Log4r::Logger.new("vagrant::communication::ssh")
|
22
|
+
@connection = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def ready?
|
26
|
+
@logger.debug("Checking whether SSH is ready...")
|
27
|
+
|
28
|
+
Timeout.timeout(@vm.config.ssh.timeout) do
|
29
|
+
connect
|
30
|
+
end
|
31
|
+
|
32
|
+
# If we reached this point then we successfully connected
|
33
|
+
@logger.info("SSH is ready!")
|
34
|
+
true
|
35
|
+
rescue Timeout::Error, Errors::SSHConnectionRefused, Net::SSH::Disconnect => e
|
36
|
+
# The above errors represent various reasons that SSH may not be
|
37
|
+
# ready yet. Return false.
|
38
|
+
@logger.info("SSH not up: #{e.inspect}")
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(command, opts=nil, &block)
|
43
|
+
opts = {
|
44
|
+
:error_check => true,
|
45
|
+
:error_class => Errors::VagrantError,
|
46
|
+
:error_key => :ssh_bad_exit_status,
|
47
|
+
:command => command,
|
48
|
+
:sudo => false
|
49
|
+
}.merge(opts || {})
|
50
|
+
|
51
|
+
# Connect via SSH and execute the command in the shell.
|
52
|
+
exit_status = connect do |connection|
|
53
|
+
shell_execute(connection, command, opts[:sudo], &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Check for any errors
|
57
|
+
if opts[:error_check] && exit_status != 0
|
58
|
+
# The error classes expect the translation key to be _key,
|
59
|
+
# but that makes for an ugly configuration parameter, so we
|
60
|
+
# set it here from `error_key`
|
61
|
+
error_opts = opts.merge(:_key => opts[:error_key])
|
62
|
+
raise opts[:error_class], error_opts
|
63
|
+
end
|
64
|
+
|
65
|
+
# Return the exit status
|
66
|
+
exit_status
|
67
|
+
end
|
68
|
+
|
69
|
+
def sudo(command, opts=nil, &block)
|
70
|
+
# Run `execute` but with the `sudo` option.
|
71
|
+
opts = { :sudo => true }.merge(opts || {})
|
72
|
+
execute(command, opts, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
def upload(from, to)
|
76
|
+
@logger.debug("Uploading: #{from} to #{to}")
|
77
|
+
|
78
|
+
# Do an SCP-based upload...
|
79
|
+
connect do |connection|
|
80
|
+
scp = Net::SCP.new(connection)
|
81
|
+
scp.upload!(from, to)
|
82
|
+
end
|
83
|
+
rescue Net::SCP::Error => e
|
84
|
+
# If we get the exit code of 127, then this means SCP is unavailable.
|
85
|
+
raise Errors::SCPUnavailable if e.message =~ /\(127\)/
|
86
|
+
|
87
|
+
# Otherwise, just raise the error up
|
88
|
+
raise
|
89
|
+
end
|
90
|
+
|
91
|
+
protected
|
92
|
+
|
93
|
+
# Opens an SSH connection and yields it to a block.
|
94
|
+
def connect
|
95
|
+
if @connection && !@connection.closed?
|
96
|
+
# There is a chance that the socket is closed despite us checking
|
97
|
+
# 'closed?' above. To test this we need to send data through the
|
98
|
+
# socket.
|
99
|
+
begin
|
100
|
+
@connection.exec!("")
|
101
|
+
rescue IOError
|
102
|
+
@logger.info("Connection has been closed. Not re-using.")
|
103
|
+
@connection = nil
|
104
|
+
end
|
105
|
+
|
106
|
+
# If the @connection is still around, then it is valid,
|
107
|
+
# and we use it.
|
108
|
+
if @connection
|
109
|
+
@logger.debug("Re-using SSH connection.")
|
110
|
+
return yield @connection if block_given?
|
111
|
+
return
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
ssh_info = @vm.ssh.info
|
116
|
+
|
117
|
+
# Build the options we'll use to initiate the connection via Net::SSH
|
118
|
+
opts = {
|
119
|
+
:port => ssh_info[:port],
|
120
|
+
:keys => [ssh_info[:private_key_path]],
|
121
|
+
:keys_only => true,
|
122
|
+
:user_known_hosts_file => [],
|
123
|
+
:paranoid => false,
|
124
|
+
:config => false,
|
125
|
+
:forward_agent => ssh_info[:forward_agent]
|
126
|
+
}
|
127
|
+
|
128
|
+
# Check that the private key permissions are valid
|
129
|
+
@vm.ssh.check_key_permissions(ssh_info[:private_key_path])
|
130
|
+
|
131
|
+
# Connect to SSH, giving it a few tries
|
132
|
+
connection = nil
|
133
|
+
begin
|
134
|
+
# These are the exceptions that we retry because they represent
|
135
|
+
# errors that are generally fixed from a retry and don't
|
136
|
+
# necessarily represent immediate failure cases.
|
137
|
+
exceptions = [
|
138
|
+
Errno::ECONNREFUSED,
|
139
|
+
Errno::EHOSTUNREACH,
|
140
|
+
Net::SSH::Disconnect,
|
141
|
+
Timeout::Error
|
142
|
+
]
|
143
|
+
|
144
|
+
@logger.info("Connecting to SSH: #{ssh_info[:host]}:#{ssh_info[:port]}")
|
145
|
+
connection = retryable(:tries => @vm.config.ssh.max_tries, :on => exceptions) do
|
146
|
+
Net::SSH.start(ssh_info[:host], ssh_info[:username], opts)
|
147
|
+
end
|
148
|
+
rescue Net::SSH::AuthenticationFailed
|
149
|
+
# This happens if authentication failed. We wrap the error in our
|
150
|
+
# own exception.
|
151
|
+
raise Errors::SSHAuthenticationFailed
|
152
|
+
rescue Errno::ECONNREFUSED
|
153
|
+
# This is raised if we failed to connect the max amount of times
|
154
|
+
raise Errors::SSHConnectionRefused
|
155
|
+
rescue NotImplementedError
|
156
|
+
# This is raised if a private key type that Net-SSH doesn't support
|
157
|
+
# is used. Show a nicer error.
|
158
|
+
raise Errors::SSHKeyTypeNotSupported
|
159
|
+
end
|
160
|
+
|
161
|
+
@connection = connection
|
162
|
+
|
163
|
+
# This is hacky but actually helps with some issues where
|
164
|
+
# Net::SSH is simply not robust enough to handle... see
|
165
|
+
# issue #391, #455, etc.
|
166
|
+
sleep 4
|
167
|
+
|
168
|
+
# Yield the connection that is ready to be used and
|
169
|
+
# return the value of the block
|
170
|
+
return yield connection if block_given?
|
171
|
+
end
|
172
|
+
|
173
|
+
# Executes the command on an SSH connection within a login shell.
|
174
|
+
def shell_execute(connection, command, sudo=false)
|
175
|
+
@logger.info("Execute: #{command} (sudo=#{sudo.inspect})")
|
176
|
+
exit_status = nil
|
177
|
+
|
178
|
+
# Determine the shell to execute. If we are using `sudo` then we
|
179
|
+
# need to wrap the shell in a `sudo` call.
|
180
|
+
shell = "#{@vm.config.ssh.shell} -l"
|
181
|
+
shell = "sudo -H #{shell}" if sudo
|
182
|
+
|
183
|
+
# Open the channel so we can execute or command
|
184
|
+
channel = connection.open_channel do |ch|
|
185
|
+
ch.exec(shell) do |ch2, _|
|
186
|
+
# Setup the channel callbacks so we can get data and exit status
|
187
|
+
ch2.on_data do |ch3, data|
|
188
|
+
if block_given?
|
189
|
+
# Filter out the clear screen command
|
190
|
+
data = remove_ansi_escape_codes(data)
|
191
|
+
@logger.debug("stdout: #{data}")
|
192
|
+
yield :stdout, data
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
ch2.on_extended_data do |ch3, type, data|
|
197
|
+
if block_given?
|
198
|
+
# Filter out the clear screen command
|
199
|
+
data = remove_ansi_escape_codes(data)
|
200
|
+
@logger.debug("stderr: #{data}")
|
201
|
+
yield :stderr, data
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
ch2.on_request("exit-status") do |ch3, data|
|
206
|
+
exit_status = data.read_long
|
207
|
+
@logger.debug("Exit status: #{exit_status}")
|
208
|
+
end
|
209
|
+
|
210
|
+
# Set the terminal
|
211
|
+
ch2.send_data "export TERM=vt100\n"
|
212
|
+
|
213
|
+
# Output the command
|
214
|
+
ch2.send_data "#{command}\n"
|
215
|
+
|
216
|
+
# Remember to exit or this channel will hang open
|
217
|
+
ch2.send_data "exit\n"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Wait for the channel to complete
|
222
|
+
channel.wait
|
223
|
+
|
224
|
+
# Return the final exit status
|
225
|
+
return exit_status
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Config
|
3
|
+
autoload :Base, 'vagrant/config/base'
|
4
|
+
autoload :Container, 'vagrant/config/container'
|
5
|
+
autoload :ErrorRecorder, 'vagrant/config/error_recorder'
|
6
|
+
autoload :Loader, 'vagrant/config/loader'
|
7
|
+
autoload :Top, 'vagrant/config/top'
|
8
|
+
|
9
|
+
autoload :NFSConfig, 'vagrant/config/nfs'
|
10
|
+
autoload :PackageConfig, 'vagrant/config/package'
|
11
|
+
autoload :SSHConfig, 'vagrant/config/ssh'
|
12
|
+
autoload :VagrantConfig, 'vagrant/config/vagrant'
|
13
|
+
autoload :VMConfig, 'vagrant/config/vm'
|
14
|
+
|
15
|
+
CONFIGURE_MUTEX = Mutex.new
|
16
|
+
|
17
|
+
# This is the method which is called by all Vagrantfiles to configure Vagrant.
|
18
|
+
# This method expects a block which accepts a single argument representing
|
19
|
+
# an instance of the {Config::Top} class.
|
20
|
+
#
|
21
|
+
# Note that the block is not run immediately. Instead, it's proc is stored
|
22
|
+
# away for execution later.
|
23
|
+
def self.run(&block)
|
24
|
+
# Store it for later
|
25
|
+
@last_procs ||= []
|
26
|
+
@last_procs << block
|
27
|
+
end
|
28
|
+
|
29
|
+
# This is a method which will yield to a block and will capture all
|
30
|
+
# ``Vagrant.configure`` calls, returning an array of `Proc`s.
|
31
|
+
#
|
32
|
+
# Wrapping this around anytime you call code which loads configurations
|
33
|
+
# will force a mutex so that procs never get mixed up. This keeps
|
34
|
+
# the configuration loading part of Vagrant thread-safe.
|
35
|
+
def self.capture_configures
|
36
|
+
CONFIGURE_MUTEX.synchronize do
|
37
|
+
# Reset the last procs so that we start fresh
|
38
|
+
@last_procs = []
|
39
|
+
|
40
|
+
# Yield to allow the caller to do whatever loading needed
|
41
|
+
yield
|
42
|
+
|
43
|
+
# Return the last procs we've seen while still in the mutex,
|
44
|
+
# knowing we're safe.
|
45
|
+
return @last_procs
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Config
|
3
|
+
# The base class for all configuration classes. This implements
|
4
|
+
# basic things such as the environment instance variable which all
|
5
|
+
# config classes need as well as a basic `to_json` implementation.
|
6
|
+
class Base
|
7
|
+
# Loads configuration values from JSON back into the proper
|
8
|
+
# configuration classes. By default, this is done by simply
|
9
|
+
# iterating over all values in the JSON hash and assigning them
|
10
|
+
# to instance variables on the class.
|
11
|
+
def self.json_create(data)
|
12
|
+
data.inject(new) do |result, data|
|
13
|
+
key, value = data
|
14
|
+
result.instance_variable_set("@#{key}".to_sym, value) if key != "json_class"
|
15
|
+
result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Allows setting options from a hash. By default this simply calls
|
20
|
+
# the `#{key}=` method on the config class with the value, which is
|
21
|
+
# the expected behavior most of the time.
|
22
|
+
def set_options(options)
|
23
|
+
options.each do |key, value|
|
24
|
+
send("#{key}=", value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Merge another configuration object into this one.
|
29
|
+
#
|
30
|
+
# @param [Object] other The other configuration object to merge from,
|
31
|
+
# this must be the same type of object as this one.
|
32
|
+
# @return [Object] The merged object.
|
33
|
+
def merge(other)
|
34
|
+
result = self.class.new
|
35
|
+
instance_variables_hash.merge(other.instance_variables_hash).each do |key, value|
|
36
|
+
# Ignore keys that start with a double underscore. This allows
|
37
|
+
# configuration classes to still hold around internal state
|
38
|
+
# that isn't propagated.
|
39
|
+
if !key.start_with?("__")
|
40
|
+
result.instance_variable_set("@#{key}".to_sym, value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
# Called by {Top} after the configuration is loaded to validate
|
48
|
+
# the configuaration objects. Subclasses should implement this
|
49
|
+
# method and add any errors to the `errors` object given.
|
50
|
+
#
|
51
|
+
# @param [ErrorRecorder] errors
|
52
|
+
def validate(env, errors); end
|
53
|
+
|
54
|
+
# Converts the configuration to a raw hash by calling `#to_hash`
|
55
|
+
# on all instance variables (if it can) and putting them into
|
56
|
+
# a hash.
|
57
|
+
def to_hash
|
58
|
+
instance_variables_hash.inject({}) do |acc, data|
|
59
|
+
k,v = data
|
60
|
+
v = v.to_hash if v.respond_to?(:to_hash)
|
61
|
+
acc[k] = v
|
62
|
+
acc
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Converts to JSON, with the `json_class` field set so that when
|
67
|
+
# the JSON is parsed back, it can be loaded back into the proper class.
|
68
|
+
# See {json_create}.
|
69
|
+
def to_json(*a)
|
70
|
+
instance_variables_hash.to_json(*a)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the instance variables as a hash of key-value pairs.
|
74
|
+
def instance_variables_hash
|
75
|
+
instance_variables.inject({}) do |acc, iv|
|
76
|
+
acc[iv.to_s[1..-1]] = instance_variable_get(iv)
|
77
|
+
acc
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Config
|
3
|
+
# Contains loaded configuration values and provides access to those
|
4
|
+
# values.
|
5
|
+
#
|
6
|
+
# This is the class returned when loading configuration and stores
|
7
|
+
# the completely loaded configuration values. This class is meant to
|
8
|
+
# be immutable.
|
9
|
+
class Container
|
10
|
+
attr_reader :global
|
11
|
+
attr_reader :vms
|
12
|
+
|
13
|
+
# Initializes the configuration container.
|
14
|
+
#
|
15
|
+
# @param [Top] global Top-level configuration for the global
|
16
|
+
# applicatoin.
|
17
|
+
# @param [Array] vms Array of VM configurations.
|
18
|
+
def initialize(global, vms)
|
19
|
+
@global = global
|
20
|
+
@vms = []
|
21
|
+
@vm_configs = {}
|
22
|
+
|
23
|
+
vms.each do |vm_config|
|
24
|
+
@vms << vm_config.vm.name
|
25
|
+
@vm_configs[vm_config.vm.name] = vm_config
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# This returns the configuration for a specific virtual machine.
|
30
|
+
# The values for this configuration are usually pertinent to a
|
31
|
+
# single virtual machine and do not affect the system globally.
|
32
|
+
def for_vm(name)
|
33
|
+
@vm_configs[name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Config
|
3
|
+
# A class which is passed into the various {Base#validate} methods and
|
4
|
+
# can be used as a helper to add error messages about a single config
|
5
|
+
# class.
|
6
|
+
class ErrorRecorder
|
7
|
+
attr_reader :errors
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@errors = []
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adds an error to the list of errors.
|
14
|
+
def add(message)
|
15
|
+
@errors << message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "log4r"
|
4
|
+
|
5
|
+
module Vagrant
|
6
|
+
module Config
|
7
|
+
# This class is responsible for loading Vagrant configuration,
|
8
|
+
# usually in the form of Vagrantfiles.
|
9
|
+
#
|
10
|
+
# Loading works by specifying the sources for the configuration
|
11
|
+
# as well as the order the sources should be loaded. Configuration
|
12
|
+
# set later always overrides those set earlier; this is how
|
13
|
+
# configuration "scoping" is implemented.
|
14
|
+
class Loader
|
15
|
+
# This is an array of symbols specifying the order in which
|
16
|
+
# configuration is loaded. For examples, see the class documentation.
|
17
|
+
attr_accessor :load_order
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@logger = Log4r::Logger.new("vagrant::config::loader")
|
21
|
+
@sources = {}
|
22
|
+
@proc_cache = {}
|
23
|
+
@config_cache = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set the configuration data for the given name.
|
27
|
+
#
|
28
|
+
# The `name` should be a symbol and must uniquely identify the data
|
29
|
+
# being given.
|
30
|
+
#
|
31
|
+
# `data` can either be a path to a Ruby Vagrantfile or a `Proc` directly.
|
32
|
+
# `data` can also be an array of such values.
|
33
|
+
#
|
34
|
+
# At this point, no configuration is actually loaded. Note that calling
|
35
|
+
# `set` multiple times with the same name will override any previously
|
36
|
+
# set values. In this way, the last set data for a given name wins.
|
37
|
+
def set(name, sources)
|
38
|
+
@logger.debug("Set #{name.inspect} = #{sources.inspect}")
|
39
|
+
|
40
|
+
# Sources should be an array
|
41
|
+
sources = [sources] if !sources.kind_of?(Array)
|
42
|
+
|
43
|
+
# Gather the procs for every source, since that is what we care about.
|
44
|
+
procs = []
|
45
|
+
sources.each do |source|
|
46
|
+
if !@proc_cache.has_key?(source)
|
47
|
+
# Load the procs for this source and cache them. This caching
|
48
|
+
# avoids the issue where a file may have side effects when loading
|
49
|
+
# and loading it multiple times causes unexpected behavior.
|
50
|
+
@logger.debug("Populating proc cache for #{source.inspect}")
|
51
|
+
@proc_cache[source] = procs_for_source(source)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Add on to the array of procs we're going to use
|
55
|
+
procs.concat(@proc_cache[source])
|
56
|
+
end
|
57
|
+
|
58
|
+
# Set this source by name.
|
59
|
+
@sources[name] = procs
|
60
|
+
end
|
61
|
+
|
62
|
+
# This loads the configured sources in the configured order and returns
|
63
|
+
# an actual configuration object that is ready to be used.
|
64
|
+
def load
|
65
|
+
@logger.debug("Loading configuration in order: #{@load_order.inspect}")
|
66
|
+
|
67
|
+
unknown_sources = @sources.keys - @load_order
|
68
|
+
if !unknown_sources.empty?
|
69
|
+
# TODO: Raise exception here perhaps.
|
70
|
+
@logger.error("Unknown config sources: #{unknown_sources.inspect}")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Create the top-level configuration which will hold all the config.
|
74
|
+
result = Top.new
|
75
|
+
|
76
|
+
@load_order.each do |key|
|
77
|
+
next if !@sources.has_key?(key)
|
78
|
+
|
79
|
+
@sources[key].each do |proc|
|
80
|
+
if !@config_cache.has_key?(proc)
|
81
|
+
@logger.debug("Loading from: #{key} (evaluating)")
|
82
|
+
current = Top.new
|
83
|
+
proc.call(current)
|
84
|
+
@config_cache[proc] = current
|
85
|
+
else
|
86
|
+
@logger.debug("Loading from: #{key} (cache)")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Merge in the results of this proc's configuration
|
90
|
+
result = result.merge(@config_cache[proc])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
@logger.debug("Configuration loaded successfully")
|
95
|
+
result
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
# This returns an array of `Proc` objects for the given source.
|
101
|
+
# The `Proc` objects returned will expect a single argument for
|
102
|
+
# the configuration object and are expected to mutate this
|
103
|
+
# configuration object.
|
104
|
+
def procs_for_source(source)
|
105
|
+
return [source] if source.is_a?(Proc)
|
106
|
+
|
107
|
+
# Assume all string sources are actually pathnames
|
108
|
+
source = Pathname.new(source) if source.is_a?(String)
|
109
|
+
|
110
|
+
if source.is_a?(Pathname)
|
111
|
+
@logger.debug("Load procs for pathname: #{source.inspect}")
|
112
|
+
|
113
|
+
begin
|
114
|
+
return Config.capture_configures do
|
115
|
+
Kernel.load source
|
116
|
+
end
|
117
|
+
rescue SyntaxError => e
|
118
|
+
# Report syntax errors in a nice way.
|
119
|
+
raise Errors::VagrantfileSyntaxError, :file => e.message
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
raise Exception, "Unknown configuration source: #{source.inspect}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|