Class: VagrantVbguest::Installers::Base
- Inherits:
-
Object
- Object
- VagrantVbguest::Installers::Base
- Includes:
- Helpers::VmCompatible
- Defined in:
- lib/vagrant-vbguest/installers/base.rb
Overview
This is the base class all installers must inherit from It defines the basic structure of an Installer and should never be used directly
Direct Known Subclasses
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Class Method Summary collapse
-
.distro(vm) ⇒ Symbol
A helper method to cache the result of Vagrant::Guest::Base#distro_dispatch which speeds up Installer detection runs a lot, when having lots of Linux based Installer classes to check.
-
.match?(vm) ⇒ Boolean
Tests whether this installer class is applicable to the current environment.
Instance Method Summary collapse
-
#cleanup ⇒ Object
A helper method to delete the uploaded GuestAdditions iso file from the guest box.
-
#guest_version(reload = false) ⇒ String
Determinates the GuestAdditions version installed on the guest system.
-
#initialize(vm, options = nil) ⇒ Base
constructor
A new instance of Base.
-
#install(opts = nil) {|type, data| ... } ⇒ Object
Handles the installation process.
-
#installer_version(path_to_installer) ⇒ String
Determinates the version of the GuestAdditions installer in use.
- #iso_file ⇒ Object (also: #additions_file)
-
#mount_point ⇒ String
The mountpoint path Subclasses shall override this method, if they need to mount the uploaded file!.
-
#rebuild(opts = nil) {|type, data| ... } ⇒ Object
Handels the rebuild of allready running GuestAdditions It may happen, that the guest has the correct GuestAdditions version running, but not the kernel module is not running.
-
#running?(opts = nil, &block) ⇒ Boolean
Determinates if the GuestAdditions kernel module is loaded.
-
#start(opts = nil) {|type, data| ... } ⇒ Object
Restarts the allready installed GuestAdditions It may happen, that the guest has the correct GuestAdditions version installed, but for some reason are not (yet) runnig.
-
#tmp_path ⇒ String
The absolute file path of the GuestAdditions iso file should be uploaded into the guest.
-
#upload(file) ⇒ Object
A helper method to handle the GuestAdditions iso file upload into the guest box.
-
#yield_installation_error_warning(path_to_installer) ⇒ Object
(also: #yield_installation_waring)
Helper to yield a warning message to the user in the event that the installer returned a non-zero exit status.
-
#yield_installation_warning(path_to_installer) ⇒ Object
Helper to yield a warning message to the user, that the installation will start now.
-
#yield_rebuild_warning ⇒ Object
Helper to yield a warning message to the user, that the installation will be rebuild using the installed GuestAdditions.
Methods included from Helpers::VmCompatible
#communicate, #driver, included
Constructor Details
#initialize(vm, options = nil) ⇒ Base
Returns a new instance of Base.
42 43 44 45 46 47 48 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 42 def initialize(vm, =nil) @vm = vm @env = vm.env @options = @host = VagrantVbguest::Hosts::VirtualBox.new(vm, ) end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
40 41 42 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 40 def env @env end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
40 41 42 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 40 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
40 41 42 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 40 def @options end |
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
40 41 42 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 40 def vm @vm end |
Class Method Details
.distro(vm) ⇒ Symbol
A helper method to cache the result of Vagrant::Guest::Base#distro_dispatch which speeds up Installer detection runs a lot, when having lots of Linux based Installer classes to check.
35 36 37 38 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 35 def self.distro(vm) @@distro ||= {} @@distro[ vm_id(vm) ] ||= distro_name vm end |
.match?(vm) ⇒ Boolean
Tests whether this installer class is applicable to the current environment. Usually, testing for a specific OS. Subclasses must override this method and return ‘true` if they wish to handle.
This method will be called only when an Installer detection is run. It is ignored, when passing an Installer class directly as an config (‘installer`) option.
24 25 26 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 24 def self.match?(vm) false end |
Instance Method Details
#cleanup ⇒ Object
A helper method to delete the uploaded GuestAdditions iso file from the guest box
206 207 208 209 210 211 212 213 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 206 def cleanup unless [:no_cleanup] @host.cleanup communicate.execute("test -f #{tmp_path} && rm #{tmp_path}", :error_check => false) do |type, data| env.ui.error(data.chomp, :prefix => false) end end end |
#guest_version(reload = false) ⇒ String
Determinates the GuestAdditions version installed on the guest system.
132 133 134 135 136 137 138 139 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 132 def guest_version(reload=false) return @guest_version if @guest_version && !reload guest_version = driver.read_guest_additions_version guest_version = !guest_version ? nil : guest_version[/\d+\.\d+\.\d+/] @guest_version = guest_version end |
#install(opts = nil) {|type, data| ... } ⇒ Object
Handles the installation process. All necessary steps for an installation must be defined here. This includes uploading the iso into the box, mounting, installing and cleaning up. The path to the local iso file should be obtained by calling iso_file
Subclasses must override this method!
76 77 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 76 def install(opts=nil, &block) end |
#installer_version(path_to_installer) ⇒ String
Determinates the version of the GuestAdditions installer in use
145 146 147 148 149 150 151 152 153 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 145 def installer_version(path_to_installer) version = nil communicate.sudo("#{path_to_installer} --info", :error_check => false) do |type, data| if (v = data.to_s.match(/\AIdentification.*\s(\d+\.\d+.\d+)/i)) version = v[1] end end version end |
#iso_file ⇒ Object Also known as: additions_file
186 187 188 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 186 def iso_file @host.additions_file end |
#mount_point ⇒ String
The mountpoint path Subclasses shall override this method, if they need to mount the uploaded file!
62 63 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 62 def mount_point end |
#rebuild(opts = nil) {|type, data| ... } ⇒ Object
Handels the rebuild of allready running GuestAdditions It may happen, that the guest has the correct GuestAdditions version running, but not the kernel module is not running. This method should perform a rebuild or try to reload the kernel module without the GuestAdditions iso file. If there is no way of rebuidling or reloading the GuestAdditions on a specific system, this method should left empty. Subclasses should override this method.
93 94 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 93 def rebuild(opts=nil, &block) end |
#running?(opts = nil, &block) ⇒ Boolean
Determinates if the GuestAdditions kernel module is loaded. This method tests if there is a working GuestAdditions kernel module. If there is none, #rebuild is beeing called. If there is no way of telling if there is a working GuestAddition for a specific system, this method should return ‘true`. Subclasses should override this method.
121 122 123 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 121 def running?(opts=nil, &block) true end |
#start(opts = nil) {|type, data| ... } ⇒ Object
Restarts the allready installed GuestAdditions It may happen, that the guest has the correct GuestAdditions version installed, but for some reason are not (yet) runnig. This method should execute the GuestAdditions system specific init script in order to start it manually. If there is no way of doing this on a specific system, this method should left empty. Subclasses should override this method.
109 110 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 109 def start(opts=nil, &block) end |
#tmp_path ⇒ String
The absolute file path of the GuestAdditions iso file should be uploaded into the guest. Subclasses must override this method!
55 56 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 55 def tmp_path end |
#upload(file) ⇒ Object
A helper method to handle the GuestAdditions iso file upload into the guest box. The file will uploaded to the location given by the temp_path
method.
199 200 201 202 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 199 def upload(file) env.ui.info(I18n.t("vagrant_vbguest.start_copy_iso", :from => file, :to => tmp_path)) communicate.upload(file, tmp_path) end |
#yield_installation_error_warning(path_to_installer) ⇒ Object Also known as: yield_installation_waring
Helper to yield a warning message to the user in the event that the installer returned a non-zero exit status. Because lack of a window system will cause this result in VirtualBox 4.2.8+, we don’t want to kill the entire boot process, but we do want to make sure the user knows there could be a problem. The message includles the installer version.
179 180 181 182 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 179 def yield_installation_error_warning(path_to_installer) @env.ui.warn I18n.t("vagrant_vbguest.install_error", :installer_version => installer_version(path_to_installer) || I18n.t("vagrant_vbguest.unknown")) end |
#yield_installation_warning(path_to_installer) ⇒ Object
Helper to yield a warning message to the user, that the installation will start now. The message includes the host and installer version strings.
158 159 160 161 162 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 158 def yield_installation_warning(path_to_installer) @env.ui.warn I18n.t("vagrant_vbguest.installing#{@options[:force] ? '_forced' : ''}", :guest_version => (guest_version || I18n.t("vagrant_vbguest.unknown")), :installer_version => installer_version(path_to_installer) || I18n.t("vagrant_vbguest.unknown")) end |
#yield_rebuild_warning ⇒ Object
Helper to yield a warning message to the user, that the installation will be rebuild using the installed GuestAdditions. The message includes the host and installer version strings.
167 168 169 170 171 |
# File 'lib/vagrant-vbguest/installers/base.rb', line 167 def yield_rebuild_warning @env.ui.warn I18n.t("vagrant_vbguest.rebuild#{@options[:force] ? '_forced' : ''}", :guest_version => guest_version(true), :host_version => @host.version) end |