diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 8b18de499..fe3b5eaf1 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -89,6 +89,7 @@ module Vagrant c.register(:"1") { Plugin::V1::Plugin } c.register([:"1", :command]) { Plugin::V1::Command } c.register([:"1", :config]) { Plugin::V1::Config } + c.register([:"1", :guest]) { Plugin::V1::Guest } c.register([:"1", :provisioner]) { Plugin::V1::Provisioner } # Returns a `Vagrant::Registry` object that contains all the built-in diff --git a/lib/vagrant/plugin/v1.rb b/lib/vagrant/plugin/v1.rb index 595dcd6e3..0c095c4c3 100644 --- a/lib/vagrant/plugin/v1.rb +++ b/lib/vagrant/plugin/v1.rb @@ -7,6 +7,7 @@ module Vagrant module V1 autoload :Command, "vagrant/plugin/v1/command" autoload :Config, "vagrant/plugin/v1/config" + autoload :Guest, "vagrant/plugin/v1/guest" autoload :Plugin, "vagrant/plugin/v1/plugin" autoload :Provisioner, "vagrant/plugin/v1/provisioner" end diff --git a/lib/vagrant/plugin/v1/guest.rb b/lib/vagrant/plugin/v1/guest.rb new file mode 100644 index 000000000..86e96c249 --- /dev/null +++ b/lib/vagrant/plugin/v1/guest.rb @@ -0,0 +1,93 @@ +module Vagrant + module Plugin + module V1 + # The base class for a guest. A guest represents an installed system + # within a machine that Vagrant manages. There are some portions of + # Vagrant which are OS-specific such as mountaing shared folders and + # halting the machine, and this abstraction allows the implementation + # for these to be seperate from the core of Vagrant. + class Guest + class BaseError < Errors::VagrantError + error_namespace("vagrant.guest.base") + end + + include Vagrant::Util + + # The VM which this system is tied to. + attr_reader :vm + + # Initializes the system. Any subclasses MUST make sure this + # method is called on the parent. Therefore, if a subclass overrides + # `initialize`, then you must call `super`. + def initialize(vm) + @vm = vm + end + + # This method is automatically called when the system is available (when + # Vagrant can successfully SSH into the machine) to give the system a chance + # to determine the distro and return a distro-specific system. + # + # **Warning:** If a return value which subclasses from {Base} is + # returned, Vagrant will use it as the new system instance for the + # class. + def distro_dispatch + end + + # Halt the machine. This method should gracefully shut down the + # operating system. This method will cause `vagrant halt` and associated + # commands to _block_, meaning that if the machine doesn't halt + # in a reasonable amount of time, this method should just return. + # + # If when this method returns, the machine's state isn't "powered_off," + # Vagrant will proceed to forcefully shut the machine down. + def halt + raise BaseError, :_key => :unsupported_halt + end + + # Mounts a shared folder. + # + # This method should create, mount, and properly set permissions + # on the shared folder. This method should also properly + # adhere to any configuration values such as `shared_folder_uid` + # on `config.vm`. + # + # @param [String] name The name of the shared folder. + # @param [String] guestpath The path on the machine which the user + # wants the folder mounted. + # @param [Hash] options Additional options for the shared folder + # which can be honored. + def mount_shared_folder(name, guestpath, options) + raise BaseError, :_key => :unsupported_shared_folder + end + + # Mounts a shared folder via NFS. This assumes that the exports + # via the host are already done. + def mount_nfs(ip, folders) + raise BaseError, :_key => :unsupported_nfs + end + + # Configures the given list of networks on the virtual machine. + # + # The networks parameter will be an array of hashes where the hashes + # represent the configuration of a network interface. The structure + # of the hash will be roughly the following: + # + # { + # :type => :static, + # :ip => "192.168.33.10", + # :netmask => "255.255.255.0", + # :interface => 1 + # } + # + def configure_networks(networks) + raise BaseError, :_key => :unsupported_configure_networks + end + + # Called to change the hostname of the virtual machine. + def change_host_name(name) + raise BaseError, :_key => :unsupported_host_name + end + end + end + end +end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index cf2badb8c..1068a00ed 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -49,7 +49,7 @@ module Vagrant @logger.info("Loading guest: #{guest}") if guest.is_a?(Class) - raise Errors::VMGuestError, :_key => :invalid_class, :guest => guest.to_s if !(guest <= Guest::Base) + raise Errors::VMGuestError, :_key => :invalid_class, :guest => guest.to_s if !(guest <= Vagrant.plugin("1", :guest)) @guest = guest.new(self) elsif guest.is_a?(Symbol) # Look for the guest as a registered plugin diff --git a/plugins/guests/freebsd/guest.rb b/plugins/guests/freebsd/guest.rb index 479a32f68..4f092fa74 100644 --- a/plugins/guests/freebsd/guest.rb +++ b/plugins/guests/freebsd/guest.rb @@ -5,7 +5,7 @@ module VagrantPlugins # A general Vagrant system implementation for "freebsd". # # Contributed by Kenneth Vestergaard - class Guest < Vagrant::Guest::Base + class Guest < Vagrant.plugin("1", :guest) # Here for whenever it may be used. class FreeBSDError < Vagrant::Errors::VagrantError error_namespace("vagrant.guest.freebsd") diff --git a/plugins/guests/linux/guest.rb b/plugins/guests/linux/guest.rb index 69ccd6890..49d40be0c 100644 --- a/plugins/guests/linux/guest.rb +++ b/plugins/guests/linux/guest.rb @@ -4,7 +4,7 @@ require "vagrant" module VagrantPlugins module GuestLinux - class Guest < Vagrant::Guest::Base + class Guest < Vagrant.plugin("1", :guest) class LinuxError < Vagrant::Errors::VagrantError error_namespace("vagrant.guest.linux") end diff --git a/plugins/guests/solaris/guest.rb b/plugins/guests/solaris/guest.rb index 031013311..51cb5c2e7 100644 --- a/plugins/guests/solaris/guest.rb +++ b/plugins/guests/solaris/guest.rb @@ -5,7 +5,7 @@ module VagrantPlugins # A general Vagrant system implementation for "solaris". # # Contributed by Blake Irvin - class Guest < Vagrant::Guest::Base + class Guest < Vagrant.plugin("1", :guest) # Here for whenever it may be used. class SolarisError < Vagrant::Errors::VagrantError error_namespace("vagrant.guest.solaris") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 5c6c8ed18..b4ee73d37 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -59,8 +59,8 @@ en: Instead, please include your Vagrant plugins in your Gemfile itself. guest: invalid_class: |- - The specified guest class does not inherit from `Vagrant::Guest::Base`. - The specified guest class must inherit from this class. + The specified guest class does not inherit from a proper guest + component class. The guest class must inherit from this. The specified guest class was: %{guest} unknown_type: |- diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index 267038917..33241eb32 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -14,6 +14,7 @@ describe Vagrant do it "returns the proper components for version 1" do described_class.plugin("1", :command).should == Vagrant::Plugin::V1::Command described_class.plugin("1", :config).should == Vagrant::Plugin::V1::Config + described_class.plugin("1", :guest).should == Vagrant::Plugin::V1::Guest described_class.plugin("1", :provisioner).should == Vagrant::Plugin::V1::Provisioner end end