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

@ -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
* 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|
# 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

View File

@ -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

View File

@ -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

View File

@ -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|

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}