From bfd93eef4eab85593952abc5338440c04aa6e731 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 10 Dec 2011 09:53:56 -0800 Subject: [PATCH] Come a lot farther in getting `up` to work again --- BRANCH_TODO | 3 ++- config/default.rb | 3 ++- lib/vagrant/action/vm/boot.rb | 14 ++++++------ lib/vagrant/action/vm/check_accessible.rb | 2 +- .../action/vm/clear_forwarded_ports.rb | 2 +- lib/vagrant/action/vm/clear_shared_folders.rb | 2 +- lib/vagrant/action/vm/customize.rb | 6 ++--- lib/vagrant/action/vm/destroy.rb | 6 ++--- .../vm/destroy_unused_network_interfaces.rb | 2 +- lib/vagrant/action/vm/forward_ports.rb | 22 +++++++++---------- lib/vagrant/action/vm/halt.rb | 10 ++++----- lib/vagrant/action/vm/import.rb | 3 +-- lib/vagrant/action/vm/modify.rb | 6 ++--- lib/vagrant/action/vm/nfs.rb | 22 +++++++++---------- lib/vagrant/action/vm/nfs_helpers.rb | 2 +- lib/vagrant/action/vm/provision.rb | 2 +- lib/vagrant/action/vm/provisioner_cleanup.rb | 2 +- lib/vagrant/action/vm/share_folders.rb | 20 ++++++++--------- lib/vagrant/environment.rb | 2 ++ 19 files changed, 67 insertions(+), 64 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index bedcddb90..afba27183 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -7,4 +7,5 @@ This is a TODO file for only this branch (config-overhaul) * Only allow one kind of vagrantfile to be loaded (i.e. if both Vagrantfile and vagrantfile exist, throw an error) * Nicer error if can't setup home directory -* vagrant box add should error if box already exists \ No newline at end of file +* vagrant box add should error if box already exists +* Default name to folder name + timestamp \ No newline at end of file diff --git a/config/default.rb b/config/default.rb index bac1a6f0a..cfb14d01c 100644 --- a/config/default.rb +++ b/config/default.rb @@ -23,7 +23,8 @@ Vagrant::Config.run do |config| config.vm.customize do |vm| # Make VM name the name of the containing folder by default - vm.name = File.basename(config.env.cwd) + "_#{Time.now.to_i}" + # TODO + # vm.name = File.basename(config.env.cwd) + "_#{Time.now.to_i}" end # Share the root folder. This can then be overridden by diff --git a/lib/vagrant/action/vm/boot.rb b/lib/vagrant/action/vm/boot.rb index 29cd0cf91..6148bea17 100644 --- a/lib/vagrant/action/vm/boot.rb +++ b/lib/vagrant/action/vm/boot.rb @@ -18,16 +18,16 @@ module Vagrant end def boot - @env.ui.info I18n.t("vagrant.actions.vm.boot.booting") - @env["vm"].vm.start(@env.env.config.vm.boot_mode) + @env[:ui].info I18n.t("vagrant.actions.vm.boot.booting") + @env[:vm].vm.start(@env[:vm].config.vm.boot_mode) end def wait_for_boot - @env.ui.info I18n.t("vagrant.actions.vm.boot.waiting") + @env[:ui].info I18n.t("vagrant.actions.vm.boot.waiting") - @env["config"].ssh.max_tries.to_i.times do |i| - if @env["vm"].ssh.up? - @env.ui.info I18n.t("vagrant.actions.vm.boot.ready") + @env[:vm].config.ssh.max_tries.to_i.times do |i| + if @env[:vm].ssh.up? + @env[:ui].info I18n.t("vagrant.actions.vm.boot.ready") return true end @@ -38,7 +38,7 @@ module Vagrant sleep 2 if !@env["vagrant.test"] end - @env.ui.error I18n.t("vagrant.actions.vm.boot.failed") + @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed") false end end diff --git a/lib/vagrant/action/vm/check_accessible.rb b/lib/vagrant/action/vm/check_accessible.rb index 3dc804eb7..55b003db0 100644 --- a/lib/vagrant/action/vm/check_accessible.rb +++ b/lib/vagrant/action/vm/check_accessible.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - if env["vm"] && env["vm"].created? && !env["vm"].vm.accessible? + if env[:vm] && env[:vm].created? && !env[:vm].vm.accessible? # The VM we are attempting to manipulate is inaccessible. This # is a very bad situation and can only be fixed by the user. It # also prohibits us from actually doing anything with the virtual diff --git a/lib/vagrant/action/vm/clear_forwarded_ports.rb b/lib/vagrant/action/vm/clear_forwarded_ports.rb index 6f5fbe153..bc90ded2b 100644 --- a/lib/vagrant/action/vm/clear_forwarded_ports.rb +++ b/lib/vagrant/action/vm/clear_forwarded_ports.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) proc = lambda do |vm| - env.ui.info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting") + env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting") vm.network_adapters.each do |na| na.nat_driver.forwarded_ports.dup.each do |fp| diff --git a/lib/vagrant/action/vm/clear_shared_folders.rb b/lib/vagrant/action/vm/clear_shared_folders.rb index 180875a48..f315f5f5d 100644 --- a/lib/vagrant/action/vm/clear_shared_folders.rb +++ b/lib/vagrant/action/vm/clear_shared_folders.rb @@ -10,7 +10,7 @@ module Vagrant def call(env) proc = lambda do |vm| if vm.shared_folders.length > 0 - env.ui.info I18n.t("vagrant.actions.vm.clear_shared_folders.deleting") + env[:ui].info I18n.t("vagrant.actions.vm.clear_shared_folders.deleting") vm.shared_folders.dup.each do |shared_folder| shared_folder.destroy diff --git a/lib/vagrant/action/vm/customize.rb b/lib/vagrant/action/vm/customize.rb index 96c117e63..a0a57a3f3 100644 --- a/lib/vagrant/action/vm/customize.rb +++ b/lib/vagrant/action/vm/customize.rb @@ -7,11 +7,11 @@ module Vagrant end def call(env) - if !env["config"].vm.proc_stack.empty? + if !env[:vm].config.vm.proc_stack.empty? # Create the proc which runs all of our procs proc = lambda do |vm| - env.ui.info I18n.t("vagrant.actions.vm.customize.running") - env["config"].vm.run_procs!(vm) + env[:ui].info I18n.t("vagrant.actions.vm.customize.running") + env[:vm].config.vm.run_procs!(vm) end # Add it to modify sequence diff --git a/lib/vagrant/action/vm/destroy.rb b/lib/vagrant/action/vm/destroy.rb index 8ac21bdd9..f38dd305d 100644 --- a/lib/vagrant/action/vm/destroy.rb +++ b/lib/vagrant/action/vm/destroy.rb @@ -7,9 +7,9 @@ module Vagrant end def call(env) - env.ui.info I18n.t("vagrant.actions.vm.destroy.destroying") - env["vm"].vm.destroy - env["vm"].vm = nil + env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying") + env[:vm].vm.destroy + env[:vm].vm = nil @app.call(env) end diff --git a/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb b/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb index f5d756466..be52bb0ac 100644 --- a/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +++ b/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb @@ -16,7 +16,7 @@ module Vagrant # Destroy it if there is nothing attached if iface.attached_vms.empty? - env.ui.info I18n.t("vagrant.actions.vm.destroy_network.destroying") + env[:ui].info I18n.t("vagrant.actions.vm.destroy_network.destroying") iface.destroy end end diff --git a/lib/vagrant/action/vm/forward_ports.rb b/lib/vagrant/action/vm/forward_ports.rb index 7a095fb3d..9cc8f8354 100644 --- a/lib/vagrant/action/vm/forward_ports.rb +++ b/lib/vagrant/action/vm/forward_ports.rb @@ -24,7 +24,7 @@ module Vagrant def threshold_check @env[:vm].config.vm.forwarded_ports.each do |name, options| if options[:hostport] <= 1024 - @env.ui.warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports") + @env[:ui].warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports") return end end @@ -58,12 +58,12 @@ module Vagrant # Get the auto port range and get rid of the used ports and # ports which are being used in other forwards so we're just # left with available ports. - range = @env.env.config.vm.auto_port_range.to_a - range -= @env.env.config.vm.forwarded_ports.collect { |n, o| o[:hostport].to_i } + range = @env[:vm].config.vm.auto_port_range.to_a + range -= @env[:vm].config.vm.forwarded_ports.collect { |n, o| o[:hostport].to_i } range -= existing_ports if range.empty? - raise Errors::ForwardPortAutolistEmpty, :vm_name => @env["vm"].name, + raise Errors::ForwardPortAutolistEmpty, :vm_name => @env[:vm].name, :name => name, :host_port => options[:hostport].to_s, :guest_port => options[:guestport].to_s @@ -75,9 +75,9 @@ module Vagrant existing_ports << options[:hostport] # Notify the user - @env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.fixed_collision", - :name => name, - :new_port => options[:hostport])) + @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.fixed_collision", + :name => name, + :new_port => options[:hostport])) end #-------------------------------------------------------------- @@ -87,7 +87,7 @@ module Vagrant @env = env proc = lambda do |vm| - env.ui.info I18n.t("vagrant.actions.vm.forward_ports.forwarding") + env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding") forward_ports(vm) end @@ -96,7 +96,7 @@ module Vagrant end def forward_ports(vm) - @env.env.config.vm.forwarded_ports.each do |name, options| + @env[:vm].config.vm.forwarded_ports.each do |name, options| adapter = options[:adapter] message_attributes = { :name => name, @@ -109,10 +109,10 @@ module Vagrant # Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these # attachment types has uncertain behaviour. if vm.network_adapters[adapter].attachment_type == :nat - @env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes)) + @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes)) forward_port(vm, name, options) else - @env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.non_nat", message_attributes)) + @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.non_nat", message_attributes)) end end end diff --git a/lib/vagrant/action/vm/halt.rb b/lib/vagrant/action/vm/halt.rb index ca9d248a2..0dc889d86 100644 --- a/lib/vagrant/action/vm/halt.rb +++ b/lib/vagrant/action/vm/halt.rb @@ -8,12 +8,12 @@ module Vagrant end def call(env) - if env["vm"].created? && env["vm"].vm.running? - env["vm"].system.halt if !env["force"] + if env[:vm].created? && env[:vm].vm.running? + env[:vm].system.halt if !env["force"] - if env["vm"].vm.state(true) != :powered_off - env.ui.info I18n.t("vagrant.actions.vm.halt.force") - env["vm"].vm.stop + if env[:vm].vm.state(true) != :powered_off + env[:ui].info I18n.t("vagrant.actions.vm.halt.force") + env[:vm].vm.stop end # Sleep for a second to verify that the VM properly diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index 5481d4196..971a9203e 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -31,8 +31,7 @@ module Vagrant return if env["vagrant.error"].is_a?(Errors::VagrantError) # Interrupted, destroy the VM - # TODO - # env[:action_runner].run(:destroy) + env[:action_runner].run(:destroy, env) end end end diff --git a/lib/vagrant/action/vm/modify.rb b/lib/vagrant/action/vm/modify.rb index ab5bbbccb..e0a10cad6 100644 --- a/lib/vagrant/action/vm/modify.rb +++ b/lib/vagrant/action/vm/modify.rb @@ -25,9 +25,9 @@ module Vagrant def call(env) # Run the procs we have saved up, save the machine, and reload # to verify we get the new settings - run_procs!(env["vm"].vm) - env["vm"].vm.save - env["vm"].reload! + run_procs!(env[:vm].vm) + env[:vm].vm.save + env[:vm].reload! @app.call(env) end diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb index 169a88777..284c4596d 100644 --- a/lib/vagrant/action/vm/nfs.rb +++ b/lib/vagrant/action/vm/nfs.rb @@ -42,7 +42,7 @@ module Vagrant end def recover(env) - clear_nfs_exports(env) if env["vm"].created? + clear_nfs_exports(env) if env[:vm].created? end # Returns the folders which are to be synced via NFS. @@ -55,7 +55,7 @@ module Vagrant # task. def extract_folders # Load the NFS enabled shared folders - @folders = @env["config"].vm.shared_folders.inject({}) do |acc, data| + @folders = @env[:vm].config.vm.shared_folders.inject({}) do |acc, data| key, opts = data if opts[:nfs] @@ -91,7 +91,7 @@ module Vagrant # The options on the hash get priority, then the default # values - value = opts.has_key?(key) ? opts[key] : @env["config"].nfs.send(key) + value = opts.has_key?(key) ? opts[key] : @env[:vm].config.nfs.send(key) return value if value != :auto # Get UID/GID from folder if we've made it this far @@ -104,9 +104,9 @@ module Vagrant # involves adding a line to `/etc/exports` for this VM, but it is # up to the host class to define the specific behavior. def export_folders - @env.ui.info I18n.t("vagrant.actions.vm.nfs.exporting") + @env[:ui].info I18n.t("vagrant.actions.vm.nfs.exporting") - @env["host"].nfs_export(guest_ip, folders) + @env[:host].nfs_export(guest_ip, folders) end # Uses the system class to mount the NFS folders. @@ -116,14 +116,14 @@ module Vagrant # Only mount the folders which have a guest path specified am_folders = folders.select { |name, folder| folder[:guestpath] } am_folders = Hash[*am_folders.flatten] if am_folders.is_a?(Array) - @env["vm"].system.mount_nfs(host_ip, Hash[am_folders]) + @env[:vm].system.mount_nfs(host_ip, Hash[am_folders]) end # Returns the IP address of the first host only network adapter # # @return [String] def host_ip - interface = @env["vm"].vm.network_adapters.find do |adapter| + interface = @env[:vm].config.vm.network_adapters.find do |adapter| adapter.host_interface_object end @@ -136,7 +136,7 @@ module Vagrant # # @return [String] def guest_ip - @env["config"].vm.network_options[1][:ip] + @env[:vm].config.vm.network_options[1][:ip] end # Checks if there are any NFS enabled shared folders. @@ -150,9 +150,9 @@ module Vagrant # Verifies that the host is set and supports NFS. def verify_settings - raise Errors::NFSHostRequired if @env["host"].nil? - raise Errors::NFSNotSupported if !@env["host"].nfs? - raise Errors::NFSNoHostNetwork if @env["config"].vm.network_options.empty? + raise Errors::NFSHostRequired if @env[:host].nil? + raise Errors::NFSNotSupported if !@env[:host].nfs? + raise Errors::NFSNoHostNetwork if @env[:vm].config.vm.network_options.empty? end end end diff --git a/lib/vagrant/action/vm/nfs_helpers.rb b/lib/vagrant/action/vm/nfs_helpers.rb index de4841b20..a4bada6e9 100644 --- a/lib/vagrant/action/vm/nfs_helpers.rb +++ b/lib/vagrant/action/vm/nfs_helpers.rb @@ -3,7 +3,7 @@ module Vagrant module VM module NFSHelpers def clear_nfs_exports(env) - env["host"].nfs_cleanup if env["host"] + env[:host].nfs_cleanup if env[:host] end end end diff --git a/lib/vagrant/action/vm/provision.rb b/lib/vagrant/action/vm/provision.rb index 4b14a6fc1..4b810d410 100644 --- a/lib/vagrant/action/vm/provision.rb +++ b/lib/vagrant/action/vm/provision.rb @@ -24,7 +24,7 @@ module Vagrant end def enabled_provisioners - @env["config"].vm.provisioners.map do |provisioner| + @env[:vm].config.vm.provisioners.map do |provisioner| provisioner.provisioner.new(@env, provisioner.config) end end diff --git a/lib/vagrant/action/vm/provisioner_cleanup.rb b/lib/vagrant/action/vm/provisioner_cleanup.rb index 33f355be6..1c5b2f0e6 100644 --- a/lib/vagrant/action/vm/provisioner_cleanup.rb +++ b/lib/vagrant/action/vm/provisioner_cleanup.rb @@ -16,7 +16,7 @@ module Vagrant end def enabled_provisioners - @env["config"].vm.provisioners.map do |provisioner| + @env[:vm].config.vm.provisioners.map do |provisioner| provisioner.provisioner.new(@env, provisioner.config) end end diff --git a/lib/vagrant/action/vm/share_folders.rb b/lib/vagrant/action/vm/share_folders.rb index 6106d1e5d..a2db045b6 100644 --- a/lib/vagrant/action/vm/share_folders.rb +++ b/lib/vagrant/action/vm/share_folders.rb @@ -20,7 +20,7 @@ module Vagrant # This method returns an actual list of VirtualBox shared # folders to create and their proper path. def shared_folders - @env.env.config.vm.shared_folders.inject({}) do |acc, data| + @env[:vm].config.vm.shared_folders.inject({}) do |acc, data| key, value = data next acc if value[:disabled] @@ -34,12 +34,12 @@ module Vagrant def create_metadata proc = lambda do |vm| - @env.ui.info I18n.t("vagrant.actions.vm.share_folders.creating") + @env[:ui].info I18n.t("vagrant.actions.vm.share_folders.creating") shared_folders.each do |name, data| folder = VirtualBox::SharedFolder.new folder.name = name - folder.host_path = File.expand_path(data[:hostpath], @env.env.root_path) + folder.host_path = File.expand_path(data[:hostpath], @env[:root_path]) vm.shared_folders << folder end end @@ -48,7 +48,7 @@ module Vagrant end def mount_shared_folders - @env.ui.info I18n.t("vagrant.actions.vm.share_folders.mounting") + @env[:ui].info I18n.t("vagrant.actions.vm.share_folders.mounting") @env["vm"].ssh.execute do |ssh| # short guestpaths first, so we don't step on ourselves @@ -65,20 +65,20 @@ module Vagrant folders.each do |name, data| if data[:guestpath] # Guest path specified, so mount the folder to specified point - @env.ui.info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", - :name => name, - :guest_path => data[:guestpath])) + @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", + :name => name, + :guest_path => data[:guestpath])) # Calculate the owner and group owner = data[:owner] || @env["config"].ssh.username group = data[:group] || @env["config"].ssh.username # Mount the actual folder - @env["vm"].system.mount_shared_folder(ssh, name, data[:guestpath], owner, group) + @env[:vm].system.mount_shared_folder(ssh, name, data[:guestpath], owner, group) else # If no guest path is specified, then automounting is disabled - @env.ui.info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry", - :name => name)) + @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry", + :name => name)) end end end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index e157fa700..39afc5c3e 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -212,7 +212,9 @@ module Vagrant @action_runner ||= Action::Runner.new(action_registry) do |env| { :global_config => config.global, + :action_runner => action_runner, :box_collection => boxes, + :root_path => root_path, :tmp_path => tmp_path, :ui => @ui }