class VagrantVbguest::Hosts::Base
Attributes
Public Class Methods
# File lib/vagrant-vbguest/hosts/base.rb, line 11 def initialize(vm, options=nil) @vm = vm @env = vm.env @options = options end
Public Instance Methods
Additions-file-detection-magig.
Detection runs in those stages:
-
Uses the
iso_path
config option, if present and not set to:auto
-
Look out for a local additions file
-
Use the default web URI
If the detected or configured path is not a local file and remote downloads are allowed (the config option :no_remote
is NOT set) it will try to download that file into a temp file using Vagrants Downloaders. If remote downloads are prohibited (the config option :no_remote
IS set) a VagrantVbguest::IsoPathAutodetectionError
will be thrown
@return [String] A absolute path to the GuestAdditions iso file.
This might be a temp-file, e.g. when downloaded from web.
# File lib/vagrant-vbguest/hosts/base.rb, line 43 def additions_file return @additions_file if @additions_file path = options[:iso_path] if !path || path.empty? || path == :auto path = local_path path = web_path if !options[:no_remote] && !path end raise VagrantVbguest::IsoPathAutodetectionError if !path || path.empty? path = versionize(path) if file_match? path @additions_file = path else # :TODO: This will also raise, if the iso_url points to an invalid local path raise VagrantVbguest::DownloadingDisabledError.new(:from => path) if options[:no_remote] @additions_file = download path end end
If needed, remove downloaded temp file
# File lib/vagrant-vbguest/hosts/base.rb, line 65 def cleanup @download.cleanup if @download end
# File lib/vagrant-vbguest/hosts/base.rb, line 24 def read_guest_additions_version driver.read_guest_additions_version end
Determinates the host’s version
@return [String] The version code of the host’s virtualisation
# File lib/vagrant-vbguest/hosts/base.rb, line 20 def version @version ||= driver.version end
Protected Instance Methods
Kicks off VagrantVbguest::Download
to download the additions file into a temp file.
To remove the created tempfile call cleanup
@param path [String] The path or URI to download
@return [String] The path to the downloaded file
# File lib/vagrant-vbguest/hosts/base.rb, line 114 def download(path) @download = VagrantVbguest::Download.new(path, @env.tmp_path, :ui => @env.ui) @download.download! @download.destination end
fix bug when the vagrant version is higher than 1.2, by moving method Vagrant::Vagrant::File.match? here
# File lib/vagrant-vbguest/hosts/base.rb, line 72 def file_match?(uri) extracted = ::URI.extract(uri, "file") return true if extracted && extracted.include?(uri) return ::File.file?(::File.expand_path(uri)) end
Finds the “additions file” on the host system. Returns nil
if none found.
@return [String] Absolute path to the local “additions file”, or nil
if not found.
# File lib/vagrant-vbguest/hosts/base.rb, line 91 def local_path raise NotImplementedError end
replaces the veriosn placeholder with the additions version string
@param path [String] A path or URL (or any other String)
@return [String] A copy of the passed string, with verision
placeholder replaced
# File lib/vagrant-vbguest/hosts/base.rb, line 102 def versionize(path) path % {:version => version} end
Default web URI, where “additions file” can be downloaded.
@return [String] A URI template containing the versions placeholder.
# File lib/vagrant-vbguest/hosts/base.rb, line 83 def web_path raise NotImplementedError end