vagrant-libvirt 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +7 -0
- data/example_box/README.md +14 -0
- data/example_box/Vagrantfile +45 -0
- data/example_box/metadata.json +5 -0
- data/lib/vagrant-libvirt/action/connect_libvirt.rb +72 -0
- data/lib/vagrant-libvirt/action/create_domain.rb +62 -0
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +58 -0
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +85 -0
- data/lib/vagrant-libvirt/action/destroy_domain.rb +28 -0
- data/lib/vagrant-libvirt/action/handle_box_image.rb +121 -0
- data/lib/vagrant-libvirt/action/handle_storage_pool.rb +49 -0
- data/lib/vagrant-libvirt/action/is_created.rb +18 -0
- data/lib/vagrant-libvirt/action/message_already_created.rb +16 -0
- data/lib/vagrant-libvirt/action/message_not_created.rb +16 -0
- data/lib/vagrant-libvirt/action/read_ssh_info.rb +51 -0
- data/lib/vagrant-libvirt/action/read_state.rb +38 -0
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +31 -0
- data/lib/vagrant-libvirt/action/start_domain.rb +27 -0
- data/lib/vagrant-libvirt/action/sync_folders.rb +58 -0
- data/lib/vagrant-libvirt/action/timed_provision.rb +21 -0
- data/lib/vagrant-libvirt/action/wait_till_up.rb +96 -0
- data/lib/vagrant-libvirt/action.rb +94 -0
- data/lib/vagrant-libvirt/config.rb +48 -0
- data/lib/vagrant-libvirt/errors.rb +90 -0
- data/lib/vagrant-libvirt/plugin.rb +77 -0
- data/lib/vagrant-libvirt/provider.rb +76 -0
- data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +13 -0
- data/lib/vagrant-libvirt/templates/domain.xml.erb +34 -0
- data/lib/vagrant-libvirt/templates/interface.xml.erb +7 -0
- data/lib/vagrant-libvirt/templates/volume_snapshot.xml.erb +26 -0
- data/lib/vagrant-libvirt/util/collection.rb +22 -0
- data/lib/vagrant-libvirt/util/erb_template.rb +21 -0
- data/lib/vagrant-libvirt/util/timer.rb +17 -0
- data/lib/vagrant-libvirt/util.rb +10 -0
- data/lib/vagrant-libvirt/version.rb +5 -0
- data/lib/vagrant-libvirt.rb +30 -0
- data/locales/en.yml +103 -0
- data/vagrant-libvirt.gemspec +23 -0
- metadata +127 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Libvirt
|
3
|
+
module Action
|
4
|
+
class MessageAlreadyCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_libvirt.already_created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Libvirt
|
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_libvirt.not_created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
module Action
|
6
|
+
# This action reads the SSH info for the machine and puts it into the
|
7
|
+
# `:machine_ssh_info` key in the environment.
|
8
|
+
class ReadSSHInfo
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_libvirt::action::read_ssh_info")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_ssh_info] = read_ssh_info(
|
16
|
+
env[:libvirt_compute], env[:machine])
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def read_ssh_info(libvirt, machine)
|
23
|
+
return nil if machine.id.nil?
|
24
|
+
|
25
|
+
# Find the machine
|
26
|
+
server = libvirt.servers.get(machine.id)
|
27
|
+
if server.nil?
|
28
|
+
# The machine can't be found
|
29
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
30
|
+
machine.id = nil
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get ip address of machine
|
35
|
+
ip_address = server.public_ip_address
|
36
|
+
ip_address = server.private_ip_address if ip_address == nil
|
37
|
+
return nil if ip_address == nil
|
38
|
+
|
39
|
+
# Return the info
|
40
|
+
# TODO: Some info should be configurable in Vagrantfile
|
41
|
+
return {
|
42
|
+
:host => ip_address,
|
43
|
+
:port => 22,
|
44
|
+
:username => 'root',
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
module Action
|
6
|
+
# This action reads the state of the machine and puts it in the
|
7
|
+
# `:machine_state_id` key in the environment.
|
8
|
+
class ReadState
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_libvirt::action::read_state")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state_id] = read_state(env[:libvirt_compute], env[:machine])
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_state(libvirt, machine)
|
21
|
+
return :not_created if machine.id.nil?
|
22
|
+
|
23
|
+
# Find the machine
|
24
|
+
server = libvirt.servers.get(machine.id)
|
25
|
+
if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
|
26
|
+
# The machine can't be found
|
27
|
+
@logger.info("Machine not found or terminated, assuming it got destroyed.")
|
28
|
+
machine.id = nil
|
29
|
+
return :not_created
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return the state
|
33
|
+
return server.state.to_sym
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Libvirt
|
3
|
+
module Action
|
4
|
+
|
5
|
+
# Setup name for domain and domain volumes.
|
6
|
+
class SetNameOfDomain
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:domain_name] = env[:root_path].basename.to_s.dup
|
13
|
+
env[:domain_name].gsub!(/[^-a-z0-9_]/i, "")
|
14
|
+
env[:domain_name] << "_#{Time.now.to_i}"
|
15
|
+
|
16
|
+
# Check if the domain name is not already taken
|
17
|
+
domain = Libvirt::Util::Collection.find_matching(
|
18
|
+
env[:libvirt_compute].servers.all, env[:domain_name])
|
19
|
+
if domain != nil
|
20
|
+
raise Vagrant::Errors::DomainNameExists,
|
21
|
+
:domain_name => env[:domain_name]
|
22
|
+
end
|
23
|
+
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
module Action
|
6
|
+
|
7
|
+
# Just start the domain.
|
8
|
+
class StartDomain
|
9
|
+
def initialize(app, env)
|
10
|
+
@logger = Log4r::Logger.new("vagrant_libvirt::action::start_domain")
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:ui].info(I18n.t("vagrant_libvirt.starting_domain"))
|
16
|
+
|
17
|
+
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
|
18
|
+
raise Errors::NoDomainError if domain == nil
|
19
|
+
domain.start
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "vagrant/util/subprocess"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Libvirt
|
6
|
+
module Action
|
7
|
+
# This middleware uses `rsync` to sync the folders over to the
|
8
|
+
# libvirt domain.
|
9
|
+
class SyncFolders
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_libvirt::action::sync_folders")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
@app.call(env)
|
17
|
+
|
18
|
+
ssh_info = env[:machine].ssh_info
|
19
|
+
|
20
|
+
env[:machine].config.vm.synced_folders.each do |id, data|
|
21
|
+
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
22
|
+
guestpath = data[:guestpath]
|
23
|
+
|
24
|
+
# Make sure there is a trailing slash on the host path to
|
25
|
+
# avoid creating an additional directory with rsync
|
26
|
+
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
27
|
+
|
28
|
+
env[:ui].info(I18n.t("vagrant_libvirt.rsync_folder",
|
29
|
+
:hostpath => hostpath,
|
30
|
+
:guestpath => guestpath))
|
31
|
+
|
32
|
+
# Create the guest path
|
33
|
+
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
34
|
+
env[:machine].communicate.sudo(
|
35
|
+
"chown #{ssh_info[:username]} '#{guestpath}'")
|
36
|
+
|
37
|
+
# Rsync over to the guest path using the SSH info
|
38
|
+
command = [
|
39
|
+
"rsync", "--verbose", "--archive", "-z",
|
40
|
+
"--exclude", ".vagrant/",
|
41
|
+
"-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i '#{ssh_info[:private_key_path]}'",
|
42
|
+
hostpath,
|
43
|
+
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
44
|
+
|
45
|
+
r = Vagrant::Util::Subprocess.execute(*command)
|
46
|
+
if r.exit_code != 0
|
47
|
+
raise Errors::RsyncError,
|
48
|
+
:guestpath => guestpath,
|
49
|
+
:hostpath => hostpath,
|
50
|
+
:stderr => r.stderr
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "vagrant-libvirt/util/timer"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
module Action
|
6
|
+
# This is the same as the builtin provision except it times the
|
7
|
+
# provisioner runs.
|
8
|
+
class TimedProvision < Vagrant::Action::Builtin::Provision
|
9
|
+
def run_provisioner(env, p)
|
10
|
+
timer = Util::Timer.time do
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
env[:metrics] ||= {}
|
15
|
+
env[:metrics]["provisioner_times"] ||= []
|
16
|
+
env[:metrics]["provisioner_times"] << [p.class.to_s, timer]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'vagrant-libvirt/util/timer'
|
3
|
+
require 'vagrant/util/retryable'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Libvirt
|
7
|
+
module Action
|
8
|
+
|
9
|
+
# Wait till domain is started, till it obtains an IP address and is
|
10
|
+
# accessible via ssh.
|
11
|
+
class WaitTillUp
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, env)
|
15
|
+
@logger = Log4r::Logger.new("vagrant_libvirt::action::wait_till_up")
|
16
|
+
@app = app
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
# Initialize metrics if they haven't been
|
21
|
+
env[:metrics] ||= {}
|
22
|
+
|
23
|
+
# Get domain object
|
24
|
+
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
|
25
|
+
raise NoDomainError if domain == nil
|
26
|
+
|
27
|
+
# Wait for domain to obtain an ip address. Ip address is searched
|
28
|
+
# from arp table, either localy or remotely via ssh, if libvirt
|
29
|
+
# connection was done via ssh.
|
30
|
+
env[:ip_address] = nil
|
31
|
+
env[:metrics]["instance_ip_time"] = Util::Timer.time do
|
32
|
+
env[:ui].info(I18n.t("vagrant_libvirt.waiting_for_ip"))
|
33
|
+
retryable(:on => Fog::Errors::TimeoutError, :tries => 300) do
|
34
|
+
# If we're interrupted don't worry about waiting
|
35
|
+
next if env[:interrupted]
|
36
|
+
|
37
|
+
# Wait for domain to obtain an ip address
|
38
|
+
domain.wait_for(2) {
|
39
|
+
addresses.each_pair do |type, ip|
|
40
|
+
env[:ip_address] = ip[0]
|
41
|
+
end
|
42
|
+
env[:ip_address] != nil
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
terminate(env) if env[:interrupted]
|
47
|
+
@logger.info("Got IP address #{env[:ip_address]}")
|
48
|
+
@logger.info("Time for getting IP: #{env[:metrics]["instance_ip_time"]}")
|
49
|
+
|
50
|
+
# Machine has ip address assigned, now wait till we are able to
|
51
|
+
# connect via ssh.
|
52
|
+
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
|
53
|
+
env[:ui].info(I18n.t("vagrant_libvirt.waiting_for_ssh"))
|
54
|
+
retryable(:on => Fog::Errors::TimeoutError, :tries => 60) do
|
55
|
+
# If we're interrupted don't worry about waiting
|
56
|
+
next if env[:interrupted]
|
57
|
+
|
58
|
+
# Wait till we are able to connect via ssh.
|
59
|
+
while true
|
60
|
+
# If we're interrupted then just back out
|
61
|
+
break if env[:interrupted]
|
62
|
+
break if env[:machine].communicate.ready?
|
63
|
+
sleep 2
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
terminate(env) if env[:interrupted]
|
68
|
+
@logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
|
69
|
+
|
70
|
+
# Booted and ready for use.
|
71
|
+
#env[:ui].info(I18n.t("vagrant_libvirt.ready"))
|
72
|
+
|
73
|
+
@app.call(env)
|
74
|
+
end
|
75
|
+
|
76
|
+
def recover(env)
|
77
|
+
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
|
78
|
+
|
79
|
+
if env[:machine].provider.state.id != :not_created
|
80
|
+
# Undo the import
|
81
|
+
terminate(env)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def terminate(env)
|
86
|
+
destroy_env = env.dup
|
87
|
+
destroy_env.delete(:interrupted)
|
88
|
+
destroy_env[:config_validate] = false
|
89
|
+
destroy_env[:force_confirm_destroy] = true
|
90
|
+
env[:action_runner].run(Action.action_destroy, destroy_env)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'vagrant/action/builder'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
module Action
|
6
|
+
# Include the built-in modules so we can use them as top-level things.
|
7
|
+
include Vagrant::Action::Builtin
|
8
|
+
|
9
|
+
# This action is called to bring the box up from nothing.
|
10
|
+
def self.action_up
|
11
|
+
Vagrant::Action::Builder.new.tap do |b|
|
12
|
+
b.use ConfigValidate
|
13
|
+
b.use ConnectLibvirt
|
14
|
+
b.use Call, IsCreated do |env, b2|
|
15
|
+
if env[:result]
|
16
|
+
b2.use MessageAlreadyCreated
|
17
|
+
next
|
18
|
+
end
|
19
|
+
|
20
|
+
b2.use SetNameOfDomain
|
21
|
+
b2.use HandleStoragePool
|
22
|
+
b2.use HandleBoxImage
|
23
|
+
b2.use CreateDomainVolume
|
24
|
+
b2.use CreateDomain
|
25
|
+
b2.use CreateNetworkInterfaces
|
26
|
+
end
|
27
|
+
|
28
|
+
b.use TimedProvision
|
29
|
+
b.use StartDomain
|
30
|
+
b.use WaitTillUp
|
31
|
+
b.use SyncFolders
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# This is the action that is primarily responsible for completely
|
36
|
+
# freeing the resources of the underlying virtual machine.
|
37
|
+
def self.action_destroy
|
38
|
+
Vagrant::Action::Builder.new.tap do |b|
|
39
|
+
b.use ConfigValidate
|
40
|
+
b.use Call, IsCreated do |env, b2|
|
41
|
+
if !env[:result]
|
42
|
+
b2.use MessageNotCreated
|
43
|
+
next
|
44
|
+
end
|
45
|
+
|
46
|
+
b2.use ConnectLibvirt
|
47
|
+
b2.use DestroyDomain
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# This action is called to read the state of the machine. The resulting
|
53
|
+
# state is expected to be put into the `:machine_state_id` key.
|
54
|
+
def self.action_read_state
|
55
|
+
Vagrant::Action::Builder.new.tap do |b|
|
56
|
+
b.use ConfigValidate
|
57
|
+
b.use ConnectLibvirt
|
58
|
+
b.use ReadState
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# This action is called to read the SSH info of the machine. The
|
63
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
64
|
+
# key.
|
65
|
+
def self.action_read_ssh_info
|
66
|
+
Vagrant::Action::Builder.new.tap do |b|
|
67
|
+
b.use ConfigValidate
|
68
|
+
b.use ConnectLibvirt
|
69
|
+
b.use ReadSSHInfo
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
74
|
+
autoload :ConnectLibvirt, action_root.join("connect_libvirt")
|
75
|
+
autoload :IsCreated, action_root.join("is_created")
|
76
|
+
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
77
|
+
autoload :MessageNotCreated, action_root.join("message_not_created")
|
78
|
+
autoload :HandleStoragePool, action_root.join("handle_storage_pool")
|
79
|
+
autoload :HandleBoxImage, action_root.join("handle_box_image")
|
80
|
+
autoload :SetNameOfDomain, action_root.join("set_name_of_domain")
|
81
|
+
autoload :CreateDomainVolume, action_root.join("create_domain_volume")
|
82
|
+
autoload :CreateDomain, action_root.join("create_domain")
|
83
|
+
autoload :CreateNetworkInterfaces, action_root.join("create_network_interfaces")
|
84
|
+
autoload :DestroyDomain, action_root.join("destroy_domain")
|
85
|
+
autoload :StartDomain, action_root.join("start_domain")
|
86
|
+
autoload :ReadState, action_root.join("read_state")
|
87
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
88
|
+
autoload :TimedProvision, action_root.join("timed_provision")
|
89
|
+
autoload :WaitTillUp, action_root.join("wait_till_up")
|
90
|
+
autoload :SyncFolders, action_root.join("sync_folders")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
class Config < Vagrant.plugin('2', :config)
|
6
|
+
# A hypervisor name to access via Libvirt.
|
7
|
+
attr_accessor :driver
|
8
|
+
|
9
|
+
# The name of the server, where libvirtd is running.
|
10
|
+
attr_accessor :host
|
11
|
+
|
12
|
+
# If use ssh tunnel to connect to Libvirt.
|
13
|
+
attr_accessor :connect_via_ssh
|
14
|
+
|
15
|
+
# The username to access Libvirt.
|
16
|
+
attr_accessor :username
|
17
|
+
|
18
|
+
# Password for Libvirt connection.
|
19
|
+
attr_accessor :password
|
20
|
+
|
21
|
+
# Libvirt storage pool name, where box image and instance snapshots will
|
22
|
+
# be stored.
|
23
|
+
attr_accessor :storage_pool_name
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@driver = UNSET_VALUE
|
27
|
+
@host = UNSET_VALUE
|
28
|
+
@connect_via_ssh = UNSET_VALUE
|
29
|
+
@username = UNSET_VALUE
|
30
|
+
@password = UNSET_VALUE
|
31
|
+
@storage_pool_name = UNSET_VALUE
|
32
|
+
end
|
33
|
+
|
34
|
+
def finalize!
|
35
|
+
@driver = 'qemu' if @driver == UNSET_VALUE
|
36
|
+
@host = nil if @host == UNSET_VALUE
|
37
|
+
@connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE
|
38
|
+
@username = nil if @username == UNSET_VALUE
|
39
|
+
@password = nil if @password == UNSET_VALUE
|
40
|
+
@storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate(machine)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Libvirt
|
5
|
+
module Errors
|
6
|
+
class VagrantLibvirtError < Vagrant::Errors::VagrantError
|
7
|
+
error_namespace("vagrant_libvirt.errors")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Storage pools and volumes exceptions
|
11
|
+
class NoStoragePool < VagrantLibvirtError
|
12
|
+
error_key(:no_storage_pool)
|
13
|
+
end
|
14
|
+
|
15
|
+
class DomainVolumeExists < VagrantLibvirtError
|
16
|
+
error_key(:domain_volume_exists)
|
17
|
+
end
|
18
|
+
|
19
|
+
class NoDomainVolume < VagrantLibvirtError
|
20
|
+
error_key(:no_domain_volume)
|
21
|
+
end
|
22
|
+
|
23
|
+
class CreatingStoragePoolError < VagrantLibvirtError
|
24
|
+
error_key(:creating_storage_pool_error)
|
25
|
+
end
|
26
|
+
|
27
|
+
class ImageUploadError < VagrantLibvirtError
|
28
|
+
error_key(:image_upload_error_error)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Box exceptions
|
33
|
+
class NoBoxVolume < VagrantLibvirtError
|
34
|
+
error_key(:no_box_volume)
|
35
|
+
end
|
36
|
+
|
37
|
+
class NoBoxVirtualSizeSet < VagrantLibvirtError
|
38
|
+
error_key(:no_box_virtual_size_error)
|
39
|
+
end
|
40
|
+
|
41
|
+
class NoBoxFormatSet < VagrantLibvirtError
|
42
|
+
error_key(:no_box_format_error)
|
43
|
+
end
|
44
|
+
|
45
|
+
class WrongBoxFormatSet < VagrantLibvirtError
|
46
|
+
error_key(:wrong_box_format_error)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Fog libvirt exceptions
|
51
|
+
class FogLibvirtConnectionError < VagrantLibvirtError
|
52
|
+
error_key(:fog_libvirt_connection_error)
|
53
|
+
end
|
54
|
+
|
55
|
+
class FogCreateVolumeError < VagrantLibvirtError
|
56
|
+
error_key(:fog_create_volume_error)
|
57
|
+
end
|
58
|
+
|
59
|
+
class FogCreateDomainVolumeError < VagrantLibvirtError
|
60
|
+
error_key(:fog_create_domain_volume_error)
|
61
|
+
end
|
62
|
+
|
63
|
+
class FogCreateServerError < VagrantLibvirtError
|
64
|
+
error_key(:fog_create_server_error)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Other exceptions
|
69
|
+
class InterfaceSlotNotAvailable < VagrantLibvirtError
|
70
|
+
error_key(:interface_slot_not_available)
|
71
|
+
end
|
72
|
+
|
73
|
+
class RsyncError < VagrantLibvirtError
|
74
|
+
error_key(:rsync_error)
|
75
|
+
end
|
76
|
+
|
77
|
+
class DomainNameExists < VagrantLibvirtError
|
78
|
+
error_key(:domain_name_exists_error)
|
79
|
+
end
|
80
|
+
|
81
|
+
class NoDomainError < VagrantLibvirtError
|
82
|
+
error_key(:no_domain_error)
|
83
|
+
end
|
84
|
+
|
85
|
+
class AttachDeviceError < VagrantLibvirtError
|
86
|
+
error_key(:attach_device_error)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant Libvirt plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
# This is a sanity check to make sure no one is attempting to install
|
9
|
+
# this into an early Vagrant version.
|
10
|
+
if Vagrant::VERSION < '1.1.0'
|
11
|
+
raise "The Vagrant Libvirt plugin is only compatible with Vagrant 1.1+"
|
12
|
+
end
|
13
|
+
|
14
|
+
module VagrantPlugins
|
15
|
+
module Libvirt
|
16
|
+
class Plugin < Vagrant.plugin('2')
|
17
|
+
name "libvirt"
|
18
|
+
description <<-DESC
|
19
|
+
Vagrant plugin to manage VMs in libvirt.
|
20
|
+
DESC
|
21
|
+
|
22
|
+
|
23
|
+
config("libvirt", :provider) do
|
24
|
+
require_relative "config"
|
25
|
+
Config
|
26
|
+
end
|
27
|
+
|
28
|
+
provider "libvirt" do
|
29
|
+
# Setup logging and i18n
|
30
|
+
setup_logging
|
31
|
+
setup_i18n
|
32
|
+
|
33
|
+
require_relative "provider"
|
34
|
+
Provider
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# This initializes the internationalization strings.
|
39
|
+
def self.setup_i18n
|
40
|
+
I18n.load_path << File.expand_path("locales/en.yml", Libvirt.source_root)
|
41
|
+
I18n.reload!
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# This sets up our log level to be whatever VAGRANT_LOG is.
|
46
|
+
def self.setup_logging
|
47
|
+
require "log4r"
|
48
|
+
|
49
|
+
level = nil
|
50
|
+
begin
|
51
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
52
|
+
rescue NameError
|
53
|
+
# This means that the logging constant wasn't found,
|
54
|
+
# which is fine. We just keep `level` as `nil`. But
|
55
|
+
# we tell the user.
|
56
|
+
level = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
# Some constants, such as "true" resolve to booleans, so the
|
60
|
+
# above error checking doesn't catch it. This will check to make
|
61
|
+
# sure that the log level is an integer, as Log4r requires.
|
62
|
+
level = nil if !level.is_a?(Integer)
|
63
|
+
|
64
|
+
# Set the logging level on all "vagrant" namespaced
|
65
|
+
# logs as long as we have a valid level.
|
66
|
+
if level
|
67
|
+
logger = Log4r::Logger.new("vagrant_libvirt")
|
68
|
+
logger.outputters = Log4r::Outputter.stderr
|
69
|
+
logger.level = level
|
70
|
+
logger = nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|