vagrant-bhyve 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +13 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +111 -0
  8. data/Rakefile +6 -0
  9. data/Vagrantfiles/Vagrantfile_CentOS-6 +14 -0
  10. data/Vagrantfiles/Vagrantfile_CentOS-7 +11 -0
  11. data/Vagrantfiles/Vagrantfile_Debian_Ubuntu +11 -0
  12. data/example_box/README.md +46 -0
  13. data/example_box/Vagrantfile +9 -0
  14. data/example_box/metadata.json +3 -0
  15. data/lib/vagrant-bhyve.rb +21 -0
  16. data/lib/vagrant-bhyve/action.rb +215 -0
  17. data/lib/vagrant-bhyve/action/boot.rb +26 -0
  18. data/lib/vagrant-bhyve/action/cleanup.rb +23 -0
  19. data/lib/vagrant-bhyve/action/create_bridge.rb +33 -0
  20. data/lib/vagrant-bhyve/action/create_tap.rb +31 -0
  21. data/lib/vagrant-bhyve/action/destroy.rb +23 -0
  22. data/lib/vagrant-bhyve/action/forward_ports.rb +53 -0
  23. data/lib/vagrant-bhyve/action/import.rb +32 -0
  24. data/lib/vagrant-bhyve/action/load.rb +27 -0
  25. data/lib/vagrant-bhyve/action/prepare_nfs_settings.rb +50 -0
  26. data/lib/vagrant-bhyve/action/prepare_nfs_valid_ids.rb +23 -0
  27. data/lib/vagrant-bhyve/action/setup.rb +27 -0
  28. data/lib/vagrant-bhyve/action/shutdown.rb +26 -0
  29. data/lib/vagrant-bhyve/action/wait_until_up.rb +48 -0
  30. data/lib/vagrant-bhyve/config.rb +75 -0
  31. data/lib/vagrant-bhyve/driver.rb +674 -0
  32. data/lib/vagrant-bhyve/errors.rb +55 -0
  33. data/lib/vagrant-bhyve/executor.rb +38 -0
  34. data/lib/vagrant-bhyve/plugin.rb +73 -0
  35. data/lib/vagrant-bhyve/provider.rb +126 -0
  36. data/lib/vagrant-bhyve/version.rb +5 -0
  37. data/locales/en.yml +90 -0
  38. data/vagrant-bhyve.gemspec +24 -0
  39. metadata +137 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 834cbbeb31e90df1fd8c9249f2c32873804857e1
