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
79
80
81
82
83
84
|
# File 'lib/vagrant-vbguest/installer.rb', line 79
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.
61
62
63
64
65
66
67
|
# File 'lib/vagrant-vbguest/installer.rb', line 61
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
|
.get(key) ⇒ Class?
Returns the registered Installer class for the given key.
74
75
76
|
# File 'lib/vagrant-vbguest/installer.rb', line 74
def get(key)
@registered[key.to_s]
end
|
.register(*args) ⇒ 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.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/vagrant-vbguest/installer.rb', line 32
def register(*args)
installer_key = nil
installer_class = nil
prio = 5
if args.first.is_a?(Symbol) || args.first.is_a?(String)
installer_key = args.first.to_s
installer_class = args[1]
prio = args[2] if args[2]
else
warn "DEPRECATION: Passing Installer class directly to Installer.register is deprecated. Please use a registration identifier as first argument. `Installer.register(:my_system, MySystemInstaller, 1)`"
installer_class = args.first
prio = args[1] if args[1]
end
@installers ||= {}
@installers[prio] ||= Set.new
@installers[prio] << installer_class
@registered ||= {}
@registered[installer_key] = installer_class if installer_key
end
|
Instance Method Details
#cleanup ⇒ Object
183
184
185
186
187
188
189
|
# File 'lib/vagrant-vbguest/installer.rb', line 183
def cleanup
return unless @guest_installer
@guest_installer.cleanup do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
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)
162
163
164
165
166
167
168
169
170
|
# File 'lib/vagrant-vbguest/installer.rb', line 162
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
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/vagrant-vbguest/installer.rb', line 172
def guest_installer_class
case (installer = @options[:installer])
when Class
installer
when Symbol, String
Installer.get(installer)
else
Installer.detect(@vm, @options)
end
end
|
#guest_version(reload = false) ⇒ Object
121
122
123
124
125
|
# File 'lib/vagrant-vbguest/installer.rb', line 121
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
127
128
129
130
131
|
# File 'lib/vagrant-vbguest/installer.rb', line 127
def host_version
installer = guest_installer
raise NoInstallerFoundError, :method => 'check host version of' if !installer
installer.host_version
end
|
#install ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/vagrant-vbguest/installer.rb', line 86
def install
installer = guest_installer
raise NoInstallerFoundError, :method => 'install' if !installer
with_hooks(:install) do
installer.install do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
end
ensure
cleanup
end
|
145
146
147
148
149
|
# File 'lib/vagrant-vbguest/installer.rb', line 145
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
139
140
141
142
143
|
# File 'lib/vagrant-vbguest/installer.rb', line 139
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
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/vagrant-vbguest/installer.rb', line 99
def rebuild
installer = guest_installer
raise NoInstallerFoundError, :method => 'rebuild' if !installer
with_hooks(:rebuild) do
installer.rebuild do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
end
end
|
#run_hook(hook_name) ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/vagrant-vbguest/installer.rb', line 199
def run_hook(hook_name)
hooks = @options.dig(:installer_hooks, hook_name)
return if !hooks || hooks.empty?
@vm.ui.info I18n.t("vagrant_vbguest.installer_hooks.#{hook_name}")
Array(hooks).each do |l|
@vm.communicate.sudo(l) do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
end
end
|
#running? ⇒ Boolean
133
134
135
136
137
|
# File 'lib/vagrant-vbguest/installer.rb', line 133
def running?
installer = guest_installer
raise NoInstallerFoundError, :method => 'check current state of' if !installer
installer.running?
end
|
#start ⇒ Object
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/vagrant-vbguest/installer.rb', line 110
def start
installer = guest_installer
raise NoInstallerFoundError, :method => 'manual start' if !installer
with_hooks(:start) do
installer.start do |type, data|
@env.ui.info(data, :prefix => false, :new_line => false)
end
end
end
|
151
152
153
154
155
|
# File 'lib/vagrant-vbguest/installer.rb', line 151
def vboxadd_tools_available?
installer = guest_installer
raise NoInstallerFoundError, :method => 'check for existing vboxadd tools of' if !installer
installer.vboxadd_tools_available?
end
|
#with_hooks(step_name) ⇒ Object
191
192
193
194
195
196
197
|
# File 'lib/vagrant-vbguest/installer.rb', line 191
def with_hooks(step_name)
run_hook(:"before_#{step_name}")
ret = yield
run_hook(:"after_#{step_name}")
ret
end
|