vagrant-mutate 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/lib/vagrant-mutate.rb +22 -0
- data/lib/vagrant-mutate/box.rb +130 -0
- data/lib/vagrant-mutate/converter.rb +111 -0
- data/lib/vagrant-mutate/errors.rb +54 -0
- data/lib/vagrant-mutate/mutate.rb +46 -0
- data/lib/vagrant-mutate/provider/libvirt.rb +22 -0
- data/lib/vagrant-mutate/provider/provider.rb +21 -0
- data/lib/vagrant-mutate/provider/virtualbox.rb +16 -0
- data/lib/vagrant-mutate/version.rb +3 -0
- data/locales/en.yml +31 -0
- data/test/mutate-test.box +0 -0
- data/vagrant-mutate.gemspec +25 -0
- metadata +113 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Pitts
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Vagrant-Mutate
|
2
|
+
|
3
|
+
Vagrant-mutate is a [vagrant](http://www.vagrantup.com/) plugin to convert vagrant boxes to work with different providers. Currently the only supported conversion is from virtualbox to [libvirt](https://github.com/pradels/vagrant-libvirt).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### qemu-img
|
8
|
+
|
9
|
+
First, you must install [qemu-img](http://wiki.qemu.org/Main_Page). Support for the disk image format most commonly used in vagrant boxes for virtualbox was added in [version 1.2.0](http://wiki.qemu.org/ChangeLog/1.2#VMDK); if you have an older version vagrant-mutate will warn you and most likely won't work.
|
10
|
+
|
11
|
+
#### Debian and derivatives
|
12
|
+
|
13
|
+
apt-get install qemu-utils
|
14
|
+
|
15
|
+
#### Red Hat and derivatives
|
16
|
+
|
17
|
+
yum install qemu-img
|
18
|
+
|
19
|
+
#### OS X
|
20
|
+
|
21
|
+
QEMU is available from [homebrew](http://brew.sh/)
|
22
|
+
|
23
|
+
#### Windows
|
24
|
+
|
25
|
+
Download and install it from [Stefan Weil](http://qemu.weilnetz.de/) or compile it yourself.
|
26
|
+
|
27
|
+
### vagrant-mutate
|
28
|
+
|
29
|
+
Then you can install vagrant-mutate. Once it has proven stable I will publish it to RubyGems, but for now you must build it from source.
|
30
|
+
|
31
|
+
git clone https://github.com/sciurus/vagrant-mutate.git
|
32
|
+
cd vagrant-mutate
|
33
|
+
rake build
|
34
|
+
vagrant plugin install pkg/*
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
The basic usage is
|
39
|
+
|
40
|
+
vagrant mutate box-name-or-file output-provider
|
41
|
+
|
42
|
+
For example, if you wanted to download a box created for virtualbox and add it to vagrant for libvirt
|
43
|
+
|
44
|
+
wget http://files.vagrantup.com/precise32.box
|
45
|
+
vagrant mutate precise32.box libvirt
|
46
|
+
|
47
|
+
Or, if you had already added the virtualbox version of the box to vagrant and now want to use it with libvirt
|
48
|
+
|
49
|
+
vagrant mutate precise32 libvirt
|
50
|
+
|
51
|
+
To export a box you created with vagrant mutate, just repackage it, e.g.
|
52
|
+
|
53
|
+
vagrant box repackage precise32 libvirt
|
54
|
+
|
55
|
+
|
56
|
+
## Debugging
|
57
|
+
|
58
|
+
vagrant and vagrant-mutate will output lots of information as they run if you set the VAGRANT_LOG environment variable to INFO. See [here](http://docs-v1.vagrantup.com/v1/docs/debugging.html) for information on how to do that on your operating system.
|
59
|
+
|
60
|
+
If you experience any problems, please open an issue on [github](https://github.com/sciurus/vagrant-mutate/issues).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Contributions are welcome! I'd especially like to see support for converting between more providers added. Be forewarned that I've made some assumptions in the code that may have to be reworked in order to support more than just virtualbox to libvirt.
|
65
|
+
|
66
|
+
To contribute, follow the standard flow of
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
73
|
+
|
74
|
+
Even if you can't contribute code, if you have an idea for an improvement please open an [issue](https://github.com/sciurus/vagrant-mutate/issues).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'vagrant-mutate/version'
|
2
|
+
require 'vagrant-mutate/errors'
|
3
|
+
|
4
|
+
module VagrantMutate
|
5
|
+
|
6
|
+
class Plugin < Vagrant.plugin('2')
|
7
|
+
name 'vagrant-mutate'
|
8
|
+
|
9
|
+
command 'mutate' do
|
10
|
+
setup_i18n
|
11
|
+
require 'vagrant-mutate/mutate'
|
12
|
+
Mutate
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.setup_i18n
|
16
|
+
I18n.load_path << File.expand_path('../../locales/en.yml', __FILE__)
|
17
|
+
I18n.reload!
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'archive/tar/minitar'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'json'
|
4
|
+
require 'zlib'
|
5
|
+
|
6
|
+
module VagrantMutate
|
7
|
+
class Box
|
8
|
+
|
9
|
+
include Archive::Tar
|
10
|
+
|
11
|
+
attr_reader :dir, :name, :provider
|
12
|
+
|
13
|
+
def initialize( env )
|
14
|
+
@env = env
|
15
|
+
@logger = Log4r::Logger.new('vagrant::mutate')
|
16
|
+
end
|
17
|
+
|
18
|
+
def prepare_for_output( box_name, provider_name )
|
19
|
+
@logger.info "Preparing #{box_name} for output as #{provider_name}"
|
20
|
+
@name = box_name
|
21
|
+
@provider = Provider::Provider.create( provider_name )
|
22
|
+
@dir = create_output_dir()
|
23
|
+
@dir_is_tmp = false
|
24
|
+
|
25
|
+
unless @provider.supported_output
|
26
|
+
raise Errors::ProviderNotSupported, :provider => provider_name, :direction => 'output'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_from_file(file)
|
31
|
+
@logger.info "Loading box from file #{file}"
|
32
|
+
@name = File.basename( file, File.extname(file) )
|
33
|
+
@dir = unpack(file)
|
34
|
+
@dir_is_tmp = true
|
35
|
+
@provider = determine_provider()
|
36
|
+
|
37
|
+
unless @provider.supported_input
|
38
|
+
raise Errors::ProviderNotSupported, :provider => provider_name, :direction => 'input'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_by_name(name)
|
43
|
+
@logger.info "Loading box from name #{name}"
|
44
|
+
@name = name
|
45
|
+
# cheat for now since only supported input is virtualbox
|
46
|
+
@provider = Provider::Provider.create('virtualbox')
|
47
|
+
@dir = find_input_dir()
|
48
|
+
@dir_is_tmp = false
|
49
|
+
end
|
50
|
+
|
51
|
+
def cleanup
|
52
|
+
if @dir_is_tmp
|
53
|
+
@env.ui.info "Cleaning up temporary files."
|
54
|
+
@logger.info "Deleting #{dir}"
|
55
|
+
FileUtils.remove_entry_secure(@dir)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def determine_provider
|
60
|
+
metadata_file = File.join(@dir, 'metadata.json')
|
61
|
+
if File.exists? metadata_file
|
62
|
+
begin
|
63
|
+
metadata = JSON.load( File.new( metadata_file, 'r') )
|
64
|
+
rescue => e
|
65
|
+
raise Errors::DetermineProviderFailed, :error_message => e.message
|
66
|
+
end
|
67
|
+
@logger.info "Determined input provider is #{metadata['provider']}"
|
68
|
+
return Provider::Provider.create( metadata['provider'] )
|
69
|
+
else
|
70
|
+
@logger.info "No metadata found, so assuming input provider is virtualbox"
|
71
|
+
return Provider::Provider.create('virtualbox')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def find_input_dir
|
76
|
+
in_dir = File.join( @env.boxes_path, @name, 'virtualbox' )
|
77
|
+
if File.directory?(in_dir)
|
78
|
+
@logger.info "Found input directory #{in_dir}"
|
79
|
+
return in_dir
|
80
|
+
else
|
81
|
+
raise Errors::BoxNotFound, :box => in_dir
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_output_dir
|
86
|
+
# e.g. $HOME/.vagrant.d/boxes/fedora-19/libvirt
|
87
|
+
out_dir = File.join( @env.boxes_path, @name, @provider.name )
|
88
|
+
begin
|
89
|
+
FileUtils.mkdir_p(out_dir)
|
90
|
+
rescue => e
|
91
|
+
raise Errors::CreateBoxDirFailed, :error_message => e.message
|
92
|
+
end
|
93
|
+
@logger.info "Created output directory #{out_dir}"
|
94
|
+
return out_dir
|
95
|
+
end
|
96
|
+
|
97
|
+
def unpack(file)
|
98
|
+
@env.ui.info "Extracting box file to a temporary directory."
|
99
|
+
unless File.exists? file
|
100
|
+
raise Errors::BoxNotFound, :box => file
|
101
|
+
end
|
102
|
+
# box may or may not be gzipped
|
103
|
+
begin
|
104
|
+
tar = Zlib::GzipReader.new(File.open(file, 'rb'))
|
105
|
+
rescue
|
106
|
+
tar = file
|
107
|
+
end
|
108
|
+
begin
|
109
|
+
tmp_dir = Dir.mktmpdir
|
110
|
+
Minitar.unpack(tar, tmp_dir)
|
111
|
+
rescue => e
|
112
|
+
raise Errors::ExtractBoxFailed, :error_message => e.message
|
113
|
+
end
|
114
|
+
@logger.info "Unpacked box to #{tmp_dir}"
|
115
|
+
return tmp_dir
|
116
|
+
end
|
117
|
+
|
118
|
+
def determine_virtual_size
|
119
|
+
input_file = File.join( @dir, @provider.image_name )
|
120
|
+
info = `qemu-img info #{input_file}`
|
121
|
+
@logger.debug "qemu-img info output\n#{info}"
|
122
|
+
if info =~ /(\d+) bytes/
|
123
|
+
return $1
|
124
|
+
else
|
125
|
+
raise Errors::DetermineImageSizeFailed
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module VagrantMutate
|
4
|
+
class Converter
|
5
|
+
|
6
|
+
def initialize(env)
|
7
|
+
@env = env
|
8
|
+
@logger = Log4r::Logger.new('vagrant::mutate')
|
9
|
+
verify_qemu_installed
|
10
|
+
verify_qemu_version
|
11
|
+
end
|
12
|
+
|
13
|
+
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
14
|
+
def verify_qemu_installed
|
15
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
16
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
17
|
+
exts.each do |ext|
|
18
|
+
exe = File.join(path, "qemu-img#{ext}")
|
19
|
+
if File.executable? exe
|
20
|
+
@logger.info "Found qemu"
|
21
|
+
return
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# if we make it here qemu-img command was not found
|
26
|
+
raise Errors::QemuNotFound
|
27
|
+
end
|
28
|
+
|
29
|
+
def verify_qemu_version
|
30
|
+
usage = `qemu-img`
|
31
|
+
if usage =~ /(\d+\.\d+\.\d+)/
|
32
|
+
recommended_version = Gem::Version.new('1.2.0')
|
33
|
+
installed_version = Gem::Version.new($1)
|
34
|
+
if installed_version < recommended_version
|
35
|
+
@env.ui.warn "You have qemu #{installed_version} installed. "\
|
36
|
+
"This version is too old to read some virtualbox boxes. "\
|
37
|
+
"If conversion fails, try upgrading to qemu 1.2.0 or newer."
|
38
|
+
end
|
39
|
+
else
|
40
|
+
raise Errors::ParseQemuVersionFailed
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def write_metadata(input_box, output_box)
|
45
|
+
metadata = output_box.provider.generate_metadata(input_box, output_box)
|
46
|
+
begin
|
47
|
+
File.open( File.join( output_box.dir, 'metadata.json'), 'w') do |f|
|
48
|
+
f.write( JSON.generate(metadata) )
|
49
|
+
end
|
50
|
+
rescue => e
|
51
|
+
raise Errors::WriteMetadataFailed, :error_message => e.message
|
52
|
+
end
|
53
|
+
@logger.info "Wrote metadata"
|
54
|
+
end
|
55
|
+
|
56
|
+
def copy_vagrantfile(input_box, output_box)
|
57
|
+
input = File.join( input_box.dir, 'Vagrantfile' )
|
58
|
+
if File.exists? input
|
59
|
+
output = File.join( output_box.dir, 'Vagrantfile' )
|
60
|
+
@logger.info "Copying #{input} to #{output}"
|
61
|
+
begin
|
62
|
+
FileUtils.copy_file(input, output)
|
63
|
+
rescue => e
|
64
|
+
raise Errors::WriteVagrantfileFailed, :error_message => e.message
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def write_disk(input_box, output_box)
|
70
|
+
if input_box.provider.image_format == output_box.provider.image_format
|
71
|
+
copy_disk(input_box, output_box)
|
72
|
+
else
|
73
|
+
convert_disk(input_box, output_box)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def copy_disk(input_box, output_box)
|
78
|
+
input = File.join( input_box.dir, input_box.provider.image_name )
|
79
|
+
output = File.join( output_box.dir, output_box.provider.image_name )
|
80
|
+
@logger.info "Copying #{input} to #{output}"
|
81
|
+
begin
|
82
|
+
FileUtils.copy_file(input, output)
|
83
|
+
rescue => e
|
84
|
+
raise Errors::WriteDiskFailed, :error_message => e.message
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def convert_disk(input_box, output_box)
|
89
|
+
input_file = File.join( input_box.dir, input_box.provider.image_name )
|
90
|
+
output_file = File.join( output_box.dir, output_box.provider.image_name )
|
91
|
+
input_format = input_box.provider.image_format
|
92
|
+
output_format = output_box.provider.image_format
|
93
|
+
|
94
|
+
command = "qemu-img convert -p -f #{input_format} -O #{output_format} #{input_file} #{output_file}"
|
95
|
+
@logger.info "Running #{command}"
|
96
|
+
unless system(command)
|
97
|
+
raise Errors::WriteDiskFailed, :error_message => "qemu-img exited with status #{$?.exitstatus}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def convert(input_box, output_box)
|
102
|
+
@env.ui.info "Converting #{input_box.name} from #{input_box.provider.name} "\
|
103
|
+
"to #{output_box.provider.name}."
|
104
|
+
write_metadata(input_box, output_box)
|
105
|
+
# will have to rethink this if any providers need to alter the vagrantfile
|
106
|
+
copy_vagrantfile(input_box, output_box)
|
107
|
+
write_disk(input_box, output_box)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantMutate
|
4
|
+
module Errors
|
5
|
+
class VagrantMutateError < Vagrant::Errors::VagrantError
|
6
|
+
error_namespace('vagrant_mutate.errors')
|
7
|
+
end
|
8
|
+
|
9
|
+
class ProviderNotSupported < VagrantMutateError
|
10
|
+
error_key(:provider_not_supported)
|
11
|
+
end
|
12
|
+
|
13
|
+
class QemuNotFound < VagrantMutateError
|
14
|
+
error_key(:qemu_not_found)
|
15
|
+
end
|
16
|
+
|
17
|
+
class BoxNotFound < VagrantMutateError
|
18
|
+
error_key(:box_not_found)
|
19
|
+
end
|
20
|
+
|
21
|
+
class ExtractBoxFailed < VagrantMutateError
|
22
|
+
error_key(:extract_box_failed)
|
23
|
+
end
|
24
|
+
|
25
|
+
class DetermineProviderFailed < VagrantMutateError
|
26
|
+
error_key(:determine_provider_failed)
|
27
|
+
end
|
28
|
+
|
29
|
+
class CreateBoxDirFailed < VagrantMutateError
|
30
|
+
error_key(:create_box_dir_failed)
|
31
|
+
end
|
32
|
+
|
33
|
+
class WriteMetadataFailed < VagrantMutateError
|
34
|
+
error_key(:write_metadata_failed)
|
35
|
+
end
|
36
|
+
|
37
|
+
class WriteVagrantfileFailed < VagrantMutateError
|
38
|
+
error_key(:write_vagrantfile_failed)
|
39
|
+
end
|
40
|
+
|
41
|
+
class WriteDiskFailed < VagrantMutateError
|
42
|
+
error_key(:write_disk_failed)
|
43
|
+
end
|
44
|
+
|
45
|
+
class ParseQemuVersionFailed < VagrantMutateError
|
46
|
+
error_key(:parse_qemu_version_failed)
|
47
|
+
end
|
48
|
+
|
49
|
+
class Errors::DetermineImageSizeFailed < VagrantMutateError
|
50
|
+
error_key(:determine_image_size_failed)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'vagrant-mutate/box'
|
2
|
+
require 'vagrant-mutate/converter'
|
3
|
+
require 'vagrant-mutate/provider/provider'
|
4
|
+
|
5
|
+
module VagrantMutate
|
6
|
+
|
7
|
+
class Mutate < Vagrant.plugin(2, :command)
|
8
|
+
|
9
|
+
def execute
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: vagrant mutate <box-name-or-file> <provider>'
|
12
|
+
end
|
13
|
+
argv = parse_options(opts)
|
14
|
+
return if !argv
|
15
|
+
|
16
|
+
unless argv.length == 2
|
17
|
+
@env.ui.info(opts.help)
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
box_arg = argv[0]
|
22
|
+
output_provider_arg = argv[1]
|
23
|
+
|
24
|
+
c = Converter.new(@env)
|
25
|
+
input_box = Box.new(@env)
|
26
|
+
output_box = Box.new(@env)
|
27
|
+
|
28
|
+
if box_arg =~ /\.box$/
|
29
|
+
input_box.load_from_file(box_arg)
|
30
|
+
else
|
31
|
+
input_box.load_by_name(box_arg)
|
32
|
+
end
|
33
|
+
|
34
|
+
output_box.prepare_for_output( input_box.name, output_provider_arg)
|
35
|
+
|
36
|
+
c.convert(input_box, output_box)
|
37
|
+
|
38
|
+
input_box.cleanup
|
39
|
+
|
40
|
+
@env.ui.info "The box #{output_box.name} (#{output_box.provider.name}) is now ready to use."
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantMutate
|
2
|
+
module Provider
|
3
|
+
class Libvirt < Provider
|
4
|
+
def initialize
|
5
|
+
@name = 'libvirt'
|
6
|
+
@supported_input = true,
|
7
|
+
@supported_output = true,
|
8
|
+
@image_format = 'qcow2',
|
9
|
+
@image_name = 'box.img'
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_metadata(input_box, output_box)
|
13
|
+
metadata = {
|
14
|
+
'provider' => output_box.provider.name,
|
15
|
+
'format' => 'qcow2',
|
16
|
+
'virtual_size' => ( input_box.determine_virtual_size.to_f / (1024 * 1024 * 1024) ).ceil
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantMutate
|
2
|
+
module Provider
|
3
|
+
class Provider
|
4
|
+
attr_reader :name, :supported_input, :supported_output, :image_format, :image_name
|
5
|
+
|
6
|
+
def self.create(name)
|
7
|
+
case name
|
8
|
+
when 'libvirt'
|
9
|
+
require_relative 'libvirt'
|
10
|
+
Libvirt.new
|
11
|
+
when 'virtualbox'
|
12
|
+
require_relative 'virtualbox'
|
13
|
+
Virtualbox.new
|
14
|
+
else
|
15
|
+
raise Errors::ProviderNotSupported, :provider => name, :direction => 'input or output'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantMutate
|
2
|
+
module Provider
|
3
|
+
|
4
|
+
class Virtualbox < Provider
|
5
|
+
def initialize
|
6
|
+
@name = 'virtualbox'
|
7
|
+
@supported_input = true,
|
8
|
+
@supported_output = false,
|
9
|
+
@image_format = 'vmdk',
|
10
|
+
@image_name = 'box-disk1.vmdk'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/locales/en.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_mutate:
|
3
|
+
errors:
|
4
|
+
provider_not_supported: |-
|
5
|
+
Vagrant-mutate does not support %{provider} for %{direction}
|
6
|
+
qemu_not_found: |-
|
7
|
+
Qemu-img was not found in your path
|
8
|
+
box_not_found: |-
|
9
|
+
The box at %{box} was not found
|
10
|
+
extract_box_failed: |-
|
11
|
+
Extracting box failed with error:
|
12
|
+
%{error_message}
|
13
|
+
determine_provider_failed: |-
|
14
|
+
Determining provider for box failed with error:
|
15
|
+
%{error_message}
|
16
|
+
create_box_dir_failed: |-
|
17
|
+
Creating directory for box failed with error:
|
18
|
+
%{error_message}
|
19
|
+
write_metadata_failed: |-
|
20
|
+
Writing metadata for box failed with error:
|
21
|
+
%{error_message}
|
22
|
+
write_vagrantfile_failed: |-
|
23
|
+
Writing vagrantfile for box failed with error:
|
24
|
+
%{error_message}
|
25
|
+
write_disk_failed: |-
|
26
|
+
Writing disk image for box failed with error:
|
27
|
+
%{error_message}
|
28
|
+
parse_qemu_version_failed: |-
|
29
|
+
Determining the version of qemu-img installed failed
|
30
|
+
determine_image_size_failed: |-
|
31
|
+
Determining the virtual size of the disk image failed
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-mutate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-mutate"
|
8
|
+
spec.version = VagrantMutate::VERSION
|
9
|
+
spec.authors = ["Brian Pitts"]
|
10
|
+
spec.email = ["brian@polibyte.com"]
|
11
|
+
spec.description = %q{Convert vagrant boxes to work with different providers}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "archive-tar-minitar", "~> 0.5.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-mutate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Pitts
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: archive-tar-minitar
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Convert vagrant boxes to work with different providers
|
63
|
+
email:
|
64
|
+
- brian@polibyte.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- CHANGELOG.md
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/vagrant-mutate.rb
|
76
|
+
- lib/vagrant-mutate/box.rb
|
77
|
+
- lib/vagrant-mutate/converter.rb
|
78
|
+
- lib/vagrant-mutate/errors.rb
|
79
|
+
- lib/vagrant-mutate/mutate.rb
|
80
|
+
- lib/vagrant-mutate/provider/libvirt.rb
|
81
|
+
- lib/vagrant-mutate/provider/provider.rb
|
82
|
+
- lib/vagrant-mutate/provider/virtualbox.rb
|
83
|
+
- lib/vagrant-mutate/version.rb
|
84
|
+
- locales/en.yml
|
85
|
+
- test/mutate-test.box
|
86
|
+
- vagrant-mutate.gemspec
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.23
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Convert vagrant boxes to work with different providers
|
112
|
+
test_files:
|
113
|
+
- test/mutate-test.box
|