Come a lot farther in getting `up` to work again

This commit is contained in:
Mitchell Hashimoto 2011-12-10 09:53:56 -08:00
parent 1758970a53
commit bfd93eef4e
19 changed files with 67 additions and 64 deletions

View File

@ -8,3 +8,4 @@ This is a TODO file for only this branch (config-overhaul)
Vagrantfile and vagrantfile exist, throw an error) Vagrantfile and vagrantfile exist, throw an error)
* Nicer error if can't setup home directory * Nicer error if can't setup home directory
* vagrant box add should error if box already exists * vagrant box add should error if box already exists
* Default name to folder name + timestamp

View File

@ -23,7 +23,8 @@ Vagrant::Config.run do |config|
config.vm.customize do |vm| config.vm.customize do |vm|
# Make VM name the name of the containing folder by default # 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 end
# Share the root folder. This can then be overridden by # Share the root folder. This can then be overridden by

View File

@ -18,16 +18,16 @@ module Vagrant
end end
def boot def boot
@env.ui.info I18n.t("vagrant.actions.vm.boot.booting") @env[:ui].info I18n.t("vagrant.actions.vm.boot.booting")
@env["vm"].vm.start(@env.env.config.vm.boot_mode) @env[:vm].vm.start(@env[:vm].config.vm.boot_mode)
end end
def wait_for_boot 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| @env[:vm].config.ssh.max_tries.to_i.times do |i|
if @env["vm"].ssh.up? if @env[:vm].ssh.up?
@env.ui.info I18n.t("vagrant.actions.vm.boot.ready") @env[:ui].info I18n.t("vagrant.actions.vm.boot.ready")
return true return true
end end
@ -38,7 +38,7 @@ module Vagrant
sleep 2 if !@env["vagrant.test"] sleep 2 if !@env["vagrant.test"]
end end
@env.ui.error I18n.t("vagrant.actions.vm.boot.failed") @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
false false
end end
end end

View File

@ -7,7 +7,7 @@ module Vagrant
end end
def call(env) 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 # The VM we are attempting to manipulate is inaccessible. This
# is a very bad situation and can only be fixed by the user. It # is a very bad situation and can only be fixed by the user. It
# also prohibits us from actually doing anything with the virtual # also prohibits us from actually doing anything with the virtual

View File

@ -8,7 +8,7 @@ module Vagrant
def call(env) def call(env)
proc = lambda do |vm| 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| vm.network_adapters.each do |na|
na.nat_driver.forwarded_ports.dup.each do |fp| na.nat_driver.forwarded_ports.dup.each do |fp|

View File

@ -10,7 +10,7 @@ module Vagrant
def call(env) def call(env)
proc = lambda do |vm| proc = lambda do |vm|
if vm.shared_folders.length > 0 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| vm.shared_folders.dup.each do |shared_folder|
shared_folder.destroy shared_folder.destroy

View File

@ -7,11 +7,11 @@ module Vagrant
end end
def call(env) 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 # Create the proc which runs all of our procs
proc = lambda do |vm| proc = lambda do |vm|
env.ui.info I18n.t("vagrant.actions.vm.customize.running") env[:ui].info I18n.t("vagrant.actions.vm.customize.running")
env["config"].vm.run_procs!(vm) env[:vm].config.vm.run_procs!(vm)
end end
# Add it to modify sequence # Add it to modify sequence

View File

@ -7,9 +7,9 @@ module Vagrant
end end
def call(env) def call(env)
env.ui.info I18n.t("vagrant.actions.vm.destroy.destroying") env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
env["vm"].vm.destroy env[:vm].vm.destroy
env["vm"].vm = nil env[:vm].vm = nil
@app.call(env) @app.call(env)
end end

View File

@ -16,7 +16,7 @@ module Vagrant
# Destroy it if there is nothing attached # Destroy it if there is nothing attached
if iface.attached_vms.empty? 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 iface.destroy
end end
end end

View File

