vagrant-mutate 1.1.0 → 1.2.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: 8d95a6ed26edca3fd9acfc503fac048f3f5e895b
4
- data.tar.gz: 011568c7558b966ffd0559f5732d1defd027ba8d
3
+ metadata.gz: db1c439fc85325283fe530d325f2b5da691903c6
4
+ data.tar.gz: 8d7fcc03d6d5415b56c9cc0cdc136d305d676f1e
5
5
  SHA512:
6
- metadata.gz: e1f6285665108a943b5d6c913aa32e4c92b46146869b896f7402d8af3a376e197ff6c027ebb3d0f2f671990658f30a78742076671184b211c761b8004f96ee30
7
- data.tar.gz: ebb8c38126842b3f19122e201501fe87e32bd57f4f6600c683d1d5be5eb8c143703ac19ca166ae975416046f4fa2695e0358aa63ed5a3d7b34874a03794b71da
6
+ metadata.gz: ad16f50d0c9cfd2882e5976b994af9ba7bff1313765b22bbac08180c99d9c29f34e690cfb001d47406afaf94f4b5a77afc9dca85e1982d0bb1ec10bcb123b7aa
7
+ data.tar.gz: fee91995f7fc4abe26638233a10fc1ad90851963af01154c8de7194218ab03ebe2e7498b94d9a89b6c2ba0994a662c628f8db7123920e627d8f49a7b44ffccfc
@@ -1,3 +1,6 @@
1
+ # 1.2.0 (2016-08-15)
2
+ * Add support for converting to bhyve (#86)
3
+
1
4
  # 1.1.1 (2016-02-24)
2
5
  * Add option to force use of virtio for disks (#82)
3
6
 
data/README.md CHANGED
@@ -6,16 +6,13 @@ Vagrant-mutate is a vagrant plugin to convert vagrant boxes to work with differe
6
6
 
7
7
  * Virtualbox to kvm
8
8
  * Virtualbox to libvirt
9
+ * Virtualbox to bhyve
9
10
  * Libvirt to kvm
10
11
  * Kvm to libvirt
11
12
 
12
13
  ## Compatibility
13
14
 
14
- Throughout its development vagrant-mutate has been tested against the following versions. It may work with other versions too. Note that Vagrant-mutate 0.3 and later requires Vagrant 1.5. If you are using an older vagrant, install vagrant-mutate version 0.2.6.
15
-
16
- * [vagrant](http://www.vagrantup.com) 1.3.5, 1.4.3, and 1.5.4
17
- * [vagrant-kvm](https://github.com/adrahon/vagrant-kvm) 0.1.4
18
- * [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) 0.0.11
15
+ Vagrant-mutate 0.3 and later requires Vagrant 1.5. If you are using an older vagrant, install vagrant-mutate version 0.2.6.
19
16
 
20
17
  ## Installation
21
18
 
@@ -25,7 +22,7 @@ First, you must install [qemu-img](http://wiki.qemu.org/Main_Page) and the libvi
25
22
 
26
23
  #### Debian and derivatives
27
24
 
28
- apt-get install qemu-utils libvirt-dev
25
+ apt-get install qemu-utils libvirt-dev ruby-dev
29
26
 
30
27
  #### Red Hat and derivatives
31
28
 
@@ -6,6 +6,20 @@ module VagrantMutate
6
6
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
7
7
  end
8
8
 
9
+ # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
10
+ def self.find_bin(bin)
11
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
12
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
13
+ exts.each do |ext|
14
+ exe = File.join(path, "#{bin}#{ext}")
15
+ if File.executable? exe
16
+ return exe if File.executable?(exe) && !File.directory?(exe)
17
+ end
18
+ end
19
+ end
20
+ return nil
21
+ end
22
+
9
23
  class Plugin < Vagrant.plugin('2')
10
24
  name 'vagrant-mutate'
11
25
 
@@ -0,0 +1,19 @@
1
+ require_relative 'box'
2
+
3
+ module VagrantMutate
4
+ module Box
5
+ class Bhyve < Box
6
+ def initialize(env, name, version, dir)
7
+ super
8
+ @provider_name = 'bhyve'
9
+ @supported_input = true
10
+ @supported_output = true
11
+ @image_format = 'raw'
12
+ @image_name = 'disk.img'
13
+ end
14
+
15
+ # TODO
16
+
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  require_relative 'box'
2
- require 'rexml/document'
2
+ require 'nokogiri'
3
3
 
4
4
  module VagrantMutate
5
5
  module Box
@@ -20,8 +20,8 @@ module VagrantMutate
20
20
  def disk_interface
21
21
  domain_file = File.join(@dir, 'box.xml')
22
22
  begin
23
- domain = REXML::Document.new(File.read(domain_file))
24
- domain.elements['/domain/devices/disk/target'].attributes['bus']
23
+ domain = File.open(domain_file) { |f| Nokogiri::XML(f) }
24
+ domain.xpath("//*[local-name()='domain']/*[local-name()='devices']/*[local-name()='disk']/*[local-name()='target']").attribute('bus')
25
25
  rescue => e
26
26
  raise Errors::BoxAttributeError, error_message: e.message
27
27
  end
@@ -137,6 +137,9 @@ module VagrantMutate
137
137
  def create_box(provider_name, name, version, dir)
138
138
  @logger.info "Creating box #{name} with provider #{provider_name} and version #{version} in #{dir}"
139
139
  case provider_name
140
+ when 'bhyve'
141
+ require_relative 'box/bhyve'
142
+ Box::Bhyve.new(@env, name, version, dir)
140
143
  when 'kvm'
141
144
  require_relative 'box/kvm'
142
145
  Box::Kvm.new(@env, name, version, dir)
@@ -0,0 +1,40 @@
1
+ require 'erb'
2
+
3
+ module VagrantMutate
4
+ module Converter
5
+ class Bhyve < Converter
6
+ def generate_metadata
7
+
8
+ output_name = File.join(@output_box.dir, @output_box.image_name).shellescape
9
+
10
+ file_output = `file #{output_name}`
11
+
12
+ if file_output.include? "GRUB"
13
+ loader = "grub-bhyve"
14
+ else
15
+ loader = "bhyveload"
16
+ end
17
+
18
+ {
19
+ "provider" => @output_box.provider_name,
20
+ }
21
+ end
22
+
23
+ def generate_vagrantfile
24
+ memory = @input_box.memory / 1024 / 1024 # convert bytes to mebibytes
25
+ cpus = @input_box.cpus
26
+ <<-EOF
27
+ config.vm.provider :bhyve do |vm|
28
+ vm.memory = "#{memory}M"
29
+ vm.cpus = "#{cpus}"
30
+ end
31
+ EOF
32
+ end
33
+
34
+ def write_specific_files
35
+ # nothing yet
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -6,6 +6,9 @@ module VagrantMutate
6
6
  class Converter
7
7
  def self.create(env, input_box, output_box, force_virtio='false')
8
8
  case output_box.provider_name
9
+ when 'bhyve'
10
+ require_relative 'bhyve'
11
+ Bhyve.new(env, input_box, output_box)
9
12
  when 'kvm'
10
13
  require_relative 'kvm'
11
14
  Kvm.new(env, input_box, output_box)
@@ -34,10 +37,10 @@ module VagrantMutate
34
37
  "to #{@output_box.provider_name}."
35
38
 
36
39
  @input_box.verify_format
40
+ write_disk
37
41
  write_metadata
38
42
  write_vagrantfile
39
43
  write_specific_files
40
- write_disk
41
44
  end
42
45
 
43
46
  private
@@ -97,7 +100,9 @@ module VagrantMutate
97
100
  qemu_options = '-p -S 16k'
98
101
  qemu_version = Qemu.qemu_version()
99
102
  if qemu_version >= Gem::Version.new('1.1.0')
100
- qemu_options += ' -o compat=1.1'
103
+ if output_format == 'qcow2'
104
+ qemu_options += ' -o compat=1.1'
105
+ end
101
106
  end
102
107
 
103
108
  command = "qemu-img convert #{qemu_options} -O #{output_format} #{input_file} #{output_file}"
@@ -43,15 +43,22 @@ module VagrantMutate
43
43
  private
44
44
 
45
45
  def find_kvm
46
- qemu_bin_list = ['/usr/bin/qemu-system-x86_64',
47
- '/usr/bin/qemu-system-i386',
48
- '/usr/bin/qemu-kvm',
49
- '/usr/libexec/qemu-kvm',
50
- '/usr/bin/kvm']
51
- qemu_bin = qemu_bin_list.find { |binary| File.exist? binary }
46
+ qemu_bin = nil
47
+
48
+ qemu_bin_list = ['qemu-system-x86_64',
49
+ 'qemu-system-i386',
50
+ 'qemu-kvm',
51
+ 'kvm']
52
+ logger = Log4r::Logger.new('vagrant::mutate')
53
+ qemu_bin_list.each do |qemu|
54
+ qemu_bin = VagrantMutate.find_bin(qemu)
55
+ break
56
+ end
57
+
52
58
  unless qemu_bin
53
59
  fail Errors::QemuNotFound
54
60
  end
61
+ logger.info 'Found qemu_bin: ' + qemu_bin
55
62
  qemu_bin
56
63
  end
57
64
 
@@ -1,20 +1,14 @@
1
1
  module VagrantMutate
2
2
  class Qemu
3
- # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
4
3
  def self.verify_qemu_installed
4
+ qemu_img_bin = nil
5
5
  logger = Log4r::Logger.new('vagrant::mutate')
6
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
7
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
8
- exts.each do |ext|
9
- exe = File.join(path, "qemu-img#{ext}")
10
- if File.executable? exe
11
- logger.info 'Found qemu'
12
- return
13
- end
14
- end
6
+ qemu_img_bin = VagrantMutate.find_bin("qemu-img")
7
+ unless qemu_img_bin
8
+ fail Errors::QemuImgNotFound
15
9
  end
16
- # if we make it here qemu-img command was not found
17
- fail Errors::QemuImgNotFound
10
+ logger.info 'Found qemu-img: ' + qemu_img_bin
11
+ qemu_img_bin
18
12
  end
19
13
 
20
14
  def self.qemu_version()
@@ -1,3 +1,3 @@
1
1
  module VagrantMutate
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,6 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.provider :bhyve do |vm|
3
+ vm.memory = "256M"
4
+ vm.cpus = "1"
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ {"provider":"bhyve"}
@@ -89,7 +89,7 @@ end
89
89
  cleanup
90
90
  ensure_pkg_dir
91
91
  build_plugin
92
- failures = test('virtualbox', %w(kvm libvirt))
92
+ failures = test('virtualbox', %w(kvm libvirt bhyve))
93
93
  failures += test('libvirt', ['kvm'])
94
94
  failures += test('kvm', ['libvirt'])
95
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-mutate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pitts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2016-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,11 +52,13 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/vagrant-mutate.rb
55
+ - lib/vagrant-mutate/box/bhyve.rb
55
56
  - lib/vagrant-mutate/box/box.rb
56
57
  - lib/vagrant-mutate/box/kvm.rb
57
58
  - lib/vagrant-mutate/box/libvirt.rb
58
59
  - lib/vagrant-mutate/box/virtualbox.rb
59
60
  - lib/vagrant-mutate/box_loader.rb
61
+ - lib/vagrant-mutate/converter/bhyve.rb
60
62
  - lib/vagrant-mutate/converter/converter.rb
61
63
  - lib/vagrant-mutate/converter/kvm.rb
62
64
  - lib/vagrant-mutate/converter/libvirt.rb
@@ -73,6 +75,9 @@ files:
73
75
  - test/expected_output/libvirt/kvm/box-disk1.img
74
76
  - test/expected_output/libvirt/kvm/box.xml
75
77
  - test/expected_output/libvirt/kvm/metadata.json
78
+ - test/expected_output/virtualbox/bhyve/Vagrantfile
79
+ - test/expected_output/virtualbox/bhyve/disk.img
80
+ - test/expected_output/virtualbox/bhyve/metadata.json
76
81
  - test/expected_output/virtualbox/kvm/Vagrantfile
77
82
  - test/expected_output/virtualbox/kvm/box-disk1.img
78
83
  - test/expected_output/virtualbox/kvm/box.xml
@@ -117,6 +122,9 @@ test_files:
117
122
  - test/expected_output/libvirt/kvm/box-disk1.img
118
123
  - test/expected_output/libvirt/kvm/box.xml
119
124
  - test/expected_output/libvirt/kvm/metadata.json
125
+ - test/expected_output/virtualbox/bhyve/Vagrantfile
126
+ - test/expected_output/virtualbox/bhyve/disk.img
127
+ - test/expected_output/virtualbox/bhyve/metadata.json
120
128
  - test/expected_output/virtualbox/kvm/Vagrantfile
121
129
  - test/expected_output/virtualbox/kvm/box-disk1.img
122
130
  - test/expected_output/virtualbox/kvm/box.xml