Class: VagrantVbguest::Hosts::Base

Inherits:
Object
  • Object
show all
Includes:
VagrantVbguest::Helpers::VmCompatible
Defined in:
lib/vagrant-vbguest/hosts/base.rb

Direct Known Subclasses

VirtualBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VagrantVbguest::Helpers::VmCompatible

#communicate, #driver, included

Constructor Details

#initialize(vm, options = nil) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/vagrant-vbguest/hosts/base.rb', line 11

def initialize(vm, options=nil)
  @vm = vm
  @env = vm.env
  @options = options
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/vagrant-vbguest/hosts/base.rb', line 9

def env
  @env
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/vagrant-vbguest/hosts/base.rb', line 9

def options
  @options
end

#vmObject (readonly)

Returns the value of attribute vm.



9
10
11
# File 'lib/vagrant-vbguest/hosts/base.rb', line 9

def vm
  @vm
end

Instance Method Details

#additions_fileString

Additions-file-detection-magig.

Detection runs in those stages:

  1. Uses the iso_path config option, if present and not set to :auto

  2. Look out for a local additions file

  3. 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

Returns:

  • (String)

    A absolute path to the GuestAdditions iso file. This might be a temp-file, e.g. when downloaded from web.

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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

#cleanupObject

If needed, remove downloaded temp file



65
66
67
# File 'lib/vagrant-vbguest/hosts/base.rb', line 65

def cleanup
  @download.cleanup if @download
end

#read_guest_additions_versionObject



24
25
26
# File 'lib/vagrant-vbguest/hosts/base.rb', line 24

def read_guest_additions_version
  driver.read_guest_additions_version
end

#versionString

Determinates the host’s version

Returns:

  • (String)

    The version code of the host’s virtualisation



20
21
22
# File 'lib/vagrant-vbguest/hosts/base.rb', line 20

def version
  @version ||= driver.version
end