vagrant-vbguest 0.7.0.pre1 → 0.7.0.pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -7,5 +7,5 @@ group :development do
7
7
  # We depend on Vagrant for development, but we don't add it as a
8
8
  # gem dependency because we expect to be installed within the
9
9
  # Vagrant environment itself using `vagrant plugin`.
10
- gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => 'v1.1.2'
11
- end
10
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
11
+ end
@@ -12,6 +12,9 @@ require 'vagrant-vbguest/helpers'
12
12
 
13
13
  require 'vagrant-vbguest/machine'
14
14
 
15
+ require 'vagrant-vbguest/hosts/base'
16
+ require 'vagrant-vbguest/hosts/virtualbox'
17
+
15
18
  require 'vagrant-vbguest/installer'
16
19
  require 'vagrant-vbguest/installers/base'
17
20
  require 'vagrant-vbguest/installers/linux'
@@ -34,7 +34,7 @@ module VagrantVbguest
34
34
 
35
35
  # Use the class if it matches the given URI or if this
36
36
  # is the last class...
37
- if classes.length == (i + 1) || klass.match?(@env[:iso_url])
37
+ if classes.length == (i + 1) || klass.match?(@env[:url])
38
38
  @env[:ui].info I18n.t("vagrant.plugins.vbguest.download.with", :class => klass.to_s)
39
39
  @downloader = klass.new(@env[:ui])
40
40
  break
@@ -45,7 +45,7 @@ module VagrantVbguest
45
45
  # just in case for now.
46
46
  raise Errors::BoxDownloadUnknownType if !@downloader
47
47
 
48
- @downloader.prepare(@env[:iso_url])
48
+ @downloader.prepare(@env[:url]) if @downloader.respond_to?(:prepare)
49
49
  true
50
50
  end
51
51
 
@@ -66,17 +66,17 @@ module VagrantVbguest
66
66
  end
67
67
 
68
68
  def with_tempfile
69
- File.open(iso_temp_path, Platform.tar_file_options) do |tempfile|
69
+ File.open(temp_filename, Platform.tar_file_options) do |tempfile|
70
70
  yield tempfile
71
71
  end
72
72
  end
73
73
 
74
- def iso_temp_path
74
+ def temp_filename
75
75
  @env[:tmp_path].join(BASENAME + Time.now.to_i.to_s)
76
76
  end
77
77
 
78
78
  def download_to(f)
79
- @downloader.download!(@env[:iso_url], f)
79
+ @downloader.download!(@env[:url], f)
80
80
  end
81
81
 
82
82
  end
