Class: VagrantVbguest::Installer
- Inherits:
-
Object
- Object
- VagrantVbguest::Installer
show all
- Defined in:
- lib/vagrant-vbguest/installer.rb
Overview
Dispatches the installation process to a rigistered Installer implementation.
Defined Under Namespace
Classes: NoInstallerFoundError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(vm, options = {}) ⇒ Installer
Returns a new instance of Installer.
52
53
54
55
56
57
|
# File 'lib/vagrant-vbguest/installer.rb', line 52
def initialize(vm, options = {})
@vm = vm
@env = vm.env
@options = options
@iso_path = nil
end
|
Class Method Details
.detect(vm, options) ⇒ Object
Returns the class of the registered Installer class which matches first (according to it’s priority) or ‘nil` if none matches.
43
44
45
46
47
48
49
|
# File 'lib/vagrant-vbguest/installer.rb', line 43
def detect(vm, options)
@installers.keys.sort.reverse.each do |prio|
klass = @installers[prio].detect { |k| k.match?(vm) }
return klass if klass
end
return nil
end
|
.register(installer_class, prio = 5) ⇒ Object
Register an Installer implementation. All Installer classes which wish to get picked automaticly using their ‘#match?` method have to register. Ad-hoc or small custom Installer meight not need to get registered, but need to get passed as an config option (`installer`)
Registration takes a priority which defines how specific the Installer matches a system. Low level installers, like “linux” or “bsd” use a small priority (2), while distribution installers use higher priority (5). Installers matching a specific version of a distribution should use heigher priority numbers.
31
32
33
34
35
|
# File 'lib/vagrant-vbguest/installer.rb', line 31
def register(installer_class, prio = 5)
@installers ||= {}
@installers[prio] ||= []
@installers[prio] << installer_class
end
|
Instance Method Details
#cleanup ⇒ Object
147
148
149
|
# File 'lib/vagrant-vbguest/installer.rb', line 147
def cleanup
@guest_installer.cleanup if @guest_installer
end
|
Returns an installer instance for the current vm This is either the one configured via ‘installer` option or detected from all registered installers (see detect)
129
130
131
132
133
134
135
136
137
|
# File 'lib/vagrant-vbguest/installer.rb', line 129
def guest_installer
return @guest_installer if @guest_installer
if (klass = guest_installer_class)
@guest_installer = klass.new(@vm, @options)
end
@guest_installer
end
|
#guest_installer_class ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/vagrant-vbguest/installer.rb', line 139
def guest_installer_class
if @options[:installer].is_a?(Class)
@options[:installer]
else
Installer.detect(@vm, @options)
end
end
|
#guest_version(reload = false) ⇒ Object
88
89
90
91
92
|
# File 'lib/vagrant-vbguest/installer.rb', line 88
def guest_version(reload=false)
installer = guest_installer
raise NoInstallerFoundError, :method => 'check guest version of' if !installer
installer.guest_version(reload)
end
|
#host_version ⇒ Object
94
95
96
97
98
|
# File 'lib/vagrant-vbguest/installer.rb', line 94
def host_version
installer = guest_installer
raise NoInstallerFoundError, :method => 'check host version of' if !installer
installer.host_version
end
|
#install ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/vagrant-vbguest/installer.rb', line 59
def install
installer = guest_installer
raise NoInstallerFoundError, :method => 'install' if !installer
installer.install do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
ensure
cleanup
end
|
112
113
114
115
116
|
# File 'lib/vagrant-vbguest/installer.rb', line 112
def provides_vboxadd_tools?
installer = guest_installer
raise NoInstallerFoundError, :method => 'check platform support for vboxadd tools of' if !installer
installer.provides_vboxadd_tools?
end
|
#reboot_after_install? ⇒ Boolean
106
107
108
109
110
|
# File 'lib/vagrant-vbguest/installer.rb', line 106
def reboot_after_install?
installer = guest_installer
raise NoInstallerFoundError, :method => 'check if we need to reboot after installing' if !installer
installer.reboot_after_install?
end
|
#rebuild ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/vagrant-vbguest/installer.rb', line 70
def rebuild
installer = guest_installer
raise NoInstallerFoundError, :method => 'rebuild' if !installer
installer.rebuild do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
end
|
#running? ⇒ Boolean
100
101
102
103
104
|
# File 'lib/vagrant-vbguest/installer.rb', line 100
def running?
installer = guest_installer
raise NoInstallerFoundError, :method => 'check current state of' if !installer
installer.running?
end
|
#start ⇒ Object
79
80
81
82
83
84
85
86
|
# File 'lib/vagrant-vbguest/installer.rb', line 79
def start
installer = guest_installer
raise NoInstallerFoundError, :method => 'manual start' if !installer
installer.start do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
end
|
118
119
120
121
122
|
# File 'lib/vagrant-vbguest/installer.rb', line 118
def vboxadd_tools_available?
installer = guest_installer
raise NoInstallerFoundError, :method => 'check for existing vboxadd tools of' if !installer
installer.vboxadd_tools_available?
end
|