vagrant-export 0.3.8 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8f0ea634ac85a2b665cdc0361595517b92f6937
4
- data.tar.gz: 46e778a223f126e41c9eaa35037eaf6bf0006dbe
3
+ metadata.gz: b1122a5f92b1f785a5bc0d32aecaa8081d1bedc3
4
+ data.tar.gz: eafee68a5a8575bba9adb5c2508aa4b347247cf3
5
5
  SHA512:
6
- metadata.gz: 11371c4ce8c2fcaec74d8b43fb18b67c7b64f6f5878b4a8b78c2f66cd7d7c0910f541dd6d95c77c8ae2fdf73939777e1301238e099a97bbe6d168fb4a43b13fd
7
- data.tar.gz: 073cb31479b171f97f17d2c992b6d4cdedc2fd2950a679ac58f6352540b54951e86e6b678a4a94f30286da66af7866f4daecd12ae79fe2b2abc928a3a29252b7
6
+ metadata.gz: a2bbed4f4bac8dbf1ed8a63f2dbb82129422cf972ff82edce2dcffd69795b7e9843da9d181cd3ae30a9c3fd09476350e9bcf91cec147001bf86b0cb79302e441
7
+ data.tar.gz: e01f513a7ce4000e45fbf592ddfdffed942904e69981daa376b7234270792a851074472177c617bfddc359700afeec447655f0e2fd23da649a5225af40017b7b
@@ -122,62 +122,6 @@ module VagrantPlugins
122
122
  end
123
123
  end
124
124
 
125
-
126
- # Add the private key if we have one
127
- # Shamelessly stolen from Vagrant::Action::General::Package
128
- def setup_private_key
129
-
130
- # Key generated by vagrant
131
- path = @vm.data_dir.join('private_key').to_s
132
-
133
- # Use a different generated key if configured
134
- if @private_key != nil
135
- path = @private_key.to_s
136
- end
137
-
138
- # If we don't have a generated private key, we do nothing
139
- return unless File.file?(path)
140
-
141
- # Copy it into our box directory
142
- new_path = File.join(@tmp_path, 'private_key')
143
- @logger.debug("Copy private key from #{path} to #{new_path}")
144
- FileUtils.cp(path, new_path)
145
-
146
- # Append it to the Vagrantfile (or create a Vagrantfile)
147
- vf_path = File.join(@tmp_path, 'Vagrantfile')
148
- mode = 'w+'
149
-
150
- @logger.debug("Check and add private_key_path setting to #{vf_path}")
151
-
152
- if File.file?(vf_path)
153
- mode = 'a'
154
- has_private_key_path = false
155
-
156
- @logger.debug('Vagrantfile exists, check for private_key_path')
157
-
158
- File.readlines(vf_path).each { |line|
159
- if line.to_s =~ /ssh\.private_key_path/i
160
- has_private_key_path = true
161
- end
162
- }
163
-
164
- if has_private_key_path
165
- @logger.debug('Existing Vagrantfile already has a private_key_path setting')
166
- return
167
- end
168
- else
169
- @logger.debug('No Vagrantfile found, create one')
170
- end
171
-
172
- File.open(vf_path, mode) do |f|
173
- f.binmode
174
- f.puts
175
- f.puts %Q[Vagrant.configure("2") do |config|]
176
- f.puts %Q[ config.ssh.private_key_path = File.expand_path("../private_key", __FILE__)]
177
- f.puts %Q[end]
178
- end
179
- end
180
-
181
125
  def export
182
126
  # Halt the machine
183
127
  if @vm.state.short_description == 'running'
@@ -203,11 +147,8 @@ module VagrantPlugins
203
147
 
204
148
  @logger.debug("Files found in #{current_dir}: #{files}")
205
149
 
206
- files.select! {|f| !File.directory?(f) }
207
- files.select!{ |f| f !~ /\.log$/ }
208
- files.select!{ |f| f !~ /core$/ }
209
- files.select!{ |f| f !~ /\.gz$/ }
210
- files.select!{ |f| f !~ /.lck$/ }
150
+ files.select! { |f| !File.directory?(f) }
151
+ files.select! { |f| f ~ /\.(vmdk|nvram|vmtm|vmx|vmxf)$/ }
211
152
 
212
153
  @logger.debug("Copying #{files} to #{exported_path}")
213
154
 
@@ -216,11 +157,8 @@ module VagrantPlugins
216
157
  @vm.ui.info('Compacting Vmware virtual disks')
217
158
 
218
159
  Dir.glob(File.join(exported_path, '**', '*.vmdk')) { |f|
219
-
220
- @logger.debug("Running 'vmware-vdiskmanager -d #{f}'")
160
+ @logger.debug("Compacting disk file #{f}")
221
161
  Vagrant::Util::Subprocess.execute('vmware-vdiskmanager', '-d', f)
222
-
223
- @logger.debug("Running 'vmware-vdiskmanager -k #{f}'")
224
162
  Vagrant::Util::Subprocess.execute('vmware-vdiskmanager', '-k', f)
225
163
  }
226
164
 
@@ -275,60 +213,50 @@ module VagrantPlugins
275
213
  f.write('{"provider":"' + provider_name + '"}')
276
214
  end
277
215
 
278
- target_include_path = File.join(@tmp_path, 'include')
279
- source_include_path = File.join(@vm.box.directory, 'include')
216
+ # Copy additional files
217
+ additional_files = Dir.glob(File.join(@vm.box.directory, '**', '*'))
218
+ additional_files.select! { |f| !File.directory?(f) }
219
+ additional_files.select! { |f| f !~ /(tar|gz|core|lck|log|vmdk|ovf|ova)$/ }
220
+ additional_files.select! { |f| f !~ /(nvram|vmem|vmsd|vmsn|vmss|vmtm|vmx|vmxf)$/ }
280
221
 
281
- # Copy includes
282
- if Dir.exist?(source_include_path) && !bare
283
- @logger.debug("Copy includes from #{source_include_path} to #{target_include_path}")
284
- FileUtils.cp_r(source_include_path, @tmp_path)
285
- end
222
+ @logger.debug("Copy includes #{additional_files} to #{@tmp_path}")
223
+ FileUtils.cp_r(additional_files, @tmp_path)
286
224
 
287
- original_vagrantfile = File.join(@vm.box.directory, 'Vagrantfile')
288
- vagrantfile_exists = File.exist?(original_vagrantfile)
289
- vagrantfile_has_mac = false
290
- vagrantfile_needs_mac = @vm.provider_name.to_s == 'virtualbox'
225
+ # Make sure the Vagrantfile includes a HMAC when the provider is virtualbox
226
+ if @vm.provider_name.to_s == 'virtualbox'
291
227
 
292
- # Check the original vagrant file for a mac settings
293
- if vagrantfile_exists && vagrantfile_needs_mac
294
228
  @logger.debug('Provider needs a hmac setting in the Vagrantfile')
295
- File.readlines(original_vagrantfile).each { |line|
296
- if line.to_s =~ /base_mac\s*=\s*("|')/i
297
- vagrantfile_has_mac = true
298
- end
299
- }
300
- end
301
229
 
302
- # If it has one, just copy it
303
- if vagrantfile_has_mac || (!vagrantfile_needs_mac && vagrantfile_exists)
304
- @logger.debug('Box has already a hmac in its Vagrantfile, copy existing')
305
- FileUtils.cp(original_vagrantfile, File.join(@tmp_path, 'Vagrantfile'))
306
-
307
- # If none, create a new one that has the mac setting,
308
- # and includes the original
309
- # The new Vagrantfile will include the old one, which
310
- # is put into the includeds directory
311
- elsif vagrantfile_needs_mac
312
- @logger.debug('Vagrantfile has no hmac, set one ourselves')
313
- File.open(File.join(@tmp_path, 'Vagrantfile'), 'wb') do |file|
314
- file.write(Vagrant::Util::TemplateRenderer.render('package_Vagrantfile', {
315
- base_mac: @vm.provider.driver.read_mac_address
316
- }))
230
+ vagrantfile_name = File.join(@tmp_path, 'Vagrantfile')
231
+ vagrantfile_has_mac = false
232
+ mode = 'w+'
233
+
234
+ if File.exist?(vagrantfile_name)
235
+ mode = 'a'
236
+ File.readlines(vagrantfile_name.to_s).each { |line|
237
+ if line.to_s =~ /base_mac\s*=\s*("|')/i
238
+ @logger.debug("Found HMAC setting in file #{vagrantfile_name.to_s}")
239
+ vagrantfile_has_mac = true
240
+ end
241
+ }
317
242
  end
318
243
 
319
- # If there is a Vagrantfile, but without a mac
320
- # ensure it is included
321
- if vagrantfile_exists
322
- included_vagrantfile = File.join(target_include_path, '_Vagrantfile')
323
- @logger.debug("Box already has a Vagrantfile, copy it from #{original_vagrantfile} to #{included_vagrantfile}")
324
- FileUtils.mkdir_p(target_include_path) unless Dir.exist?(target_include_path)
325
- FileUtils.cp(original_vagrantfile, included_vagrantfile)
244
+ unless vagrantfile_has_mac
245
+
246
+ @logger.debug("Found HMAC setting in file #{vagrantfile_name.to_s}")
247
+
248
+ vagrantfile_name.open(mode) { |f|
249
+ hmac_address = @vm.provider.driver.read_mac_address
250
+ f.binmode
251
+ f.puts
252
+ f.puts %Q[# Automatically added by export]
253
+ f.puts %Q[Vagrant.configure("2") do |config|]
254
+ f.puts %Q[ config.vm.base_mac = "#{hmac_address}"]
255
+ f.puts %Q[end]
256
+ }
326
257
  end
327
258
  end
328
259
 
329
- # Copy the private key if available
330
- setup_private_key
331
-
332
260
  # Make a box file out of it
333
261
  @box_file_name = @tmp_path + '.box'
334
262
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module VagrantPlugins
7
7
  module Export
8
- VERSION = '0.3.8'
8
+ VERSION = '0.4.0'
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Grossberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Export boxes to .box files including the original Vagrantfile and some
14
14
  cleanups inside the VM