@@ -0,0 +1,112 @@
1
+ module VagrantVbguest
2
+ module Hosts
3
+ class Base
4
+ include VagrantVbguest::Helpers::VmCompatible
5
+
6
+ attr_reader :env, :vm, :options
7
+
8
+ def initialize(vm, options=nil)
9
+ @vm = vm
10
+ @env = vm.env
11
+ @options = options
12
+ end
13
+
14
+ # Determinates the host's version
15
+ #
16
+ # @return [String] The version code of the *host*'s virtualisation
17
+ def version
18
+ @version ||= driver.version
19
+ end
20
+
21
+
22
+ # Additions-file-detection-magig.
23
+ #
24
+ # Detection runs in those stages:
25
+ # 1. Uses the +iso_path+ config option, if present and not set to +:auto+
26
+ # 2. Look out for a local additions file
27
+ # 3. Use the default web URI
28
+ #
29
+ # If the detected or configured path is not a local file and remote downloads
30
+ # are allowed (the config option +:no_remote+ is NOT set) it will try to
31
+ # download that file into a temp file using Vagrants Downloaders.
32
+ # If remote downloads are prohibited (the config option +:no_remote+ IS set)
33
+ # a +VagrantVbguest::IsoPathAutodetectionError+ will be thrown
34
+ #
35
+ # @return [String] A absolute path to the GuestAdditions iso file.
36
+ # This might be a temp-file, e.g. when downloaded from web.
37
+ def additions_file
38
+ return @additions_file if @additions_file
39
+
40
+ path = options[:iso_path]
41
+ if !path || path.empty? || path == :auto
42
+ path = local_path
43
+ path = web_path if !options[:no_remote] && !path
44
+ end
45
+ raise VagrantVbguest::IsoPathAutodetectionError if !path || path.empty?
46
+
47
+ path = versionize(path)
48
+
49
+ if Vagrant::Downloaders::File.match? path
50
+ @additions_file = path
51
+ else
52
+ # :TODO: This will also raise, if the iso_url points to an invalid local path
53
+ raise VagrantVbguest::DownloadingDisabledError.new(:from => path) if options[:no_remote]
54
+ @additions_file = download path
55
+ end
56
+ end
57
+
58
+ # If needed, remove downloaded temp file
59
+ def cleanup
60
+ @download.cleanup if @download
61
+ end
62
+
63
+ protected
64
+
65
+ # Default web URI, where "additions file" can be downloaded.
66
+ #
67
+ # @return [String] A URI template containing the versions placeholder.
68
+ def web_path
69
+ raise NotImplementedError
70
+ end
71
+
72
+ # Finds the "additions file" on the host system.
73
+ # Returns +nil+ if none found.
74
+ #
75
+ # @return [String] Absolute path to the local "additions file", or +nil+ if not found.
76
+ def local_path
77
+ raise NotImplementedError
78
+ end
79
+
80
+ # replaces the veriosn placeholder with the additions
81
+ # version string
82
+ #
83
+ # @param [String] A path or URL (or any other String)
84
+ #
85
+ # @retrun [String] A copy of the passed string, with verision
86
+ # placeholder replaced
87
+ def versionize(path)
88
+ path % {:version => version}
89
+ end
90
+
91
+ # Kicks off +VagrantVbguest::Download+ to download the additions file
92
+ # into a temp file.
93
+ #
94
+ # To remove the created tempfile call +cleanup+
95
+ #
96
+ # @param [String] The path or URI to download
97
+ #
98
+ # @return [String] The path to the downloaded file
99
+ def download(path)
100
+ downloader_env = {
101
+ :ui => @env.ui,
102
+ :tmp_path => @env.tmp_path,
103
+ :url => path
104
+ }
105
+ @download = VagrantVbguest::Download.new(downloader_env)
106
+ @download.download
107
+ @download.temp_path
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,86 @@
1
+ module VagrantVbguest
2
+ module Hosts
3
+ class VirtualBox < Base
4
+
5
+ protected
6
+
7
+ # Default web URI, where GuestAdditions iso file can be downloaded.
8
+ #
9
+ # @return [String] A URI template containing the versions placeholder.
10
+ def web_path
11
+ "http://download.virtualbox.org/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"
12
+ end
13
+
14
+
15
+ # Finds GuestAdditions iso file on the host system.
16
+ # Returns +nil+ if none found.
17
+ #
18
+ # @return [String] Absolute path to the local GuestAdditions iso file, or +nil+ if not found.
19
+ def local_path
20
+ media_manager_iso || guess_local_iso
21
+ end
22
+
23
+ private
24
+
25
+ # Helper method which queries the VirtualBox media manager
26
+ # for a +VBoxGuestAdditions.iso+ file.
27
+ # Returns +nil+ if none found.
28
+ #
29
+ # @return [String] Absolute path to the local GuestAdditions iso file, or +nil+ if not found.
30
+ def media_manager_iso
31
+ (m = driver.execute('list', 'dvds').match(/^.+:\s+(.*VBoxGuestAdditions(?:_#{version})?\.iso)$/i)) && m[1]
32
+ end
33
+
34
+ # Find the first GuestAdditions iso file which exists on the host system
35
+ #
36
+ # @return [String] Absolute path to the local GuestAdditions iso file, or +nil+ if not found.
37
+ def guess_local_iso
38
+ Array(platform_path).find do |path|
39
+ path && File.exists?(path)
40
+ end
41
+ end
42
+
43
+ # Makes an educated guess where the GuestAdditions iso file
44
+ # could be found on the host system depending on the OS.
45
+ # Returns +nil+ if no the file is not in it's place.
46
+ def platform_path
47
+ [:linux, :darwin, :cygwin, :windows].each do |sys|
48
+ return self.send("#{sys}_path") if Vagrant::Util::Platform.respond_to?("#{sys}?") && Vagrant::Util::Platform.send("#{sys}?")
49
+ end
50
+ nil
51
+ end
52
+
53
+ # Makes an educated guess where the GuestAdditions iso file
54
+ # on linux based systems
55
+ def linux_path
56
+ paths = ["/usr/share/virtualbox/VBoxGuestAdditions.iso"]
57
+ paths.unshift(File.join(ENV['HOME'], '.VirtualBox', "VBoxGuestAdditions_#{version}.iso")) if ENV['HOME']
58
+ paths
59
+ end
60
+
61
+ # Makes an educated guess where the GuestAdditions iso file
62
+ # on Macs
63
+ def darwin_path
64
+ "/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"
65
+ end
66
+
67
+ # Makes an educated guess where the GuestAdditions iso file
68
+ # on windows systems
69
+ def windows_path
70
+ if (p = ENV["VBOX_INSTALL_PATH"]) && !p.empty?
71
+ File.join(p, "VBoxGuestAdditions.iso")
72
+ elsif (p = ENV["PROGRAM_FILES"] || ENV["ProgramW6432"] || ENV["PROGRAMFILES"]) && !p.empty?
73
+ File.join(p, "/Oracle/VirtualBox/VBoxGuestAdditions.iso")
74
+ end
75
+ end
76
+ alias_method :cygwin_path, :windows_path
77
+
78
+ # overwrite the default version string to allow lagacy
79
+ # '$VBOX_VERSION' as a placerholder
80
+ def versionize(path)
81
+ super(path.gsub('$VBOX_VERSION', version))
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -91,7 +91,7 @@ module VagrantVbguest
91
91
  def host_version
92
92
  installer = guest_installer
93
93
  raise NoInstallerFoundError, :method => 'check host version of' if !installer
94
- installer.host_version
94
+ installer.host.version
95
95
  end
96
96
 
97
97
  def running?
@@ -25,12 +25,14 @@ module VagrantVbguest
25
25
  false
26
26
  end
27
27
 
28
- attr_reader :env, :vm, :options
28
+ attr_reader :env, :vm, :options, :host
29
29
 
30
30
  def initialize(vm, options=nil)
31
31
  @vm = vm
32
32
  @env = vm.env
33
33
  @options = options
34
+
35
+ @host = VagrantVbguest::Hosts::VirtualBox.new(vm, options)
34
36
  end
35
37
 
36
38
  # The absolute file path of the GuestAdditions iso file should
@@ -124,12 +126,6 @@ module VagrantVbguest
124
126
  @guest_version = guest_version
125
127
  end
126
128
 
127
- # Determinates the host's version
128
- #
129
- # @return [String] The version code of the Virtual Box *host*
130
- def host_version
131
- driver.version
132
- end
133
129
 
134
130
  # Determinates the version of the GuestAdditions installer in use
135
131
  #
@@ -159,7 +155,7 @@ module VagrantVbguest
159
155
  def yield_rebuild_warning
160
156
  @env.ui.warn I18n.t("vagrant.plugins.vbguest.rebuild#{@options[:force] ? '_forced' : ''}",
161
157
  :guest_version => guest_version(true),
162
- :host_version => host_version)
158
+ :host_version => @host.version)
163
159
  end
164
160
 
165
161
  # Helper to yield a warning message to the user in the event that the
@@ -173,102 +169,17 @@ module VagrantVbguest
173
169
  :installer_version => installer_version(path_to_installer) || I18n.t("vagrant.plugins.vbguest.unknown"))
174
170
  end
175
171
 
176
- # GuestAdditions-iso-file-detection-magig.
177
- #
178
- # Detectio runs in those stages:
179
- # 1. Uses the +iso_path+ config option, if present and not set to +:auto+
180
- # 2. Look out for a local iso file
181
- # 3. Use the default web URI
182
- #
183
- # If the detected or configured path is not a local file and remote downloads
184
- # are allowed (the config option +:no_remote+ is NOT set) it will try to
185
- # download that file into a temp file using Vagrants Downloaders.
186
- # If remote downloads are prohibited (the config option +:no_remote+ IS set)
187
- # a +VagrantVbguest::IsoPathAutodetectionError+ will be thrown
188
- #
189
- # @return [String] A absolute path to the GuestAdditions iso file.
190
- # This might be a temp-file, e.g. when downloaded from web.
191
172
  def iso_file
192
- @iso_file ||= begin
193
- iso_path = options[:iso_path]
194
- if !iso_path || iso_path.empty? || iso_path == :auto
195
- iso_path = local_iso_path
196
- iso_path = web_iso_path if !iso_path || iso_path.empty? && !options[:no_remote]
197
- end
198
- raise VagrantVbguest::IsoPathAutodetectionError if !iso_path || iso_path.empty?
199
-
200
- version = host_version
201
- iso_path = iso_path.gsub('$VBOX_VERSION', version) % {:version => version}
202
- if Vagrant::Downloaders::File.match? iso_path
203
- iso_path
204
- else
205
- # :TODO: This will also raise, if the iso_url points to an invalid local path
206
- raise VagrantVbguest::DownloadingDisabledError.new(:from => iso_path) if options[:no_remote]
207
- downloader_env = {
208
- :ui => @env.ui,
209
- :tmp_path => @env.tmp_path,
210
- :iso_url => iso_path
211
- }
212
- @download = VagrantVbguest::Download.new(downloader_env)
213
- @download.download
214
- @download.temp_path
215
- end
216
- end
217
- end
218
-
219
- # Default web URI, where GuestAdditions iso file can be downloaded.
220
- #
221
- # @return [String] A URI template containing the versions placeholder.
222
- def web_iso_path
223
- "http://download.virtualbox.org/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"
224
- end
225
-
226
- # Finds GuestAdditions iso file on the host system.
227
- # Returns +nil+ if none found.
228
- #
229
- # @return [String] Absolute path to the local GuestAdditions iso file, or +nil+ if not found.
230
- def local_iso_path
231
- media_manager_iso || guess_iso
232
- end
233
-
234
- # Helper method which queries the VirtualBox media manager
235
- # for a +VBoxGuestAdditions.iso+ file.
236
- # Returns +nil+ if none found.
237
- #
238
- # @return [String] Absolute path to the local GuestAdditions iso file, or +nil+ if not found.
239
- def media_manager_iso
240
- (m = driver.execute('list', 'dvds').match(/^.+:\s+(.*VBoxGuestAdditions(?:_#{guest_version})?\.iso)$/i)) && m[1]
241
- end
242
-
243
- # Makes an educated guess where the GuestAdditions iso file
244
- # could be found on the host system depending on the OS.
245
- # Returns +nil+ if no the file is not in it's place.
246
- #
247
- # @return [String] Absolute path to the local GuestAdditions iso file, or +nil+ if not found.
248
- def guess_iso
249
- paths = if Vagrant::Util::Platform.linux?
250
- [
251
- (File.join(ENV['HOME'], '.VirtualBox', "VBoxGuestAdditions_#{guest_version}.iso") if ENV['HOME']),
252
- "/usr/share/virtualbox/VBoxGuestAdditions.iso"
253
- ]
254
- elsif Vagrant::Util::Platform.darwin?
255
- "/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"
256
- elsif Vagrant::Util::Platform.windows?
257
- if (p = ENV["VBOX_INSTALL_PATH"]) && !p.empty?
258
- File.join(p, "VBoxGuestAdditions.iso")
259
- elsif ENV["PROGRAM_FILES"] || ENV["ProgramW6432"] || ENV["PROGRAMFILES"]
260
- File.join((ENV["PROGRAM_FILES"] || ENV["ProgramW6432"] || ENV["PROGRAMFILES"]), "/Oracle/VirtualBox/VBoxGuestAdditions.iso")
261
- end
262
- end
263
- Array(paths).find { |path| path && File.exists?(path) }
173
+ @host.additions_file
264
174
  end
175
+ alias_method :additions_file, :iso_file
265
176
 
266
177
  # A helper method to handle the GuestAdditions iso file upload
267
178
  # into the guest box.
268
179
  # The file will uploaded to the location given by the +temp_path+ method.
269
180
  #
270
181
  # @example Default upload
271
- # upload(iso_file)
182
+ # upload(file)
272
183
  #
273
184
  # @param [String] Path of the file to upload to the +tmp_path*
274
185
  def upload(file)
@@ -279,7 +190,7 @@ module VagrantVbguest
279
190
  # A helper method to delete the uploaded GuestAdditions iso file
280
191
  # from the guest box
281
192
  def cleanup
282
- @download.cleanup if @download
193
+ @host.cleanup
283
194
  communicate.execute("test -f #{tmp_path} && rm #{tmp_path}", :error_check => false) do |type, data|
284
195
  env.ui.error(data.chomp, :prefix => false)
285
196
  end
@@ -14,20 +14,6 @@ module VagrantVbguest
14
14
  @logger.debug("initialize vbguest machine for VM '#{vm.name}' (#{vm.to_s})")
15
15
 
16
16
  @installer = Installer.new vm, options
17
-
18
- @ga_machine = MicroMachine.new(:pending).tap { |m|
19
- m.when :install, :pending => :installed
20
- m.when :start, :pending => :started
21
- m.when :rebuild, :pending => :rebuilt, :started => :rebuilt
22
-
23
- m.on(:installed) { installer.install }
24
- m.on(:started) { installer.start }
25
- m.on(:rebuilt) { installer.rebuild }
26
- }
27
-
28
- @box_machine = MicroMachine.new(:first_boot).tap { |m|
29
- m.when :reboot, :first_boot => :rebooted
30
- }
31
17
  end
32
18
 
33
19
  def run
@@ -47,24 +33,24 @@ module VagrantVbguest
47
33
 
48
34
  def install
49
35
  return env.ui.warn(I18n.t("vagrant.plugins.vbguest.skipped_installation")) if options[:no_install] && !options[:force]
50
- @ga_machine.trigger :install
36
+ guest_additions_state.trigger :install
51
37
  end
52
38
 
53
39
  def rebuild
54
40
  return env.ui.warn(I18n.t("vagrant.plugins.vbguest.skipped_rebuild")) if options[:no_install] && !options[:force]
55
- @ga_machine.trigger :rebuild
41
+ guest_additions_state.trigger :rebuild
56
42
  end
57
43
 
58
44
  def start
59
- @ga_machine.trigger :start
45
+ guest_additions_state.trigger :start
60
46
  end
61
47
 
62
- def installation_ran?; @ga_machine == :installed end
63
- def started?; @ga_machine == :started end
64
- def rebuilt?; @ga_machine == :rebuilt end
48
+ def installation_ran?; guest_additions_state == :installed end
49
+ def started?; guest_additions_state == :started end
50
+ def rebuilt?; guest_additions_state == :rebuilt end
65
51
 
66
- def reboot; @box_machine.trigger :reboot end
67
- def reboot?; @box_machine.state == :rebooted end
52
+ def reboot; box_state.trigger :reboot end
53
+ def reboot?; box_state.state == :rebooted end
68
54
 
69
55
  def steps(state)
70
56
  case state
@@ -95,5 +81,25 @@ module VagrantVbguest
95
81
  :guest_version => installer.guest_version
96
82
  }
97
83
  end
84
+
85
+ protected
86
+
87
+ def guest_additions_state
88
+ @guest_additions_state ||= MicroMachine.new(:pending).tap { |m|
89
+ m.when :install, :pending => :installed
90
+ m.when :start, :pending => :started
91
+ m.when :rebuild, :pending => :rebuilt, :started => :rebuilt
92
+
93
+ m.on(:installed) { installer.install }
94
+ m.on(:started) { installer.start }
95
+ m.on(:rebuilt) { installer.rebuild }
96
+ }
97
+ end
98
+
99
+ def box_state
100
+ @box_state ||= MicroMachine.new(:first_boot).tap { |m|
101
+ m.when :reboot, :first_boot => :rebooted
102
+ }
103
+ end
98
104
  end
99
105
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantVbguest
2
- VERSION = "0.7.0.pre1"
2
+ VERSION = "0.7.0.pre2"
3
3
  end
@@ -13,6 +13,9 @@ require 'vagrant-vbguest/helpers'
13
13
 
14
14
  require 'vagrant-vbguest/machine'
15
15
 
16
+ require 'vagrant-vbguest/hosts/base'
17
+ require 'vagrant-vbguest/hosts/virtualbox'
18
+
16
19
  require 'vagrant-vbguest/installer'
17
20
  require 'vagrant-vbguest/installers/base'
18
21
  require 'vagrant-vbguest/installers/linux'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vbguest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.pre1
4
+ version: 0.7.0.pre2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: micromachine
@@ -96,6 +96,8 @@ files:
96
96
  - lib/vagrant-vbguest/download.rb
97
97
  - lib/vagrant-vbguest/errors.rb
98
98
  - lib/vagrant-vbguest/helpers.rb
99
+ - lib/vagrant-vbguest/hosts/base.rb
100
+ - lib/vagrant-vbguest/hosts/virtualbox.rb
99
101
  - lib/vagrant-vbguest/installer.rb
100
102
  - lib/vagrant-vbguest/installers/base.rb
101
103
  - lib/vagrant-vbguest/installers/debian.rb
@@ -123,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
125
  version: '0'
124
126
  segments:
125
127
  - 0
126
- hash: 1097977286854134739
128
+ hash: 3162000350700078297
127
129
  required_rubygems_version: !ruby/object:Gem::Requirement
128
130
  none: false
129
131
  requirements: