vagrant-kvm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +10 -0
- data/LICENSE +8 -0
- data/README.md +90 -0
- data/Rakefile +15 -0
- data/example_box/README.md +18 -0
- data/example_box/box.xml +78 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-kvm.rb +20 -0
- data/lib/vagrant-kvm/action.rb +268 -0
- data/lib/vagrant-kvm/action/boot.rb +22 -0
- data/lib/vagrant-kvm/action/check_box.rb +36 -0
- data/lib/vagrant-kvm/action/check_created.rb +21 -0
- data/lib/vagrant-kvm/action/check_kvm.rb +23 -0
- data/lib/vagrant-kvm/action/check_running.rb +21 -0
- data/lib/vagrant-kvm/action/created.rb +20 -0
- data/lib/vagrant-kvm/action/destroy.rb +19 -0
- data/lib/vagrant-kvm/action/destroy_confirm.rb +17 -0
- data/lib/vagrant-kvm/action/export.rb +57 -0
- data/lib/vagrant-kvm/action/forced_halt.rb +21 -0
- data/lib/vagrant-kvm/action/import.rb +54 -0
- data/lib/vagrant-kvm/action/init_storage_pool.rb +19 -0
- data/lib/vagrant-kvm/action/is_paused.rb +20 -0
- data/lib/vagrant-kvm/action/is_running.rb +20 -0
- data/lib/vagrant-kvm/action/is_saved.rb +20 -0
- data/lib/vagrant-kvm/action/match_mac_address.rb +21 -0
- data/lib/vagrant-kvm/action/message_not_created.rb +16 -0
- data/lib/vagrant-kvm/action/message_will_not_destroy.rb +17 -0
- data/lib/vagrant-kvm/action/network.rb +69 -0
- data/lib/vagrant-kvm/action/package.rb +20 -0
- data/lib/vagrant-kvm/action/package_vagrantfile.rb +31 -0
- data/lib/vagrant-kvm/action/prepare_nfs_settings.rb +61 -0
- data/lib/vagrant-kvm/action/prune_nfs_exports.rb +20 -0
- data/lib/vagrant-kvm/action/resume.rb +25 -0
- data/lib/vagrant-kvm/action/setup_package_files.rb +51 -0
- data/lib/vagrant-kvm/action/share_folders.rb +76 -0
- data/lib/vagrant-kvm/action/suspend.rb +20 -0
- data/lib/vagrant-kvm/config.rb +31 -0
- data/lib/vagrant-kvm/driver/driver.rb +271 -0
- data/lib/vagrant-kvm/errors.rb +11 -0
- data/lib/vagrant-kvm/plugin.rb +73 -0
- data/lib/vagrant-kvm/provider.rb +104 -0
- data/lib/vagrant-kvm/util.rb +12 -0
- data/lib/vagrant-kvm/util/kvm_template_renderer.rb +20 -0
- data/lib/vagrant-kvm/util/network_definition.rb +106 -0
- data/lib/vagrant-kvm/util/vm_definition.rb +192 -0
- data/lib/vagrant-kvm/version.rb +5 -0
- data/locales/en.yml +4 -0
- data/templates/libvirt_domain.erb +64 -0
- data/vagrant-kvm.gemspec +58 -0
- metadata +191 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class Boot
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@env = env
|
11
|
+
|
12
|
+
# Start up the VM
|
13
|
+
env[:ui].info I18n.t("vagrant.actions.vm.boot.booting")
|
14
|
+
env[:machine].provider.driver.start
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class CheckBox
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
box_name = env[:machine].config.vm.box
|
11
|
+
raise Vagrant::Errors::BoxNotSpecified if !box_name
|
12
|
+
|
13
|
+
if !env[:box_collection].find(box_name, :kvm)
|
14
|
+
box_url = env[:machine].config.vm.box_url
|
15
|
+
raise Vagrant::Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url
|
16
|
+
|
17
|
+
# Add the box then reload the box collection so that it becomes
|
18
|
+
# aware of it.
|
19
|
+
env[:ui].info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
|
20
|
+
env[:action_runner].run(Vagrant::Action.action_box_add, {
|
21
|
+
:box_name => box_name,
|
22
|
+
:box_provider => env[:machine].provider_name,
|
23
|
+
:box_url => box_url
|
24
|
+
})
|
25
|
+
|
26
|
+
# Reload the environment and set the VM to be the new loaded VM.
|
27
|
+
env[:machine] = env[:machine].env.machine(
|
28
|
+
env[:machine].name, env[:machine].provider_name, true)
|
29
|
+
end
|
30
|
+
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
# This middleware checks that the VM is created, and raises an exception
|
5
|
+
# if it is not, notifying the user that creation is required.
|
6
|
+
class CheckCreated
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env[:machine].state.id == :not_created
|
13
|
+
raise Vagrant::Errors::VMNotCreatedError
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
# Checks that the libvirt/kvm/qemu environment is ready to be used.
|
5
|
+
class CheckKvm
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
# This verifies that kvm/qemu is installed, the environment is
|
12
|
+
# set-up and the driver is ready to function. If not, then an
|
13
|
+
# exception will be raised which will break us out of execution
|
14
|
+
# of the middleware sequence.
|
15
|
+
Driver::Driver.new.verify!
|
16
|
+
|
17
|
+
# Carry on.
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
# This middleware checks that the VM is running, and raises an exception
|
5
|
+
# if it is not, notifying the user that the VM must be running.
|
6
|
+
class CheckRunning
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env[:machine].state.id != :running
|
13
|
+
raise Vagrant::Errors::VMNotRunningError
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class Created
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Set the result to be true if the machine is created.
|
11
|
+
env[:result] = env[:machine].state.id != :not_created
|
12
|
+
|
13
|
+
# Call the next if we have one (but we shouldn't, since this
|
14
|
+
# middleware is built to run with the Call-type middlewares)
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class Destroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
|
11
|
+
env[:machine].provider.driver.delete
|
12
|
+
env[:machine].id = nil
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "vagrant/action/builtin/confirm"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderKvm
|
5
|
+
module Action
|
6
|
+
class DestroyConfirm < Vagrant::Action::Builtin::Confirm
|
7
|
+
def initialize(app, env)
|
8
|
+
force_key = :force_confirm_destroy
|
9
|
+
message = I18n.t("vagrant.commands.destroy.confirmation",
|
10
|
+
:name => env[:machine].name)
|
11
|
+
|
12
|
+
super(app, env, message, force_key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderKvm
|
5
|
+
module Action
|
6
|
+
class Export
|
7
|
+
attr_reader :temp_dir
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
@env = env
|
15
|
+
|
16
|
+
raise Vagrant::Errors::VMPowerOffToPackage if \
|
17
|
+
@env[:machine].provider.state.id != :poweroff
|
18
|
+
|
19
|
+
setup_temp_dir
|
20
|
+
export
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
|
24
|
+
recover(env) # called to cleanup temp directory
|
25
|
+
end
|
26
|
+
|
27
|
+
def recover(env)
|
28
|
+
if temp_dir && File.exist?(temp_dir)
|
29
|
+
FileUtils.rm_rf(temp_dir)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_temp_dir
|
34
|
+
@env[:ui].info I18n.t("vagrant.actions.vm.export.create_dir")
|
35
|
+
@temp_dir = @env["export.temp_dir"] = @env[:tmp_path].join(Time.now.to_i.to_s)
|
36
|
+
FileUtils.mkpath(@env["export.temp_dir"])
|
37
|
+
end
|
38
|
+
|
39
|
+
def export
|
40
|
+
@env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
|
41
|
+
@env[:machine].provider.driver.export(xml_path) do |progress|
|
42
|
+
@env[:ui].clear_line
|
43
|
+
@env[:ui].report_progress(progress.percent, 100, false)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Clear the line a final time so the next data can appear
|
47
|
+
# alone on the line.
|
48
|
+
@env[:ui].clear_line
|
49
|
+
end
|
50
|
+
|
51
|
+
def xml_path
|
52
|
+
File.join(@env["export.temp_dir"], "box.xml")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class ForcedHalt
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
current_state = env[:machine].state.id
|
11
|
+
if current_state == :running
|
12
|
+
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
|
13
|
+
env[:machine].provider.driver.halt
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class Import
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
|
11
|
+
:name => env[:machine].box.name)
|
12
|
+
|
13
|
+
# Import the virtual machine (ovf or libvirt)
|
14
|
+
# if a libvirt XML definition is present we use it
|
15
|
+
# otherwise we convert the OVF
|
16
|
+
storage_path = File.join(env[:tmp_path],"/storage-pool")
|
17
|
+
box_file = env[:machine].box.directory.join("box.xml").to_s
|
18
|
+
if File.file?(box_file)
|
19
|
+
env[:machine].id = env[:machine].provider.driver.import(
|
20
|
+
box_file, storage_path)
|
21
|
+
else
|
22
|
+
box_file = env[:machine].box.directory.join("box.ovf").to_s
|
23
|
+
env[:machine].id = env[:machine].provider.driver.import_ovf(
|
24
|
+
box_file, storage_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
# If we got interrupted, then the import could have been
|
28
|
+
# interrupted and its not a big deal. Just return out.
|
29
|
+
return if env[:interrupted]
|
30
|
+
|
31
|
+
# Flag as erroneous and return if import failed
|
32
|
+
raise Vagrant::Errors::VMImportFailure if !env[:machine].id
|
33
|
+
|
34
|
+
# Import completed successfully. Continue the chain
|
35
|
+
@app.call(env)
|
36
|
+
end
|
37
|
+
|
38
|
+
def recover(env)
|
39
|
+
if env[:machine].provider.state.id != :not_created
|
40
|
+
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
|
41
|
+
|
42
|
+
# Interrupted, destroy the VM. We note that we don't want to
|
43
|
+
# validate the configuration here, and we don't want to confirm
|
44
|
+
# we want to destroy.
|
45
|
+
destroy_env = env.clone
|
46
|
+
destroy_env[:config_validate] = false
|
47
|
+
destroy_env[:force_confirm_destroy] = true
|
48
|
+
env[:action_runner].run(Action.action_destroy, destroy_env)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
# Initialize storage pool.
|
5
|
+
class InitStoragePool
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
# Create a storage pool in tmp_path if it doesn't exist
|
12
|
+
Driver::Driver.new.init_storage(env[:tmp_path])
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class IsPaused
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Set the result to be true if the machine is paused.
|
11
|
+
env[:result] = env[:machine].state.id == :paused
|
12
|
+
|
13
|
+
# Call the next if we have one (but we shouldn't, since this
|
14
|
+
# middleware is built to run with the Call-type middlewares)
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class IsRunning
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Set the result to be true if the machine is running.
|
11
|
+
env[:result] = env[:machine].state.id == :running
|
12
|
+
|
13
|
+
# Call the next if we have one (but we shouldn't, since this
|
14
|
+
# middleware is built to run with the Call-type middlewares)
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class IsSaved
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Set the result to be true if the machine is saved.
|
11
|
+
env[:result] = env[:machine].state.id == :saved
|
12
|
+
|
13
|
+
# Call the next if we have one (but we shouldn't, since this
|
14
|
+
# middleware is built to run with the Call-type middlewares)
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class MatchMACAddress
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
raise Vagrant::Errors::VMBaseMacNotSpecified if !env[:machine].config.vm.base_mac
|
11
|
+
|
12
|
+
# Create the proc which we want to use to modify the virtual machine
|
13
|
+
env[:ui].info I18n.t("vagrant.actions.vm.match_mac.matching")
|
14
|
+
env[:machine].provider.driver.set_mac_address(env[:machine].config.vm.base_mac)
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderKvm
|
3
|
+
module Action
|
4
|
+
class MessageNotCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|