4
+ data.tar.gz: 947fe959a6ba8fd5727adb5d9e6e7862f6468151
5
+ SHA512:
6
+ metadata.gz: 1ba2aab48080e9e3f7049927fb6559718c8c1521ecfd63df1dfd2d9a329ca7ed420af31cc69109598dfaef941bad172039d8d21c72f32819c67f576948ff8fb5
7
+ data.tar.gz: 158a4f95c3878b63ba6040ee8f3d8959644c6389a8aa8b9b8cc48cb0ac9ed6aa8decc8d894a923ee172685f15f70e6447faeb82c5b21f2541f33e874863c8e66
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /svn-commit.tmp
11
+ /vendor/
12
+ /example_box/*img
13
+ /example_box/*raw
14
+ /bin/
15
+ /Vagrantfile
16
+ /.vagrant
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.4'
7
+ end
8
+
9
+ group :plugins do
10
+ gem 'vagrant-bhyve', path: '.'
11
+ #gem 'vagrant-sshfs', '1.1.0'
12
+ #gem 'vagrant-mutate', :git => 'https://github.com/swills/vagrant-mutate'
13
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tong Li
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # vagrant-bhyve
2
+
3
+ This is a Vagrant plugin which enable FreeBSD's hypervisor bhyve as its backend.
4
+
5
+ - [Status](#status)
6
+ - [Functions](#functions)
7
+ - [Boxes](#boxes)
8
+ - [Test](#test)
9
+ - [Setup environment](#setup-environment)
10
+ - [Create a box](#create-a-box)
11
+ - [Add the box](#add-the-box)
12
+ - [Run the box](#run-the-box)
13
+ - [SSH into the box](#ssh-into-the-box)
14
+ - [Shutdown the box and cleanup](#shutdown-the-box-and-cleanup)
15
+
16
+ ## Status
17
+
18
+ ### Functions
19
+
20
+ | Function | Status
21
+ | :---------- | :-----
22
+ | Box format | Defined
23
+ | Check bhyve support | Working
24
+ | Cloning | Working(needs gcp package to copy image)
25
+ | Booting(BIOS) | Working
26
+ | Network | Working(needs pf and dnsmasq to provider NAT and DHCP)
27
+ | SSH/SSH run | Working(SSH run may needs bash)
28
+ | Graceful shutdown | Working
29
+ | ACPI shutdown | Working
30
+ | Destroying | Working
31
+ | Provision | Working
32
+ | File sharing | Working(NFS and vagrant-sshfs, maybe switch to VirtFS in the future)
33
+ | Booting(UEFI) | Not working
34
+ | Port forwarding | Not working
35
+ | Suspend | Not supported by bhyve yet
36
+ | Resume | Not supported by bhyve yet
37
+
38
+ ### Boxes
39
+
40
+ Collecting status of boxes from [Atlas](https://atlas.hashicorp.com/boxes/search) other than those provided by [FreeBSD](https://atlas.hashicorp.com/freebsd)
41
+
42
+ | Function | Status
43
+ | :--------------------------------------------------------------------------------- | :------
44
+ | [ubuntu/trusty64](https://atlas.hashicorp.com/ubuntu/boxes/trusty64) | Working
45
+ | [laravel/homestead](https://atlas.hashicorp.com/laravel/boxes/homestead) | Untested
46
+ | [hashicorp/precise64](https://atlas.hashicorp.com/hashicorp/boxes/precise64) | Untested
47
+ | [hashicorp/precise32](https://atlas.hashicorp.com/hashicorp/boxes/precise32) | Untested
48
+ | [centos/7](https://atlas.hashicorp.com/centos/boxes/7) | Working
49
+ | [puphpet/ubuntu1404-x64](https://atlas.hashicorp.com/puphpet/boxes/ubuntu1404-x64) | Untested
50
+ | [ubuntu/trusty32](https://atlas.hashicorp.com/ubuntu/boxes/trusty32) | Untested
51
+ | [puphpet/debian75-x64](https://atlas.hashicorp.com/puphpet/boxes/debian75-x64) | Untested
52
+ | [debian/jessie64](https://atlas.hashicorp.com/debian/boxes/jessie64) | Working
53
+ | [scotch/box](https://atlas.hashicorp.com/scotch/boxes/box) | Untested
54
+ | [centos/6](https://atlas.hashicorp.com/centos/boxes/6) | Working
55
+
56
+ ## Test
57
+
58
+ ### Setup environment
59
+
60
+ $ git clone https://github.com/jesa7955/vagrant-bhyve.git
61
+ $ cd vagrant-bhyve
62
+ $ bundle install --path vendor/bundle --binstubs
63
+
64
+ Note we will need package coreutils and dnsmasq(and of course we will need grub-bhyve to boot Linux box), vagrant-bhyve will try to install them with pkg.
65
+
66
+ ### Create a box
67
+
68
+ Thanks to [Steve Wills](https://github.com/swills)'s work, now you can convert a VirtualBox box to a bhyve one with [vagrant-mutate](https://github.com/sciurus/vagrant-mutate).
69
+
70
+ ### Run the box
71
+
72
+ After a box is created, you should create another Vagrantfile.
73
+
74
+ ```ruby
75
+ Vagrant.configure("2") do |config|
76
+ config.vm.box = "boxname"
77
+ end
78
+ ```
79
+
80
+ then execute this command to start the box with bhyve
81
+
82
+ $ /path/to/vagrant-bhyve/bin/vagrant up --provider=bhyve
83
+
84
+ ### SSH into the box
85
+
86
+ After the box is booted(uped), you can ssh into by executing this command. Note that you will have to use password to authorize for now.
87
+
88
+ $ /path/to/vagrant-bhyve/bin/vagrant ssh
89
+
90
+ ### Shutdown the box and cleanup
91
+
92
+ This command will shutdown the booted VM and clean up environment
93
+
94
+ $ /path/to/vagrant-bhyve/bin/vagrant halt
95
+
96
+ ### Destroy the box
97
+
98
+ $ /path/to/vagrant-bhyve/vagrant destroy
99
+
100
+ ## Installation
101
+
102
+ ## Usage
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jesa7955/vagrant-bhyve.
107
+
108
+
109
+ ## License
110
+
111
+ MIT
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.provider :bhyve do |vm|
6
+ vm.grub_config_file = %{
7
+ linux (hd0,msdos1)/vmlinuz-2.6.32-642.1.1.el6.x86_64 root=/dev/mapper/VolGroup00-LogVol00
8
+ initrd (hd0,msdos1)/initramfs-2.6.32-642.1.1.el6.x86_64.img
9
+ boot
10
+ }
11
+ vm.memory = "512M"
12
+ vm.cpus = "1"
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.provider :bhyve do |vm|
6
+ vm.grub_run_partition = "msdos2"
7
+ vm.grub_run_dir = "/grub2"
8
+ vm.memory = "512M"
9
+ vm.cpus = "1"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.provider :bhyve do |vm|
6
+ vm.grub_run_partition = "msdos1"
7
+ vm.memory = "512M"
8
+ vm.cpus = "1"
9
+ end
10
+ end
11
+
@@ -0,0 +1,46 @@
1
+ # Vagrant Bhyve Example Box
2
+
3
+ Box format of bhyve provider is a plain directory consist of `Vagrantfile`, `metadata.json`, bhyve disk file, and an optional `uefi.fd`
4
+
5
+ ```
6
+ |
7
+ |- Vagrantfile This is where Bhyve is configured.
8
+ |- disk.img The disk image including basic OS.
9
+ |- metadata.json Box metadata.
10
+ `- uefi.fd UEFI firmware (only for guests who use uefi as firmware).
11
+ ```
12
+
13
+ Available configurations for the provider are:
14
+
15
+ * `memory`: Amount of memory, e.g. `512M`
16
+ * `cpus`: Number of CPUs, e.g. `1`
17
+ * `disks`: An array of disks which users want to attach to the guest other than the box shipped one. Each disk is described by a hash which has three members.
18
+ * **path/name**: path is used to specify a image file outside .vagrant direcotory while name is used to specify an image file name which will be created inside .vagrant directory for the box. Only one of these two arguments is needed to describe an additional disk file.
19
+ * **size**: specify the image file's virutal size.
20
+ * **format**: specify the format of disk image file. Bhyve only support raw images now but maybe we can extend vagrant-bhyve when bhyve supports more.
21
+ * `cdroms`: Like `disks`, this is an array contains all ISO files which users want to attach to bhyve. Now, each cdrom is described by a hash contains only the path to a ISO file.
22
+ * ~~`grub_config_file`:~~
23
+ * ~~`grub_run_partition`:~~
24
+ :* ~~`grub_run_dir`:~~
25
+
26
+ Put everything we need in a directory and run the command below to package them as a box file.
27
+ ```
28
+ $ tar cvzf test.box ./metadata.json ./Vagrantfile ./disk.img
29
+ ```
30
+
31
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
32
+ defaults for Bhyve. These defaults can easily be overwritten by higher-level
33
+ Vagrantfiles (such as project root Vagrantfiles).
34
+
35
+ ## Box Metadata
36
+
37
+ Bhyve box should define at least two data fields in `metadata.json` file.
38
+
39
+ * provider - Provider name is bhyve.
40
+
41
+ ## Converting Boxes
42
+
43
+ Instead of creating a box from scratch, you can use
44
+ [vagrant-mutate](https://github.com/sciurus/vagrant-mutate)
45
+ to take boxes created for other Vagrant providers and use them
46
+ with vagrant-bhyve
@@ -0,0 +1,9 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.provider :bhyve do |vm|
6
+ vm.memory = "512M"
7
+ vm.cpus = "1"
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider" : "bhyve"
3
+ }
@@ -0,0 +1,21 @@
1
+ require "pathname"
2
+
3
+ module VagrantPlugins
4
+ module ProviderBhyve
5
+ lib_path = Pathname.new(File.expand_path("../vagrant-bhyve", __FILE__))
6
+ autoload :Action, lib_path.join('action')
7
+ autoload :Executor, lib_path.join('executor')
8
+ autoload :Driver, lib_path.join('driver')
9
+ autoload :Errors, lib_path.join('errors')
10
+
11
+
12
+ # This function returns the path to the source of this plugin
13
+ #
14
+ # @return [Pathname]
15
+ def self.source_root
16
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
17
+ end
18
+ end
19
+ end
20
+
21
+ require "vagrant-bhyve/plugin"
@@ -0,0 +1,215 @@
1
+ require "pathname"
2
+ require "vagrant/action/builder"
3
+
4
+ module VagrantPlugins
5
+ module ProviderBhyve
6
+ module Action
7
+ include Vagrant::Action::Builtin
8
+
9
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
10
+ autoload :Boot, action_root.join('boot')
11
+ autoload :CreateBridge, action_root.join('create_bridge')
12
+ autoload :CreateTap, action_root.join('create_tap')
13
+ autoload :Cleanup, action_root.join('cleanup')
14
+ autoload :Destroy, action_root.join('destroy')
15
+ autoload :ForwardPorts, action_root.join('forward_ports')
16
+ autoload :Import, action_root.join('import')
17
+ autoload :Load, action_root.join('load')
18
+ autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
19
+ autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
20
+ autoload :Setup, action_root.join('setup')
21
+ autoload :Shutdown, action_root.join('shutdown')
22
+ autoload :WaitUntilUP, action_root.join('wait_until_up')
23
+
24
+ def self.action_boot
25
+ Vagrant::Action::Builder.new.tap do |b|
26
+ b.use CreateBridge
27
+ b.use CreateTap
28
+ b.use Load
29
+ b.use Boot
30
+ b.use Call, WaitUntilUP do |env, b1|
31
+ if env[:uncleaned]
32
+ b1.use action_reload
33
+ else
34
+ b1.use ForwardPorts
35
+ end
36
+ end
37
+ b.use PrepareNFSValidIds
38
+ b.use SyncedFolderCleanup
39
+ b.use SyncedFolders
40
+ b.use PrepareNFSSettings
41
+ end
42
+ end
43
+
44
+ def self.action_halt
45
+ Vagrant::Action::Builder.new.tap do |b|
46
+ b.use ConfigValidate
47
+ b.use Call, IsState, :running do |env, b1|
48
+ if env[:result]
49
+ b1.use Call, GracefulHalt, :uncleaned, :running do |env1, b2|
50
+ if !env1[:result]
51
+ b3.use Shutdown
52
+ end
53
+ end
54
+ end
55
+ end
56
+ b.use Call, IsState, :uncleaned do |env, b1|
57
+ if env[:result]
58
+ b1.use Cleanup
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def self.action_reload
65
+ Vagrant::Action::Builder.new.tap do |b|
66
+ b.use Message, I18n.t('vagrant_bhyve.action.vm.reload.reloading')
67
+ b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, b1|
68
+ if env[:result]
69
+ b1.use Message, I18n.t('vagrant_bhyve.commands.common.vm_not_created')
70
+ next
71
+ end
72
+ b1.use Call, IsState, :stopped do |env1, b2|
73
+ if !env1[:result]
74
+ b2.use action_halt
75
+ end
76
+ end
77
+ b1.use ConfigValidate
78
+ b1.use action_start
79
+ end
80
+ end
81
+ end
82
+
83
+ def self.action_ssh
84
+ Vagrant::Action::Builder.new.tap do |b|
85
+ b.use ConfigValidate
86
+ b.use Call, IsState, :running do |env, b1|
87
+ if !env[:result]
88
+ b1.use Message, I18n.t('vagrant_bhyve.commands.common.vm_not_running')
89
+ next
90
+ end
91
+ b1.use SSHExec
92
+ end
93
+ end
94
+ end
95
+
96
+ def self.action_ssh_run
97
+ Vagrant::Action::Builder.new.tap do |b|
98
+ b.use ConfigValidate
99
+ b.use Call, IsState, :running do |env, b1|
100
+ if !env[:result]
101
+ b1.use Message, I18n.t('vagrant_bhyve.commands.common.vm_not_running')
102
+ next
103
+ end
104
+ b1.use SSHRun
105
+ end
106
+ end
107
+ end
108
+
109
+ def self.action_start
110
+ Vagrant::Action::Builder.new.tap do |b|
111
+ b.use ConfigValidate
112
+ b.use Call, IsState, :running do |env, b1|
113
+ if env[:result]
114
+ b1.use Message, I18n.t('vagrant_bhyve.commands.common.vm_already_running')
115
+ next
116
+ end
117
+ b1.use Call, IsState, :uncleaned do |env1, b2|
118
+ if env1[:result]
119
+ b2.use Cleanup
120
+ end
121
+ end
122
+ b1.use Setup
123
+ b1.use action_boot
124
+ end
125
+ end
126
+ end
127
+
128
+ def self.action_up
129
+ Vagrant::Action::Builder.new.tap do |b|
130
+ b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, b1|
131
+ if env[:result]
132
+ b1.use HandleBox
133
+ end
134
+ end
135
+
136
+ b.use ConfigValidate
137
+ b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env,b1|
138
+ if env[:result]
139
+ b1.use Import
140
+ b1.use Provision
141
+ end
142
+ end
143
+ b.use action_start
144
+ end
145
+ end
146
+
147
+ def self.action_destroy
148
+ Vagrant::Action::Builder.new.tap do |b|
149
+ b.use ConfigValidate
150
+ b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env, b1|
151
+ if env[:result]
152
+ b1.use Message, I18n.t('vagrant_bhyve.commands.common.vm_not_created')
153
+ next
154
+ end
155
+
156
+ b1.use Call, DestroyConfirm do |env1, b2|
157
+ if !env1[:result]
158
+ b2.use Message, I18n.t(
159
+ 'vagrant.commands.destroy.will_not_destroy',
160
+ name: env1[:machine].name)
161
+ next
162
+ end
163
+ b2.use Call, IsState, :running do |env2, b3|
164
+ if env2[:result]
165
+ b3.use action_halt
166
+ end
167
+ end
168
+ b2.use Call, IsState, :uncleaned do |env2, b3|
169
+ if env2[:result]
170
+ b3.use Cleanup
171
+ end
172
+ end
173
+ b2.use Destroy
174
+ b2.use ProvisionerCleanup
175
+ b2.use PrepareNFSValidIds
176
+ b2.use SyncedFolderCleanup
177
+ end
178
+ end
179
+ end
180
+ end
181
+
182
+ def self.action_provision
183
+ Vagrant::Action::Builder.new.tap do |b|
184
+ b.use ConfigValidate
185
+ b.use Call, IsState, Vagrant::MachineState::NOT_CREATED_ID do |env,b1|
186
+ if env[:result]
187
+ b1.use Message, I18n.t('vagrant_bhyve.commands.common.vm_not_created')
188
+ next
189
+ end
190
+ b1.use Call, IsState, :running do |env1, b2|
191
+ if !env1[:result]
192
+ b2.use Message, I18n.t('vagrant_bhyve.commands.common.vm_not_running')
193
+ next
194
+ end
195
+ b2.use Provision
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ def self.action_suspend
202
+ Vagrant::Action::Builder.new.tap do |b|
203
+ b.use Warn, I18n.t('vagrant_bhyve.actions.vm.suspend.not_supported')
204
+ end
205
+ end
206
+
207
+ def self.action_resume
208
+ Vagrant::Action::Builder.new.tap do |b|
209
+ b.use Warn, I18n.t('vagrant_bhyve.actions.vm.resume.not_supported')
210
+ end
211
+ end
212
+
213
+ end
214
+ end
215
+ end