@ -24,7 +24,7 @@ module Vagrant
def threshold_check def threshold_check
@env[:vm].config.vm.forwarded_ports.each do |name, options| @env[:vm].config.vm.forwarded_ports.each do |name, options|
if options[:hostport] <= 1024 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 return
end end
end end
@ -58,12 +58,12 @@ module Vagrant
# Get the auto port range and get rid of the used ports and # 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 # ports which are being used in other forwards so we're just
# left with available ports. # left with available ports.
range = @env.env.config.vm.auto_port_range.to_a range = @env[:vm].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.forwarded_ports.collect { |n, o| o[:hostport].to_i }
range -= existing_ports range -= existing_ports
if range.empty? if range.empty?
raise Errors::ForwardPortAutolistEmpty, :vm_name => @env["vm"].name, raise Errors::ForwardPortAutolistEmpty, :vm_name => @env[:vm].name,
:name => name, :name => name,
:host_port => options[:hostport].to_s, :host_port => options[:hostport].to_s,
:guest_port => options[:guestport].to_s :guest_port => options[:guestport].to_s
@ -75,9 +75,9 @@ module Vagrant
existing_ports << options[:hostport] existing_ports << options[:hostport]
# Notify the user # Notify the user
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.fixed_collision", @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.fixed_collision",
:name => name, :name => name,
:new_port => options[:hostport])) :new_port => options[:hostport]))
end end
#-------------------------------------------------------------- #--------------------------------------------------------------
@ -87,7 +87,7 @@ module Vagrant
@env = env @env = env
proc = lambda do |vm| 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) forward_ports(vm)
end end
@ -96,7 +96,7 @@ module Vagrant
end end
def forward_ports(vm) 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] adapter = options[:adapter]
message_attributes = { message_attributes = {
:name => name, :name => name,
@ -109,10 +109,10 @@ module Vagrant
# Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these # Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
# attachment types has uncertain behaviour. # attachment types has uncertain behaviour.
if vm.network_adapters[adapter].attachment_type == :nat 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) forward_port(vm, name, options)
else 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 end
end end

View File

@ -8,12 +8,12 @@ module Vagrant
end end
def call(env) def call(env)
if env["vm"].created? && env["vm"].vm.running? if env[:vm].created? && env[:vm].vm.running?
env["vm"].system.halt if !env["force"] env[:vm].system.halt if !env["force"]
if env["vm"].vm.state(true) != :powered_off if env[:vm].vm.state(true) != :powered_off
env.ui.info I18n.t("vagrant.actions.vm.halt.force") env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
env["vm"].vm.stop env[:vm].vm.stop
end end
# Sleep for a second to verify that the VM properly # Sleep for a second to verify that the VM properly

View File

@ -31,8 +31,7 @@ module Vagrant
return if env["vagrant.error"].is_a?(Errors::VagrantError) return if env["vagrant.error"].is_a?(Errors::VagrantError)
# Interrupted, destroy the VM # Interrupted, destroy the VM
# TODO env[:action_runner].run(:destroy, env)
# env[:action_runner].run(:destroy)
end end
end end
end end

View File

@ -25,9 +25,9 @@ module Vagrant
def call(env) def call(env)
# Run the procs we have saved up, save the machine, and reload # Run the procs we have saved up, save the machine, and reload
# to verify we get the new settings # to verify we get the new settings
run_procs!(env["vm"].vm) run_procs!(env[:vm].vm)
env["vm"].vm.save env[:vm].vm.save
env["vm"].reload! env[:vm].reload!
@app.call(env) @app.call(env)
end end

View File

@ -42,7 +42,7 @@ module Vagrant
end end
def recover(env) def recover(env)
clear_nfs_exports(env) if env["vm"].created? clear_nfs_exports(env) if env[:vm].created?
end end
# Returns the folders which are to be synced via NFS. # Returns the folders which are to be synced via NFS.
@ -55,7 +55,7 @@ module Vagrant
# task. # task.
def extract_folders def extract_folders
# Load the NFS enabled shared 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 key, opts = data
if opts[:nfs] if opts[:nfs]
@ -91,7 +91,7 @@ module Vagrant
# The options on the hash get priority, then the default # The options on the hash get priority, then the default
# values # 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 return value if value != :auto
# Get UID/GID from folder if we've made it this far # 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 # involves adding a line to `/etc/exports` for this VM, but it is
# up to the host class to define the specific behavior. # up to the host class to define the specific behavior.
def export_folders 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 end
# Uses the system class to mount the NFS folders. # 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 # Only mount the folders which have a guest path specified
am_folders = folders.select { |name, folder| folder[:guestpath] } am_folders = folders.select { |name, folder| folder[:guestpath] }
am_folders = Hash[*am_folders.flatten] if am_folders.is_a?(Array) 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 end
# Returns the IP address of the first host only network adapter # Returns the IP address of the first host only network adapter
# #
# @return [String] # @return [String]
def host_ip 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 adapter.host_interface_object
end end
@ -136,7 +136,7 @@ module Vagrant
# #
# @return [String] # @return [String]
def guest_ip def guest_ip
@env["config"].vm.network_options[1][:ip] @env[:vm].config.vm.network_options[1][:ip]
end end
# Checks if there are any NFS enabled shared folders. # Checks if there are any NFS enabled shared folders.
@ -150,9 +150,9 @@ module Vagrant
# Verifies that the host is set and supports NFS. # Verifies that the host is set and supports NFS.
def verify_settings def verify_settings
raise Errors::NFSHostRequired if @env["host"].nil? raise Errors::NFSHostRequired if @env[:host].nil?
raise Errors::NFSNotSupported if !@env["host"].nfs? raise Errors::NFSNotSupported if !@env[:host].nfs?
raise Errors::NFSNoHostNetwork if @env["config"].vm.network_options.empty? raise Errors::NFSNoHostNetwork if @env[:vm].config.vm.network_options.empty?
end end
end end
end end

View File

@ -3,7 +3,7 @@ module Vagrant
module VM module VM
module NFSHelpers module NFSHelpers
def clear_nfs_exports(env) def clear_nfs_exports(env)
env["host"].nfs_cleanup if env["host"] env[:host].nfs_cleanup if env[:host]
end end
end end
end end

View File

@ -24,7 +24,7 @@ module Vagrant
end end
def enabled_provisioners def enabled_provisioners
@env["config"].vm.provisioners.map do |provisioner| @env[:vm].config.vm.provisioners.map do |provisioner|
provisioner.provisioner.new(@env, provisioner.config) provisioner.provisioner.new(@env, provisioner.config)
end end
end end

View File

@ -16,7 +16,7 @@ module Vagrant
end end
def enabled_provisioners def enabled_provisioners
@env["config"].vm.provisioners.map do |provisioner| @env[:vm].config.vm.provisioners.map do |provisioner|
provisioner.provisioner.new(@env, provisioner.config) provisioner.provisioner.new(@env, provisioner.config)
end end
end end

View File

@ -20,7 +20,7 @@ module Vagrant
# This method returns an actual list of VirtualBox shared # This method returns an actual list of VirtualBox shared
# folders to create and their proper path. # folders to create and their proper path.
def shared_folders 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 key, value = data
next acc if value[:disabled] next acc if value[:disabled]
@ -34,12 +34,12 @@ module Vagrant
def create_metadata def create_metadata
proc = lambda do |vm| 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| shared_folders.each do |name, data|
folder = VirtualBox::SharedFolder.new folder = VirtualBox::SharedFolder.new
folder.name = name 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 vm.shared_folders << folder
end end
end end
@ -48,7 +48,7 @@ module Vagrant
end end
def mount_shared_folders 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| @env["vm"].ssh.execute do |ssh|
# short guestpaths first, so we don't step on ourselves # short guestpaths first, so we don't step on ourselves
@ -65,20 +65,20 @@ module Vagrant
folders.each do |name, data| folders.each do |name, data|
if data[:guestpath] if data[:guestpath]
# Guest path specified, so mount the folder to specified point # Guest path specified, so mount the folder to specified point
@env.ui.info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
:name => name, :name => name,
:guest_path => data[:guestpath])) :guest_path => data[:guestpath]))
# Calculate the owner and group # Calculate the owner and group
owner = data[:owner] || @env["config"].ssh.username owner = data[:owner] || @env["config"].ssh.username
group = data[:group] || @env["config"].ssh.username group = data[:group] || @env["config"].ssh.username
# Mount the actual folder # 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 else
# If no guest path is specified, then automounting is disabled # If no guest path is specified, then automounting is disabled
@env.ui.info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry", @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry",
:name => name)) :name => name))
end end
end end
end end

View File

@ -212,7 +212,9 @@ module Vagrant
@action_runner ||= Action::Runner.new(action_registry) do |env| @action_runner ||= Action::Runner.new(action_registry) do |env|
{ {
:global_config => config.global, :global_config => config.global,
:action_runner => action_runner,
:box_collection => boxes, :box_collection => boxes,
:root_path => root_path,
:tmp_path => tmp_path, :tmp_path => tmp_path,
:ui => @ui :ui => @ui
} }