vagrant-mutate 0.2.3 → 0.2.4
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/CHANGELOG.md +4 -0
- data/lib/vagrant-mutate/box/kvm.rb +12 -1
- data/lib/vagrant-mutate/box/libvirt.rb +6 -2
- data/lib/vagrant-mutate/box/virtualbox.rb +1 -6
- data/lib/vagrant-mutate/converter/converter.rb +11 -11
- data/lib/vagrant-mutate/converter/kvm.rb +10 -1
- data/lib/vagrant-mutate/converter/libvirt.rb +8 -0
- data/lib/vagrant-mutate/version.rb +1 -1
- data/test/expected_output/kvm/libvirt/Vagrantfile +4 -10
- data/test/expected_output/libvirt/kvm/Vagrantfile +2 -10
- data/test/expected_output/virtualbox/kvm/Vagrantfile +2 -10
- data/test/expected_output/virtualbox/libvirt/Vagrantfile +4 -10
- data/test/test.rb +8 -5
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 0.2.4 (2014-01-23)
|
2
|
+
* Generate new vagrantfiles instead of copying them
|
3
|
+
* Set disk bus when converting to vagrant-libvirt (#41)
|
4
|
+
|
1
5
|
# 0.2.3 (2014-01-20)
|
2
6
|
* Warn when qemu version cannot read vmdk3 files (#29)
|
3
7
|
* Fix errors in how box name and provider were parsed (#35)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'box'
|
2
|
+
require 'rexml/document'
|
2
3
|
|
3
4
|
module VagrantMutate
|
4
5
|
module Box
|
@@ -14,9 +15,19 @@ module VagrantMutate
|
|
14
15
|
end
|
15
16
|
|
16
17
|
# TODO implement these methods
|
17
|
-
# architecture, mac_address, cpus,
|
18
|
+
# architecture, mac_address, cpus, memory
|
18
19
|
# to support converting to providers besides libvirt
|
19
20
|
|
21
|
+
def disk_interface
|
22
|
+
domain_file = File.join( @dir, 'box.xml' )
|
23
|
+
begin
|
24
|
+
domain = REXML::Document.new( File.read(domain_file) )
|
25
|
+
domain.elements['/domain/devices/disk/target'].attributes['bus']
|
26
|
+
rescue => e
|
27
|
+
raise Errors::BoxAttributeError, :error_message => e.message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
20
31
|
end
|
21
32
|
end
|
22
33
|
end
|
@@ -11,6 +11,7 @@ module VagrantMutate
|
|
11
11
|
@supported_output = true
|
12
12
|
@image_format = 'qcow2'
|
13
13
|
@image_name = 'box.img'
|
14
|
+
@mac = nil
|
14
15
|
end
|
15
16
|
|
16
17
|
# since none of below can be determined from the box
|
@@ -22,8 +23,11 @@ module VagrantMutate
|
|
22
23
|
|
23
24
|
# kvm prefix is 52:54:00
|
24
25
|
def mac_address
|
25
|
-
|
26
|
-
|
26
|
+
unless @mac
|
27
|
+
octets = 3.times.map { rand(255).to_s(16) }
|
28
|
+
@mac = "525400#{octets[0]}#{octets[1]}#{octets[2]}"
|
29
|
+
end
|
30
|
+
return @mac
|
27
31
|
end
|
28
32
|
|
29
33
|
def cpus
|
@@ -34,7 +34,7 @@ module VagrantMutate
|
|
34
34
|
|
35
35
|
ovf.elements.each("//vbox:Machine/Hardware//Adapter") do |ele|
|
36
36
|
if ele.attributes['enabled'] == 'true'
|
37
|
-
mac =
|
37
|
+
mac = ele.attributes['MACAddress']
|
38
38
|
break
|
39
39
|
end
|
40
40
|
end
|
@@ -118,11 +118,6 @@ module VagrantMutate
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
# convert to more standard format with colons
|
122
|
-
def format_mac(mac)
|
123
|
-
mac.scan(/(.{2})/).join(':')
|
124
|
-
end
|
125
|
-
|
126
121
|
# Takes a quantity and a unit
|
127
122
|
# returns quantity in bytes
|
128
123
|
# mib = true to use mebibytes, etc
|
@@ -34,14 +34,13 @@ module VagrantMutate
|
|
34
34
|
|
35
35
|
@input_box.verify_format
|
36
36
|
write_metadata
|
37
|
-
|
37
|
+
write_vagrantfile
|
38
38
|
write_specific_files
|
39
39
|
write_disk
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
|
45
44
|
def write_metadata
|
46
45
|
metadata = generate_metadata
|
47
46
|
begin
|
@@ -54,17 +53,18 @@ module VagrantMutate
|
|
54
53
|
@logger.info "Wrote metadata"
|
55
54
|
end
|
56
55
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
rescue => e
|
65
|
-
raise Errors::WriteVagrantfileFailed, :error_message => e.message
|
56
|
+
def write_vagrantfile
|
57
|
+
body = generate_vagrantfile
|
58
|
+
begin
|
59
|
+
File.open( File.join( @output_box.dir, 'Vagrantfile'), 'w') do |f|
|
60
|
+
f.puts( 'Vagrant.configure("2") do |config|' )
|
61
|
+
f.puts( body )
|
62
|
+
f.puts( 'end' )
|
66
63
|
end
|
64
|
+
rescue => e
|
65
|
+
raise Errors::WriteVagrantfileFailed, :error_message => e.message
|
67
66
|
end
|
67
|
+
@logger.info "Wrote vagrantfile"
|
68
68
|
end
|
69
69
|
|
70
70
|
def write_disk
|
@@ -10,6 +10,10 @@ module VagrantMutate
|
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
|
+
def generate_vagrantfile
|
14
|
+
" config.vm.base_mac = '#{@input_box.mac_address}'"
|
15
|
+
end
|
16
|
+
|
13
17
|
def write_specific_files
|
14
18
|
template_path = VagrantMutate.source_root.join('templates', 'kvm', 'box.xml.erb')
|
15
19
|
template = File.read(template_path)
|
@@ -24,7 +28,7 @@ module VagrantMutate
|
|
24
28
|
name = @input_box.name
|
25
29
|
memory = @input_box.memory / 1024 # convert bytes to kib
|
26
30
|
cpus = @input_box.cpus
|
27
|
-
mac = @input_box.mac_address
|
31
|
+
mac = format_mac( @input_box.mac_address )
|
28
32
|
arch = @input_box.architecture
|
29
33
|
|
30
34
|
qemu_bin = find_kvm
|
@@ -48,6 +52,11 @@ module VagrantMutate
|
|
48
52
|
return qemu_bin
|
49
53
|
end
|
50
54
|
|
55
|
+
# convert to format with colons
|
56
|
+
def format_mac(mac)
|
57
|
+
mac.scan(/(.{2})/).join(':')
|
58
|
+
end
|
59
|
+
|
51
60
|
end
|
52
61
|
end
|
53
62
|
end
|
@@ -10,6 +10,14 @@ module VagrantMutate
|
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
|
+
def generate_vagrantfile
|
14
|
+
<<-EOF
|
15
|
+
config.vm.provider :libvirt do |libvirt|
|
16
|
+
libvirt.disk_bus = '#{@input_box.disk_interface}'
|
17
|
+
end
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
|
13
21
|
def write_specific_files
|
14
22
|
# nothing to do here
|
15
23
|
end
|
@@ -1,11 +1,5 @@
|
|
1
|
-
Vagrant
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
config.vm.base_mac = "08002755B88D"
|
1
|
+
Vagrant.configure("2") do |config|
|
2
|
+
config.vm.provider :libvirt do |libvirt|
|
3
|
+
libvirt.disk_bus = 'virtio'
|
4
|
+
end
|
6
5
|
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)
|
@@ -1,11 +1,3 @@
|
|
1
|
-
Vagrant
|
2
|
-
|
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"
|
1
|
+
Vagrant.configure("2") do |config|
|
2
|
+
config.vm.base_mac = '525400cbb280'
|
6
3
|
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)
|
@@ -1,11 +1,3 @@
|
|
1
|
-
Vagrant
|
2
|
-
|
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"
|
1
|
+
Vagrant.configure("2") do |config|
|
2
|
+
config.vm.base_mac = '08002755B88D'
|
6
3
|
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)
|
@@ -1,11 +1,5 @@
|
|
1
|
-
Vagrant
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
config.vm.base_mac = "08002755B88D"
|
1
|
+
Vagrant.configure("2") do |config|
|
2
|
+
config.vm.provider :libvirt do |libvirt|
|
3
|
+
libvirt.disk_bus = 'sata'
|
4
|
+
end
|
6
5
|
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)
|
data/test/test.rb
CHANGED
@@ -34,11 +34,14 @@ end
|
|
34
34
|
def derandomize_output(input, output_dir)
|
35
35
|
if input == 'libvirt'
|
36
36
|
if File.split(output_dir).last == 'kvm'
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
['box.xml', 'Vagrantfile'].each do |f|
|
38
|
+
path = File.join(output_dir, f)
|
39
|
+
contents = File.read(path)
|
40
|
+
contents.gsub!(/52:54:00:[0-9a-f:]+/, '52:54:00:cb:b2:80')
|
41
|
+
contents.gsub!(/525400[0-9a-f]+/, '525400cbb280')
|
42
|
+
File.open(path, 'w') do |f|
|
43
|
+
f.write(contents)
|
44
|
+
end
|
42
45
|
end
|
43
46
|
end
|
44
47
|
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.2.
|
4
|
+
version: 0.2.4
|
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: 2014-01-
|
12
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|