Change config.vm.system to config.vm.guest. Rename internals.

This commit is contained in:
Mitchell Hashimoto 2011-12-15 20:55:16 -08:00
parent eda286b476
commit 5fe50c8b5d
11 changed files with 51 additions and 50 deletions

View File

@ -4,6 +4,8 @@
to make debugging issues easier. To enable logging, set the VAGRANT_LOG
environmental variable to the log level you wish to see. By default,
logging is silent.
- `system` renamed to `guest` throughout the source. Any `config.vm.system`
configurations must be changed to `config.vm.guest`
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently
power off the system. [GH-575]
- Tweaks to SSH to hopefully be more reliable in coming up.

View File

@ -18,7 +18,7 @@ Vagrant::Config.run do |config|
config.vm.base_mac = nil
config.vm.forward_port("ssh", 22, 2222, :auto => true)
config.vm.boot_mode = "vrdp"
config.vm.system = :linux
config.vm.guest = :linux
# Share the root folder. This can then be overridden by
# other Vagrantfiles, if they wish.

View File

@ -9,7 +9,7 @@ module Vagrant
def call(env)
if env[:vm].created? && env[:vm].vm.running?
env[:vm].system.halt if !env["force"]
env[:vm].guest.halt if !env["force"]
if env[:vm].vm.state(true) != :powered_off
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")

View File

@ -12,7 +12,7 @@ module Vagrant
host_name = env[:vm].config.vm.host_name
if !host_name.nil?
env[:ui].info I18n.t("vagrant.actions.vm.host_name.setting")
env[:vm].system.change_host_name(host_name)
env[:vm].guest.change_host_name(host_name)
end
end
end

View File

@ -29,12 +29,12 @@ module Vagrant
# Prepare for new networks...
options = @env[:vm].config.vm.network_options.compact
options.each do |network_options|
@env["vm"].system.prepare_host_only_network(network_options)
@env["vm"].guest.prepare_host_only_network(network_options)
end
# Then enable the networks...
options.each do |network_options|
@env["vm"].system.enable_host_only_network(network_options)
@env["vm"].guest.enable_host_only_network(network_options)
end
end
end

View File

@ -116,7 +116,7 @@ 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].guest.mount_nfs(host_ip, Hash[am_folders])
end
# Returns the IP address of the first host only network adapter

View File

@ -74,7 +74,7 @@ module Vagrant
group = data[:group] || @env[:vm].config.ssh.username
# Mount the actual folder
@env[:vm].system.mount_shared_folder(ssh, name, data[:guestpath], owner, group)
@env[:vm].guest.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",

View File

@ -17,7 +17,7 @@ module Vagrant
attr_reader :shared_folders
attr_reader :network_options
attr_reader :provisioners
attr_accessor :system
attr_accessor :guest
def initialize
@forwarded_ports = {}

View File

@ -324,6 +324,11 @@ module Vagrant
error_key(:failed_to_boot, "vagrant.actions.vm.boot")
end
class VMGuestError < VagrantError
status_code(39)
error_namespace("vagrant.errors.guest")
end
class VMImportFailure < VagrantError
status_code(28)
error_key(:failure, "vagrant.actions.vm.import")
@ -353,10 +358,5 @@ module Vagrant
status_code(24)
error_key(:power_off, "vagrant.actions.vm.export")
end
class VMSystemError < VagrantError
status_code(39)
error_namespace("vagrant.errors.system")
end
end
end

View File

@ -19,44 +19,43 @@ module Vagrant
@config = config
@box = env.boxes.find(config.vm.box)
# Load the associated system.
load_system!
@loaded_system_distro = false
# Load the associated guest.
load_guest!
@loaded_guest_distro = false
end
# Loads the system associated with the VM. The system class is
# Loads the guest associated with the VM. The guest class is
# responsible for OS-specific functionality. More information
# can be found by reading the documentation on {Vagrant::Systems::Base}.
# can be found by reading the documentation on {Vagrant::Guest::Base}.
#
# **This method should never be called manually.**
def load_system!(system=nil)
system ||= config.vm.system
@logger.info("Loading system: #{system}")
def load_guest!(guest=nil)
guest ||= config.vm.guest
@logger.info("Loading guest: #{guest}")
if system.is_a?(Class)
raise Errors::VMSystemError, :_key => :invalid_class, :system => system.to_s if !(system <= Systems::Base)
@system = system.new(self)
elsif system.is_a?(Symbol)
system_klass = Vagrant.guests.get(system)
raise Errors::VMSystemError, :_key => :unknown_type, :system => system.to_s if !system_klass
@system = system_klass.new(self)
if guest.is_a?(Class)
raise Errors::VMGuestError, :_key => :invalid_class, :system => guest.to_s if !(guest <= Systems::Base)
@guest = guest.new(self)
elsif guest.is_a?(Symbol)
guest_klass = Vagrant.guests.get(guest)
raise Errors::VMGuestError, :_key => :unknown_type, :system => guest.to_s if !guest_klass
@guest = guest_klass.new(self)
else
raise Errors::VMSystemError, :unspecified
raise Errors::VMGuestError, :unspecified
end
end
# Returns the system for this VM, loading the distro of the system if
# Returns the guest for this VM, loading the distro of the system if
# we can.
def system
if !@loaded_system_distro && created? && vm.running?
# Load the system distro for the first time
result = @system.distro_dispatch
load_system!(result)
@loaded_system_distro = true
def guest
if !@loaded_guest_distro && created? && vm.running?
# Load the guest distro for the first time
result = @guest.distro_dispatch
load_guest!(result)
@loaded_guest_distro = true
end
@system
@guest
end
# Access the {Vagrant::SSH} object associated with this VM.

View File

@ -43,6 +43,18 @@ en:
may run at any given time to avoid problems with VirtualBox inconsistencies
occurring. Please wait for the other instance of Vagrant to end and then
try again.
guest:
invalid_class: |-
The specified system does not inherit from `Vagrant::Systems::Base`. The
specified system class must inherit from this class.
The specified system class was: %{system}
unknown_type: |-
The specified system type is unknown: %{system}. Please change this
to a proper value.
unspecified: |-
A VM system type must be specified! This is done via the `config.vm.system`
configuration value. Please read the documentation online for more information.
home_dir_not_accessible: |-
The home directory you specified is not accessible. The home
directory that Vagrant uses must be both readable and writable.
@ -103,18 +115,6 @@ en:
http://vagrantup.com/docs/getting-started/setup/windows.html
system:
invalid_class: |-
The specified system does not inherit from `Vagrant::Systems::Base`. The
specified system class must inherit from this class.
The specified system class was: %{system}
unknown_type: |-
The specified system type is unknown: %{system}. Please change this
to a proper value.
unspecified: |-
A VM system type must be specified! This is done via the `config.vm.system`
configuration value. Please read the documentation online for more information.
vagrantfile_syntax_error: |-
There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience: