lib/vagrant-libvirt/action/package_domain.rb in vagrant-libvirt-0.0.37 vs lib/vagrant-libvirt/action/package_domain.rb in vagrant-libvirt-0.0.38
- old
+ new
@@ -37,25 +37,43 @@
FileUtils.cp(root_disk.path, @tmp_img)
`qemu-img rebase -p -b "" #{@tmp_img}`
# remove hw association with interface
# working for centos with lvs default disks
`virt-sysprep --no-logfile --operations defaults,-ssh-userdir -a #{@tmp_img}`
+ # add any user provided file
+ extra = ''
+ @tmp_include = @tmp_dir + '/_include'
+ if env['package.include']
+ extra = './_include'
+ Dir.mkdir(@tmp_include)
+ env['package.include'].each do |f|
+ env[:ui].info("Including user file: #{f}")
+ FileUtils.cp(f, @tmp_include)
+ end
+ end
+ if env['package.vagrantfile']
+ extra = './_include'
+ Dir.mkdir(@tmp_include) unless File.directory?(@tmp_include)
+ env[:ui].info('Including user Vagrantfile')
+ FileUtils.cp(env['package.vagrantfile'], @tmp_include + '/Vagrantfile')
+ end
Dir.chdir(@tmp_dir)
- img_size = `qemu-img info #{@tmp_img} | grep 'virtual size' | awk '{print $3;}' | tr -d 'G'`.chomp
+ info = JSON.parse(`qemu-img info --output=json #{@tmp_img}`)
+ img_size = (Float(info['virtual-size'])/(1024**3)).ceil
File.write(@tmp_dir + '/metadata.json', metadata_content(img_size))
File.write(@tmp_dir + '/Vagrantfile', vagrantfile_content)
- assebmle_box(boxname)
+ assemble_box(boxname, extra)
FileUtils.mv(@tmp_dir + '/' + boxname, '../' + boxname)
FileUtils.rm_rf(@tmp_dir)
env[:ui].info('Box created')
env[:ui].info('You can now add the box:')
env[:ui].info("vagrant box add #{boxname} --name any_comfortable_name")
@app.call(env)
end
- def assebmle_box(boxname)
- `tar cvzf "#{boxname}" --totals ./metadata.json ./Vagrantfile ./box.img`
+ def assemble_box(boxname, extra)
+ `tar cvzf "#{boxname}" --totals ./metadata.json ./Vagrantfile ./box.img #{extra}`
end
def vagrantfile_content
<<-EOF
Vagrant.configure("2") do |config|
@@ -64,9 +82,12 @@
libvirt.host = ""
libvirt.connect_via_ssh = false
libvirt.storage_pool_name = "default"
end
end
+
+ user_vagrantfile = File.expand_path('../_include/Vagrantfile', __FILE__)
+ load user_vagrantfile if File.exists?(user_vagrantfile)
EOF
end
def metadata_content(filesize)
<<-EOF