vagrant-mutate 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +16 -11
- data/lib/vagrant-mutate/box.rb +17 -15
- data/lib/vagrant-mutate/converter.rb +35 -27
- data/lib/vagrant-mutate/mutate.rb +3 -3
- data/lib/vagrant-mutate/provider/kvm.rb +57 -0
- data/lib/vagrant-mutate/provider/libvirt.rb +10 -5
- data/lib/vagrant-mutate/provider/provider.rb +6 -3
- data/lib/vagrant-mutate/provider/virtualbox.rb +87 -1
- data/lib/vagrant-mutate/version.rb +1 -1
- data/lib/vagrant-mutate.rb +5 -2
- data/templates/kvm/box.xml.erb +66 -0
- data/test/expected_output/virtualbox/kvm/Vagrantfile +11 -0
- data/test/expected_output/virtualbox/kvm/box-disk1.img +0 -0
- data/test/expected_output/virtualbox/kvm/box.xml +62 -0
- data/test/expected_output/virtualbox/kvm/metadata.json +1 -0
- data/test/expected_output/virtualbox/libvirt/Vagrantfile +11 -0
- data/test/expected_output/virtualbox/libvirt/box.img +0 -0
- data/test/expected_output/virtualbox/libvirt/metadata.json +1 -0
- data/test/input/kvm/mutate-test.box +0 -0
- data/test/input/libvirt/mutate-test.box +0 -0
- data/test/input/virtualbox/mutate-test.box +0 -0
- data/test/test.rb +71 -0
- metadata +26 -4
- data/test/mutate-test.box +0 -0
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Vagrant-Mutate
|
2
2
|
|
3
|
-
Vagrant-mutate is a [vagrant](http://www.vagrantup.com/) plugin to convert vagrant boxes to work with different providers.
|
3
|
+
Vagrant-mutate is a [vagrant](http://www.vagrantup.com/) plugin to convert vagrant boxes to work with different providers.
|
4
|
+
|
5
|
+
## Supported Conversions
|
6
|
+
|
7
|
+
* Virtualbox to [kvm](https://github.com/adrahon/vagrant-kvm) (tested against 0.1.4)
|
8
|
+
* Virtualbox to [libvirt](https://github.com/pradels/vagrant-libvirt) (tested against 0.0.11)
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -26,12 +31,11 @@ Download and install it from [Stefan Weil](http://qemu.weilnetz.de/) or compile
|
|
26
31
|
|
27
32
|
### vagrant-mutate
|
28
33
|
|
29
|
-
|
34
|
+
Now you're ready to install vagrant-mutate. To install the latest released version simply run
|
35
|
+
|
36
|
+
vagrant plugin install vagrant-mutate
|
30
37
|
|
31
|
-
|
32
|
-
cd vagrant-mutate
|
33
|
-
rake build
|
34
|
-
vagrant plugin install pkg/*
|
38
|
+
To install from source, clone the repository and run `rake build`. That will produce a gem file in the _pkg_ directory which you can then install with `vagrant plugin install`.
|
35
39
|
|
36
40
|
## Usage
|
37
41
|
|
@@ -61,14 +65,15 @@ If you experience any problems, please open an issue on [github](https://github.
|
|
61
65
|
|
62
66
|
## Contributing
|
63
67
|
|
64
|
-
Contributions are welcome! I'd especially like to see support for converting between more providers added.
|
68
|
+
Contributions are welcome! I'd especially like to see support for converting between more providers added.
|
65
69
|
|
66
70
|
To contribute, follow the standard flow of
|
67
71
|
|
68
72
|
1. Fork it
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
1. Make sure the acceptance tests pass (`ruby test/test.rb`)
|
76
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
1. Create new Pull Request
|
73
78
|
|
74
79
|
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/lib/vagrant-mutate/box.rb
CHANGED
@@ -18,7 +18,7 @@ module VagrantMutate
|
|
18
18
|
def prepare_for_output( box_name, provider_name )
|
19
19
|
@logger.info "Preparing #{box_name} for output as #{provider_name}"
|
20
20
|
@name = box_name
|
21
|
-
@provider = Provider::Provider.create( provider_name )
|
21
|
+
@provider = Provider::Provider.create( provider_name, self )
|
22
22
|
@dir = create_output_dir()
|
23
23
|
@dir_is_tmp = false
|
24
24
|
|
@@ -43,7 +43,7 @@ module VagrantMutate
|
|
43
43
|
@logger.info "Loading box from name #{name}"
|
44
44
|
@name = name
|
45
45
|
# cheat for now since only supported input is virtualbox
|
46
|
-
@provider = Provider::Provider.create('virtualbox')
|
46
|
+
@provider = Provider::Provider.create('virtualbox', self)
|
47
47
|
@dir = find_input_dir()
|
48
48
|
@dir_is_tmp = false
|
49
49
|
end
|
@@ -56,6 +56,19 @@ module VagrantMutate
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
def virtual_size
|
60
|
+
input_file = File.join( @dir, @provider.image_name )
|
61
|
+
info = `qemu-img info #{input_file}`
|
62
|
+
@logger.debug "qemu-img info output\n#{info}"
|
63
|
+
if info =~ /(\d+) bytes/
|
64
|
+
return $1
|
65
|
+
else
|
66
|
+
raise Errors::DetermineImageSizeFailed
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
59
72
|
def determine_provider
|
60
73
|
metadata_file = File.join(@dir, 'metadata.json')
|
61
74
|
if File.exists? metadata_file
|
@@ -65,10 +78,10 @@ module VagrantMutate
|
|
65
78
|
raise Errors::DetermineProviderFailed, :error_message => e.message
|
66
79
|
end
|
67
80
|
@logger.info "Determined input provider is #{metadata['provider']}"
|
68
|
-
return Provider::Provider.create( metadata['provider'] )
|
81
|
+
return Provider::Provider.create( metadata['provider'], self )
|
69
82
|
else
|
70
83
|
@logger.info "No metadata found, so assuming input provider is virtualbox"
|
71
|
-
return Provider::Provider.create('virtualbox')
|
84
|
+
return Provider::Provider.create('virtualbox', self)
|
72
85
|
end
|
73
86
|
end
|
74
87
|
|
@@ -115,16 +128,5 @@ module VagrantMutate
|
|
115
128
|
return tmp_dir
|
116
129
|
end
|
117
130
|
|
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
131
|
end
|
130
132
|
end
|
@@ -10,6 +10,22 @@ module VagrantMutate
|
|
10
10
|
verify_qemu_version
|
11
11
|
end
|
12
12
|
|
13
|
+
def convert(input_box, output_box)
|
14
|
+
@input_box = input_box
|
15
|
+
@output_box = output_box
|
16
|
+
|
17
|
+
@env.ui.info "Converting #{input_box.name} from #{input_box.provider.name} "\
|
18
|
+
"to #{output_box.provider.name}."
|
19
|
+
|
20
|
+
write_metadata
|
21
|
+
# will have to rethink this if any providers need to alter the vagrantfile
|
22
|
+
copy_vagrantfile
|
23
|
+
output_box.provider.write_specific_files(input_box)
|
24
|
+
write_disk
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
13
29
|
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
14
30
|
def verify_qemu_installed
|
15
31
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
@@ -41,10 +57,11 @@ module VagrantMutate
|
|
41
57
|
end
|
42
58
|
end
|
43
59
|
|
44
|
-
|
45
|
-
|
60
|
+
|
61
|
+
def write_metadata
|
62
|
+
metadata = @output_box.provider.generate_metadata(@input_box)
|
46
63
|
begin
|
47
|
-
File.open( File.join( output_box.dir, 'metadata.json'), 'w') do |f|
|
64
|
+
File.open( File.join( @output_box.dir, 'metadata.json'), 'w') do |f|
|
48
65
|
f.write( JSON.generate(metadata) )
|
49
66
|
end
|
50
67
|
rescue => e
|
@@ -53,10 +70,10 @@ module VagrantMutate
|
|
53
70
|
@logger.info "Wrote metadata"
|
54
71
|
end
|
55
72
|
|
56
|
-
def copy_vagrantfile
|
57
|
-
input = File.join( input_box.dir, 'Vagrantfile' )
|
73
|
+
def copy_vagrantfile
|
74
|
+
input = File.join( @input_box.dir, 'Vagrantfile' )
|
58
75
|
if File.exists? input
|
59
|
-
output = File.join( output_box.dir, 'Vagrantfile' )
|
76
|
+
output = File.join( @output_box.dir, 'Vagrantfile' )
|
60
77
|
@logger.info "Copying #{input} to #{output}"
|
61
78
|
begin
|
62
79
|
FileUtils.copy_file(input, output)
|
@@ -66,17 +83,17 @@ module VagrantMutate
|
|
66
83
|
end
|
67
84
|
end
|
68
85
|
|
69
|
-
def write_disk
|
70
|
-
if input_box.provider.image_format == output_box.provider.image_format
|
71
|
-
copy_disk
|
86
|
+
def write_disk
|
87
|
+
if @input_box.provider.image_format == @output_box.provider.image_format
|
88
|
+
copy_disk
|
72
89
|
else
|
73
|
-
convert_disk
|
90
|
+
convert_disk
|
74
91
|
end
|
75
92
|
end
|
76
93
|
|
77
|
-
def copy_disk
|
78
|
-
input = File.join( input_box.dir, input_box.provider.image_name )
|
79
|
-
output = File.join( output_box.dir, output_box.provider.image_name )
|
94
|
+
def copy_disk
|
95
|
+
input = File.join( @input_box.dir, @input_box.provider.image_name )
|
96
|
+
output = File.join( @output_box.dir, @output_box.provider.image_name )
|
80
97
|
@logger.info "Copying #{input} to #{output}"
|
81
98
|
begin
|
82
99
|
FileUtils.copy_file(input, output)
|
@@ -85,11 +102,11 @@ module VagrantMutate
|
|
85
102
|
end
|
86
103
|
end
|
87
104
|
|
88
|
-
def convert_disk
|
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
|
105
|
+
def convert_disk
|
106
|
+
input_file = File.join( @input_box.dir, @input_box.provider.image_name )
|
107
|
+
output_file = File.join( @output_box.dir, @output_box.provider.image_name )
|
108
|
+
input_format = @input_box.provider.image_format
|
109
|
+
output_format = @output_box.provider.image_format
|
93
110
|
|
94
111
|
command = "qemu-img convert -p -f #{input_format} -O #{output_format} #{input_file} #{output_file}"
|
95
112
|
@logger.info "Running #{command}"
|
@@ -98,14 +115,5 @@ module VagrantMutate
|
|
98
115
|
end
|
99
116
|
end
|
100
117
|
|
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
118
|
end
|
111
119
|
end
|
@@ -21,8 +21,8 @@ module VagrantMutate
|
|
21
21
|
box_arg = argv[0]
|
22
22
|
output_provider_arg = argv[1]
|
23
23
|
|
24
|
-
|
25
|
-
input_box
|
24
|
+
converter = Converter.new(@env)
|
25
|
+
input_box = Box.new(@env)
|
26
26
|
output_box = Box.new(@env)
|
27
27
|
|
28
28
|
if box_arg =~ /\.box$/
|
@@ -33,7 +33,7 @@ module VagrantMutate
|
|
33
33
|
|
34
34
|
output_box.prepare_for_output( input_box.name, output_provider_arg)
|
35
35
|
|
36
|
-
|
36
|
+
converter.convert(input_box, output_box)
|
37
37
|
|
38
38
|
input_box.cleanup
|
39
39
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module VagrantMutate
|
4
|
+
module Provider
|
5
|
+
class Kvm < Provider
|
6
|
+
def initialize(box)
|
7
|
+
@box = box
|
8
|
+
@name = 'kvm'
|
9
|
+
@supported_input = false,
|
10
|
+
@supported_output = true,
|
11
|
+
@image_format = 'raw',
|
12
|
+
@image_name = 'box-disk1.img'
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_metadata(input_box)
|
16
|
+
metadata = {
|
17
|
+
'provider' => @box.provider.name,
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def write_specific_files(input_box)
|
22
|
+
template_path = VagrantMutate.source_root.join('templates', 'kvm', 'box.xml.erb')
|
23
|
+
template = File.read(template_path)
|
24
|
+
|
25
|
+
uuid = nil
|
26
|
+
gui = true
|
27
|
+
disk_bus = 'virtio'
|
28
|
+
name = input_box.name
|
29
|
+
image_type = @image_format
|
30
|
+
disk = @image_name
|
31
|
+
qemu_bin = find_kvm
|
32
|
+
memory = input_box.provider.memory / 1024 # convert bytes to kib
|
33
|
+
cpus = input_box.provider.cpus
|
34
|
+
mac = input_box.provider.mac_address
|
35
|
+
arch = input_box.provider.architecture
|
36
|
+
|
37
|
+
File.open( File.join( @box.dir, 'box.xml'), 'w') do |f|
|
38
|
+
f.write( ERB.new(template).result(binding) )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def find_kvm
|
45
|
+
qemu_bin_list = [ '/usr/bin/qemu-kvm', '/usr/bin/kvm',
|
46
|
+
'/usr/bin/qemu-system-x86_64',
|
47
|
+
'/usr/bin/qemu-system-i386' ]
|
48
|
+
qemu_bin = qemu_bin_list.detect { |binary| File.exists? binary }
|
49
|
+
unless qemu_bin
|
50
|
+
raise Errors::QemuNotFound
|
51
|
+
end
|
52
|
+
return qemu_bin
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,22 +1,27 @@
|
|
1
1
|
module VagrantMutate
|
2
2
|
module Provider
|
3
3
|
class Libvirt < Provider
|
4
|
-
def initialize
|
4
|
+
def initialize(box)
|
5
|
+
@box = box
|
5
6
|
@name = 'libvirt'
|
6
|
-
@supported_input =
|
7
|
+
@supported_input = false,
|
7
8
|
@supported_output = true,
|
8
9
|
@image_format = 'qcow2',
|
9
10
|
@image_name = 'box.img'
|
10
11
|
end
|
11
12
|
|
12
|
-
def generate_metadata(input_box
|
13
|
+
def generate_metadata(input_box)
|
13
14
|
metadata = {
|
14
|
-
'provider' =>
|
15
|
+
'provider' => @box.provider.name,
|
15
16
|
'format' => 'qcow2',
|
16
|
-
'virtual_size' => ( input_box.
|
17
|
+
'virtual_size' => ( input_box.virtual_size.to_f / (1024 * 1024 * 1024) ).ceil
|
17
18
|
}
|
18
19
|
end
|
19
20
|
|
21
|
+
def write_specific_files(input_box)
|
22
|
+
# nothing to do here
|
23
|
+
end
|
24
|
+
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -3,14 +3,17 @@ module VagrantMutate
|
|
3
3
|
class Provider
|
4
4
|
attr_reader :name, :supported_input, :supported_output, :image_format, :image_name
|
5
5
|
|
6
|
-
def self.create(name)
|
6
|
+
def self.create(name, box)
|
7
7
|
case name
|
8
|
+
when 'kvm'
|
9
|
+
require_relative 'kvm'
|
10
|
+
Kvm.new(box)
|
8
11
|
when 'libvirt'
|
9
12
|
require_relative 'libvirt'
|
10
|
-
Libvirt.new
|
13
|
+
Libvirt.new(box)
|
11
14
|
when 'virtualbox'
|
12
15
|
require_relative 'virtualbox'
|
13
|
-
Virtualbox.new
|
16
|
+
Virtualbox.new(box)
|
14
17
|
else
|
15
18
|
raise Errors::ProviderNotSupported, :provider => name, :direction => 'input or output'
|
16
19
|
end
|
@@ -1,14 +1,100 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
|
1
3
|
module VagrantMutate
|
2
4
|
module Provider
|
3
5
|
|
4
6
|
class Virtualbox < Provider
|
5
|
-
def initialize
|
7
|
+
def initialize(box)
|
8
|
+
@box = box
|
6
9
|
@name = 'virtualbox'
|
7
10
|
@supported_input = true,
|
8
11
|
@supported_output = false,
|
9
12
|
@image_format = 'vmdk',
|
10
13
|
@image_name = 'box-disk1.vmdk'
|
14
|
+
|
15
|
+
definition = File.read( File.join( box.dir, 'box.ovf') )
|
16
|
+
@ovf = REXML::Document.new(definition)
|
17
|
+
end
|
18
|
+
|
19
|
+
# the architecture is not defined in the ovf file,
|
20
|
+
# we could try to guess from OSType
|
21
|
+
# (https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Main/include/ovfreader.h)
|
22
|
+
# but if that is not set correctly we risk a 64-bit box not booting
|
23
|
+
# because we try to run in 32-bit vm.
|
24
|
+
# in contrast, running 32-bit box in a 64-bit vm should work.
|
25
|
+
def architecture
|
26
|
+
return 'x86_64'
|
27
|
+
end
|
28
|
+
|
29
|
+
# use mac from the first enabled nic
|
30
|
+
def mac_address
|
31
|
+
@ovf.elements.each("//vbox:Machine/Hardware//Adapter") do |ele|
|
32
|
+
if ele.attributes['enabled'] == 'true'
|
33
|
+
mac = ele.attributes['MACAddress']
|
34
|
+
# convert to more standarad format with colons
|
35
|
+
return mac[0..1] + ":" + mac[2..3] + ":" +
|
36
|
+
mac[4..5] + ":" + mac[6..7] + ":" +
|
37
|
+
mac[8..9] + ":" + mac[10..11]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def cpus
|
43
|
+
@ovf.elements.each("//VirtualHardwareSection/Item") do |device|
|
44
|
+
if device.elements["rasd:ResourceType"].text == '3'
|
45
|
+
return device.elements["rasd:VirtualQuantity"].text
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def memory
|
51
|
+
@ovf.elements.each("//VirtualHardwareSection/Item") do |device|
|
52
|
+
if device.elements["rasd:ResourceType"].text == '4'
|
53
|
+
return size_in_bytes(device.elements["rasd:VirtualQuantity"].text,
|
54
|
+
device.elements["rasd:AllocationUnits"].text)
|
55
|
+
end
|
56
|
+
end
|
11
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Takes a quantity and a unit
|
62
|
+
# returns quantity in bytes
|
63
|
+
# mib = true to use mebibytes, etc
|
64
|
+
# defaults to false because ovf MB != megabytes
|
65
|
+
def size_in_bytes(qty, unit, mib=false)
|
66
|
+
qty = qty.to_i
|
67
|
+
unit = unit.downcase
|
68
|
+
if !mib
|
69
|
+
case unit
|
70
|
+
when "kb", "kilobytes"
|
71
|
+
unit = "kib"
|
72
|
+
when "mb", "megabytes"
|
73
|
+
unit = "mib"
|
74
|
+
when "gb", "gigabytes"
|
75
|
+
unit = "gib"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
case unit
|
79
|
+
when "b", "bytes"
|
80
|
+
qty
|
81
|
+
when "kb", "kilobytes"
|
82
|
+
(qty * 1000)
|
83
|
+
when "kib", "kibibytes"
|
84
|
+
(qty * 1024)
|
85
|
+
when "mb", "megabytes"
|
86
|
+
(qty * 1000000)
|
87
|
+
when "m", "mib", "mebibytes"
|
88
|
+
(qty * 1048576)
|
89
|
+
when "gb", "gigabytes"
|
90
|
+
(qty * 1000000000)
|
91
|
+
when "g", "gib", "gibibytes"
|
92
|
+
(qty * 1073741824)
|
93
|
+
else
|
94
|
+
raise ArgumentError, "Unknown unit #{unit}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
12
98
|
end
|
13
99
|
|
14
100
|
end
|
data/lib/vagrant-mutate.rb
CHANGED
@@ -3,6 +3,10 @@ require 'vagrant-mutate/errors'
|
|
3
3
|
|
4
4
|
module VagrantMutate
|
5
5
|
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
8
|
+
end
|
9
|
+
|
6
10
|
class Plugin < Vagrant.plugin('2')
|
7
11
|
name 'vagrant-mutate'
|
8
12
|
|
@@ -13,10 +17,9 @@ module VagrantMutate
|
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.setup_i18n
|
16
|
-
I18n.load_path << File.expand_path('
|
20
|
+
I18n.load_path << File.expand_path('locales/en.yml', VagrantMutate.source_root)
|
17
21
|
I18n.reload!
|
18
22
|
end
|
19
|
-
|
20
23
|
end
|
21
24
|
|
22
25
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<domain type='kvm'>
|
2
|
+
<name><%= name %></name>
|
3
|
+
<% if uuid %>
|
4
|
+
<uuid><%= uuid %></uuid>
|
5
|
+
<% end %>
|
6
|
+
<memory unit='KiB'><%= memory %></memory>
|
7
|
+
<currentMemory unit='KiB'><%= memory%></currentMemory>
|
8
|
+
<vcpu placement='static'><%= cpus %></vcpu>
|
9
|
+
<os>
|
10
|
+
<type arch='<%= arch %>' machine='pc-1.2'>hvm</type>
|
11
|
+
<boot dev='hd'/>
|
12
|
+
</os>
|
13
|
+
<features>
|
14
|
+
<acpi/>
|
15
|
+
<apic/>
|
16
|
+
<pae/>
|
17
|
+
</features>
|
18
|
+
<clock offset='utc'/>
|
19
|
+
<on_poweroff>destroy</on_poweroff>
|
20
|
+
<on_reboot>restart</on_reboot>
|
21
|
+
<on_crash>restart</on_crash>
|
22
|
+
<devices>
|
23
|
+
<emulator><%= qemu_bin %></emulator>
|
24
|
+
<disk type='file' device='disk'>
|
25
|
+
<driver name='qemu' type='<%= image_type %>'/>
|
26
|
+
<source file='<%= disk %>'/>
|
27
|
+
<target dev='vda' bus='<%= disk_bus %>'/>
|
28
|
+
<% if disk_bus == 'virtio' %>
|
29
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
30
|
+
<% else %>
|
31
|
+
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
32
|
+
<% end %>
|
33
|
+
</disk>
|
34
|
+
<controller type='usb' index='0'>
|
35
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
36
|
+
</controller>
|
37
|
+
<controller type='virtio-serial' index='0'>
|
38
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
39
|
+
</controller>
|
40
|
+
<interface type='network'>
|
41
|
+
<mac address='<%= mac %>'/>
|
42
|
+
<source network='vagrant'/>
|
43
|
+
<model type='virtio'/>
|
44
|
+
</interface>
|
45
|
+
<serial type='pty'>
|
46
|
+
<target port='0'/>
|
47
|
+
</serial>
|
48
|
+
<console type='pty'>
|
49
|
+
<target type='serial' port='0'/>
|
50
|
+
</console>
|
51
|
+
<input type='mouse' bus='ps2'/>
|
52
|
+
<sound model='ich6'>
|
53
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
54
|
+
</sound>
|
55
|
+
<% if gui %>
|
56
|
+
<%= "<graphics type='vnc' port='-1' autoport='yes'/>" %>
|
57
|
+
<% end %>
|
58
|
+
<video>
|
59
|
+
<model type='cirrus' vram='9216' heads='1'/>
|
60
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
61
|
+
</video>
|
62
|
+
<memballoon model='virtio'>
|
63
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
64
|
+
</memballoon>
|
65
|
+
</devices>
|
66
|
+
</domain>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Vagrant::Config.run do |config|
|
2
|
+
# This Vagrantfile is auto-generated by `vagrant package` to contain
|
3
|
+
# the MAC address of the box. Custom configuration should be placed in
|
4
|
+
# the actual `Vagrantfile` in this box.
|
5
|
+
config.vm.base_mac = "08002755B88D"
|
6
|
+
end
|
7
|
+
|
8
|
+
# Load include vagrant file if it exists after the auto-generated
|
9
|
+
# so it can override any of the settings
|
10
|
+
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
|
11
|
+
load include_vagrantfile if File.exist?(include_vagrantfile)
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<domain type='kvm'>
|
2
|
+
<name>mutate-test</name>
|
3
|
+
|
4
|
+
<memory unit='KiB'>262144</memory>
|
5
|
+
<currentMemory unit='KiB'>262144</currentMemory>
|
6
|
+
<vcpu placement='static'>1</vcpu>
|
7
|
+
<os>
|
8
|
+
<type arch='x86_64' machine='pc-1.2'>hvm</type>
|
9
|
+
<boot dev='hd'/>
|
10
|
+
</os>
|
11
|
+
<features>
|
12
|
+
<acpi/>
|
13
|
+
<apic/>
|
14
|
+
<pae/>
|
15
|
+
</features>
|
16
|
+
<clock offset='utc'/>
|
17
|
+
<on_poweroff>destroy</on_poweroff>
|
18
|
+
<on_reboot>restart</on_reboot>
|
19
|
+
<on_crash>restart</on_crash>
|
20
|
+
<devices>
|
21
|
+
<emulator>/usr/bin/kvm</emulator>
|
22
|
+
<disk type='file' device='disk'>
|
23
|
+
<driver name='qemu' type='raw'/>
|
24
|
+
<source file='box-disk1.img'/>
|
25
|
+
<target dev='vda' bus='virtio'/>
|
26
|
+
|
27
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
28
|
+
|
29
|
+
</disk>
|
30
|
+
<controller type='usb' index='0'>
|
31
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
32
|
+
</controller>
|
33
|
+
<controller type='virtio-serial' index='0'>
|
34
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
35
|
+
</controller>
|
36
|
+
<interface type='network'>
|
37
|
+
<mac address='08:00:27:55:B8:8D'/>
|
38
|
+
<source network='vagrant'/>
|
39
|
+
<model type='virtio'/>
|
40
|
+
</interface>
|
41
|
+
<serial type='pty'>
|
42
|
+
<target port='0'/>
|
43
|
+
</serial>
|
44
|
+
<console type='pty'>
|
45
|
+
<target type='serial' port='0'/>
|
46
|
+
</console>
|
47
|
+
<input type='mouse' bus='ps2'/>
|
48
|
+
<sound model='ich6'>
|
49
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
50
|
+
</sound>
|
51
|
+
|
52
|
+
<graphics type='vnc' port='-1' autoport='yes'/>
|
53
|
+
|
54
|
+
<video>
|
55
|
+
<model type='cirrus' vram='9216' heads='1'/>
|
56
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
57
|
+
</video>
|
58
|
+
<memballoon model='virtio'>
|
59
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
60
|
+
</memballoon>
|
61
|
+
</devices>
|
62
|
+
</domain>
|
@@ -0,0 +1 @@
|
|
1
|
+
{"provider":"kvm"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Vagrant::Config.run do |config|
|
2
|
+
# This Vagrantfile is auto-generated by `vagrant package` to contain
|
3
|
+
# the MAC address of the box. Custom configuration should be placed in
|
4
|
+
# the actual `Vagrantfile` in this box.
|
5
|
+
config.vm.base_mac = "08002755B88D"
|
6
|
+
end
|
7
|
+
|
8
|
+
# Load include vagrant file if it exists after the auto-generated
|
9
|
+
# so it can override any of the settings
|
10
|
+
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
|
11
|
+
load include_vagrantfile if File.exist?(include_vagrantfile)
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
{"provider":"libvirt","format":"qcow2","virtual_size":1}
|
Binary file
|
Binary file
|
Binary file
|
data/test/test.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
def cleanup
|
6
|
+
puts "\nCLEANING UP"
|
7
|
+
base_output_dir = File.expand_path('../actual_output', __FILE__)
|
8
|
+
if File.directory? base_output_dir
|
9
|
+
FileUtils.rm_rf base_output_dir
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_plugin
|
14
|
+
puts "\nBUILDING PLUGIN"
|
15
|
+
pkg_dir = File.expand_path('../../pkg', __FILE__)
|
16
|
+
working_dir = Dir.pwd
|
17
|
+
Dir.chdir pkg_dir
|
18
|
+
FileUtils.rm( Dir.glob('*.gem') )
|
19
|
+
system('rake build')
|
20
|
+
Dir.chdir working_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_plugin
|
24
|
+
puts "\nINSTALLING PLUGIN"
|
25
|
+
pkg_dir = File.expand_path('../../pkg', __FILE__)
|
26
|
+
working_dir = Dir.pwd
|
27
|
+
Dir.chdir pkg_dir
|
28
|
+
system('vagrant plugin install *.gem')
|
29
|
+
Dir.chdir working_dir
|
30
|
+
end
|
31
|
+
|
32
|
+
def test(input, outputs)
|
33
|
+
failures = []
|
34
|
+
test_dir = File.expand_path( File.dirname(__FILE__) )
|
35
|
+
|
36
|
+
input_box = File.join(test_dir, 'input', input, 'mutate-test.box')
|
37
|
+
|
38
|
+
vagrant_dir = File.join(test_dir, 'actual_output', input)
|
39
|
+
FileUtils.mkdir_p vagrant_dir
|
40
|
+
ENV['VAGRANT_HOME'] = vagrant_dir
|
41
|
+
install_plugin
|
42
|
+
|
43
|
+
outputs.each do |output|
|
44
|
+
puts "\nTESTING #{input} to #{output}"
|
45
|
+
system("vagrant mutate #{input_box} #{output}")
|
46
|
+
output_dir = File.join(vagrant_dir, 'boxes', 'mutate-test', output)
|
47
|
+
expected_output_dir = File.join(test_dir, 'expected_output', input, output)
|
48
|
+
Dir.foreach(expected_output_dir) do |f|
|
49
|
+
next if f == '.' or f == '..'
|
50
|
+
output = File.join(output_dir, f)
|
51
|
+
expected_output = File.join(expected_output_dir, f)
|
52
|
+
test_passed = FileUtils.compare_file(output, expected_output)
|
53
|
+
unless test_passed
|
54
|
+
failures.push "#{output} does not match #{expected_output}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
return failures
|
60
|
+
end
|
61
|
+
|
62
|
+
cleanup
|
63
|
+
build_plugin
|
64
|
+
failures = test( 'virtualbox', ['kvm', 'libvirt'] )
|
65
|
+
|
66
|
+
unless failures.empty?
|
67
|
+
puts "\nTESTS FAILED"
|
68
|
+
failures.each {|f| puts f}
|
69
|
+
else
|
70
|
+
puts "\nALL TESTS PASSED"
|
71
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-mutate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
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-
|
12
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: archive-tar-minitar
|
@@ -77,12 +77,24 @@ files:
|
|
77
77
|
- lib/vagrant-mutate/converter.rb
|
78
78
|
- lib/vagrant-mutate/errors.rb
|
79
79
|
- lib/vagrant-mutate/mutate.rb
|
80
|
+
- lib/vagrant-mutate/provider/kvm.rb
|
80
81
|
- lib/vagrant-mutate/provider/libvirt.rb
|
81
82
|
- lib/vagrant-mutate/provider/provider.rb
|
82
83
|
- lib/vagrant-mutate/provider/virtualbox.rb
|
83
84
|
- lib/vagrant-mutate/version.rb
|
84
85
|
- locales/en.yml
|
85
|
-
-
|
86
|
+
- templates/kvm/box.xml.erb
|
87
|
+
- test/expected_output/virtualbox/kvm/Vagrantfile
|
88
|
+
- test/expected_output/virtualbox/kvm/box-disk1.img
|
89
|
+
- test/expected_output/virtualbox/kvm/box.xml
|
90
|
+
- test/expected_output/virtualbox/kvm/metadata.json
|
91
|
+
- test/expected_output/virtualbox/libvirt/Vagrantfile
|
92
|
+
- test/expected_output/virtualbox/libvirt/box.img
|
93
|
+
- test/expected_output/virtualbox/libvirt/metadata.json
|
94
|
+
- test/input/kvm/mutate-test.box
|
95
|
+
- test/input/libvirt/mutate-test.box
|
96
|
+
- test/input/virtualbox/mutate-test.box
|
97
|
+
- test/test.rb
|
86
98
|
- vagrant-mutate.gemspec
|
87
99
|
homepage: ''
|
88
100
|
licenses:
|
@@ -110,4 +122,14 @@ signing_key:
|
|
110
122
|
specification_version: 3
|
111
123
|
summary: Convert vagrant boxes to work with different providers
|
112
124
|
test_files:
|
113
|
-
- test/
|
125
|
+
- test/expected_output/virtualbox/kvm/Vagrantfile
|
126
|
+
- test/expected_output/virtualbox/kvm/box-disk1.img
|
127
|
+
- test/expected_output/virtualbox/kvm/box.xml
|
128
|
+
- test/expected_output/virtualbox/kvm/metadata.json
|
129
|
+
- test/expected_output/virtualbox/libvirt/Vagrantfile
|
130
|
+
- test/expected_output/virtualbox/libvirt/box.img
|
131
|
+
- test/expected_output/virtualbox/libvirt/metadata.json
|
132
|
+
- test/input/kvm/mutate-test.box
|
133
|
+
- test/input/libvirt/mutate-test.box
|
134
|
+
- test/input/virtualbox/mutate-test.box
|
135
|
+
- test/test.rb
|
data/test/mutate-test.box
DELETED
Binary file
|