vagrant-ovirt 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.
- data/.gitignore +20 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +219 -0
- data/Rakefile +7 -0
- data/example_box/Vagrantfile +22 -0
- data/example_box/metadata.json +4 -0
- data/example_box/ovirt.box +0 -0
- data/lib/vagrant-ovirt/action/connect_ovirt.rb +84 -0
- data/lib/vagrant-ovirt/action/create_network_interfaces.rb +96 -0
- data/lib/vagrant-ovirt/action/create_vm.rb +114 -0
- data/lib/vagrant-ovirt/action/destroy_vm.rb +25 -0
- data/lib/vagrant-ovirt/action/is_created.rb +18 -0
- data/lib/vagrant-ovirt/action/message_already_created.rb +16 -0
- data/lib/vagrant-ovirt/action/message_not_created.rb +16 -0
- data/lib/vagrant-ovirt/action/read_ssh_info.rb +68 -0
- data/lib/vagrant-ovirt/action/read_state.rb +37 -0
- data/lib/vagrant-ovirt/action/set_name_of_domain.rb +31 -0
- data/lib/vagrant-ovirt/action/start_vm.rb +37 -0
- data/lib/vagrant-ovirt/action/sync_folders.rb +58 -0
- data/lib/vagrant-ovirt/action/timed_provision.rb +21 -0
- data/lib/vagrant-ovirt/action/wait_till_up.rb +108 -0
- data/lib/vagrant-ovirt/action.rb +89 -0
- data/lib/vagrant-ovirt/config.rb +57 -0
- data/lib/vagrant-ovirt/errors.rb +61 -0
- data/lib/vagrant-ovirt/plugin.rb +74 -0
- data/lib/vagrant-ovirt/provider.rb +76 -0
- data/lib/vagrant-ovirt/util/collection.rb +21 -0
- data/lib/vagrant-ovirt/util/timer.rb +17 -0
- data/lib/vagrant-ovirt/util.rb +9 -0
- data/lib/vagrant-ovirt/version.rb +6 -0
- data/lib/vagrant-ovirt.rb +47 -0
- data/locales/en.yml +82 -0
- data/tools/prepare_redhat_for_box.sh +138 -0
- data/vagrant-ovirt.gemspec +23 -0
- metadata +128 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
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_ovirt::action::read_ssh_info")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_ssh_info] = read_ssh_info(
|
16
|
+
env[:ovirt_compute], env[:machine])
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_ssh_info(ovirt, machine)
|
22
|
+
return nil if machine.id.nil?
|
23
|
+
|
24
|
+
# Get config.
|
25
|
+
config = machine.provider_config
|
26
|
+
|
27
|
+
# Find the machine
|
28
|
+
server = ovirt.servers.get(machine.id.to_s)
|
29
|
+
|
30
|
+
if server.nil?
|
31
|
+
# The machine can't be found
|
32
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
33
|
+
machine.id = nil
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# oVirt doesn't provide a way how to find out IP of VM via API.
|
38
|
+
# IP command should return IP address of MAC defined as a shell
|
39
|
+
# variable.
|
40
|
+
# TODO place code for obtaining IP in one place.
|
41
|
+
first_interface = OVirtProvider::Util::Collection.find_matching(
|
42
|
+
server.interfaces, 'nic1')
|
43
|
+
ip_command = "MAC=#{first_interface.mac}; #{config.ip_command}"
|
44
|
+
|
45
|
+
for i in 1..3
|
46
|
+
# Get IP address via ip_command.
|
47
|
+
ip_address = %x{#{ip_command}}
|
48
|
+
break if ip_address != ''
|
49
|
+
sleep 2
|
50
|
+
end
|
51
|
+
if ip_address == nil or ip_address == ''
|
52
|
+
raise Errors::NoIpAddressError
|
53
|
+
end
|
54
|
+
|
55
|
+
# Return the info
|
56
|
+
# TODO: Some info should be configurable in Vagrantfile
|
57
|
+
return {
|
58
|
+
:host => ip_address.chomp!,
|
59
|
+
:port => 22,
|
60
|
+
:username => 'root',
|
61
|
+
:forward_agent => true,
|
62
|
+
:forward_x11 => true,
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
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_ovirt::action::read_state")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state_id] = read_state(env[:ovirt_compute], env[:machine])
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_state(ovirt, machine)
|
20
|
+
return :not_created if machine.id.nil?
|
21
|
+
|
22
|
+
# Find the machine
|
23
|
+
server = ovirt.servers.get(machine.id)
|
24
|
+
if server.nil? || [:"shutting-down", :terminated].include?(server.status.to_sym)
|
25
|
+
# The machine can't be found
|
26
|
+
@logger.info("Machine not found or terminated, assuming it got destroyed.")
|
27
|
+
machine.id = nil
|
28
|
+
return :not_created
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return the state
|
32
|
+
return server.status.to_sym
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OVirtProvider
|
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 = OVirtProvider::Util::Collection.find_matching(
|
18
|
+
env[:ovirt_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,37 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
5
|
+
module Action
|
6
|
+
|
7
|
+
# Just start the VM.
|
8
|
+
class StartVM
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@logger = Log4r::Logger.new("vagrant_ovirt::action::start_vm")
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:ui].info(I18n.t("vagrant_ovirt.starting_vm"))
|
17
|
+
|
18
|
+
machine = env[:ovirt_compute].servers.get(env[:machine].id.to_s)
|
19
|
+
if machine == nil
|
20
|
+
raise Errors::NoVMError,
|
21
|
+
:vm_name => env[:machine].id.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
# Start VM.
|
25
|
+
begin
|
26
|
+
machine.start
|
27
|
+
rescue OVIRT::OvirtException => e
|
28
|
+
raise Errors::StartVMError,
|
29
|
+
:error_message => e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
@app.call(env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "vagrant/util/subprocess"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module OVirtProvider
|
6
|
+
module Action
|
7
|
+
# This middleware uses `rsync` to sync the folders over to the
|
8
|
+
# oVirt VM.
|
9
|
+
class SyncFolders
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_ovirt::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_ovirt.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-ovirt/util/timer"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
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,108 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'vagrant-ovirt/util/timer'
|
3
|
+
require 'vagrant/util/retryable'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module OVirtProvider
|
7
|
+
module Action
|
8
|
+
|
9
|
+
# Wait till VM 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_ovirt::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 config.
|
24
|
+
config = env[:machine].provider_config
|
25
|
+
|
26
|
+
# Get VM.
|
27
|
+
server = env[:ovirt_compute].servers.get(env[:machine].id.to_s)
|
28
|
+
if server == nil
|
29
|
+
raise NoVMError, :vm_name => ''
|
30
|
+
end
|
31
|
+
|
32
|
+
# oVirt doesn't provide a way how to find out IP of VM via API.
|
33
|
+
# IP command should return IP address of MAC defined as a shell
|
34
|
+
# variable.
|
35
|
+
first_interface = OVirtProvider::Util::Collection.find_matching(
|
36
|
+
server.interfaces, 'nic1')
|
37
|
+
ip_command = "MAC=#{first_interface.mac}; #{config.ip_command}"
|
38
|
+
|
39
|
+
# Wait for VM to obtain an ip address. Ip address is searched via
|
40
|
+
# custom configurable 'ip_command', or by default in local arp table.
|
41
|
+
env[:ip_address] = nil
|
42
|
+
env[:metrics]["instance_ip_time"] = Util::Timer.time do
|
43
|
+
env[:ui].info(I18n.t("vagrant_ovirt.waiting_for_ip"))
|
44
|
+
#retryable(:on => Fog::Errors::TimeoutError, :tries => 300) do
|
45
|
+
for i in 1..300
|
46
|
+
# If we're interrupted don't worry about waiting
|
47
|
+
next if env[:interrupted]
|
48
|
+
|
49
|
+
# Wait for VM to obtain an ip address.
|
50
|
+
@logger.debug("Executing command #{ip_command}")
|
51
|
+
env[:ip_address] = %x{#{ip_command}}
|
52
|
+
@logger.debug("Got output #{env[:ip_address]}")
|
53
|
+
break if env[:ip_address] != ''
|
54
|
+
sleep 2
|
55
|
+
end
|
56
|
+
#end
|
57
|
+
end
|
58
|
+
terminate(env) if env[:interrupted]
|
59
|
+
@logger.info("Got IP address #{env[:ip_address]}")
|
60
|
+
@logger.info("Time for getting IP: #{env[:metrics]["instance_ip_time"]}")
|
61
|
+
|
62
|
+
# Machine has ip address assigned, now wait till we are able to
|
63
|
+
# connect via ssh.
|
64
|
+
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
|
65
|
+
env[:ui].info(I18n.t("vagrant_ovirt.waiting_for_ssh"))
|
66
|
+
retryable(:on => Fog::Errors::TimeoutError, :tries => 60) do
|
67
|
+
# If we're interrupted don't worry about waiting
|
68
|
+
next if env[:interrupted]
|
69
|
+
|
70
|
+
# Wait till we are able to connect via ssh.
|
71
|
+
while true
|
72
|
+
# If we're interrupted then just back out
|
73
|
+
break if env[:interrupted]
|
74
|
+
break if env[:machine].communicate.ready?
|
75
|
+
sleep 2
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
terminate(env) if env[:interrupted]
|
80
|
+
@logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
|
81
|
+
|
82
|
+
# Booted and ready for use.
|
83
|
+
env[:ui].info(I18n.t("vagrant_ovirt.ready"))
|
84
|
+
|
85
|
+
@app.call(env)
|
86
|
+
end
|
87
|
+
|
88
|
+
def recover(env)
|
89
|
+
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
|
90
|
+
|
91
|
+
if env[:machine].provider.state.id != :not_created
|
92
|
+
# Undo the import
|
93
|
+
terminate(env)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def terminate(env)
|
98
|
+
destroy_env = env.dup
|
99
|
+
destroy_env.delete(:interrupted)
|
100
|
+
destroy_env[:config_validate] = false
|
101
|
+
destroy_env[:force_confirm_destroy] = true
|
102
|
+
env[:action_runner].run(Action.action_destroy, destroy_env)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'vagrant/action/builder'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
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 ConnectOVirt
|
14
|
+
b.use Call, IsCreated do |env, b2|
|
15
|
+
if env[:result]
|
16
|
+
b2.use MessageAlreadyCreated
|
17
|
+
next
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create and start VM if not yet created.
|
21
|
+
b2.use SetNameOfDomain
|
22
|
+
b2.use CreateVM
|
23
|
+
b2.use CreateNetworkInterfaces
|
24
|
+
|
25
|
+
b2.use TimedProvision
|
26
|
+
b2.use StartVM
|
27
|
+
b2.use WaitTillUp
|
28
|
+
b2.use SyncFolders
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# This is the action that is primarily responsible for completely
|
34
|
+
# freeing the resources of the underlying virtual machine.
|
35
|
+
def self.action_destroy
|
36
|
+
Vagrant::Action::Builder.new.tap do |b|
|
37
|
+
b.use ConfigValidate
|
38
|
+
b.use Call, IsCreated do |env, b2|
|
39
|
+
if !env[:result]
|
40
|
+
b2.use MessageNotCreated
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
b2.use ConnectOVirt
|
45
|
+
b2.use DestroyVM
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# This action is called to read the state of the machine. The resulting
|
51
|
+
# state is expected to be put into the `:machine_state_id` key.
|
52
|
+
def self.action_read_state
|
53
|
+
Vagrant::Action::Builder.new.tap do |b|
|
54
|
+
b.use ConfigValidate
|
55
|
+
b.use ConnectOVirt
|
56
|
+
b.use ReadState
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# This action is called to read the SSH info of the machine. The
|
61
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
62
|
+
# key.
|
63
|
+
def self.action_read_ssh_info
|
64
|
+
Vagrant::Action::Builder.new.tap do |b|
|
65
|
+
b.use ConfigValidate
|
66
|
+
b.use ConnectOVirt
|
67
|
+
b.use ReadSSHInfo
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
72
|
+
autoload :ConnectOVirt, action_root.join("connect_ovirt")
|
73
|
+
autoload :IsCreated, action_root.join("is_created")
|
74
|
+
autoload :SetNameOfDomain, action_root.join("set_name_of_domain")
|
75
|
+
autoload :CreateVM, action_root.join("create_vm")
|
76
|
+
autoload :CreateNetworkInterfaces, action_root.join("create_network_interfaces")
|
77
|
+
autoload :StartVM, action_root.join("start_vm")
|
78
|
+
autoload :MessageNotCreated, action_root.join("message_not_created")
|
79
|
+
autoload :DestroyVM, action_root.join("destroy_vm")
|
80
|
+
autoload :ReadState, action_root.join("read_state")
|
81
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
82
|
+
autoload :TimedProvision, action_root.join("timed_provision")
|
83
|
+
autoload :WaitTillUp, action_root.join("wait_till_up")
|
84
|
+
autoload :SyncFolders, action_root.join("sync_folders")
|
85
|
+
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
5
|
+
class Config < Vagrant.plugin('2', :config)
|
6
|
+
|
7
|
+
attr_accessor :url
|
8
|
+
attr_accessor :username
|
9
|
+
attr_accessor :password
|
10
|
+
attr_accessor :datacenter
|
11
|
+
attr_accessor :cluster
|
12
|
+
attr_accessor :ip_command
|
13
|
+
|
14
|
+
# Domain specific settings used while creating new machine.
|
15
|
+
attr_accessor :memory
|
16
|
+
attr_accessor :cpus
|
17
|
+
attr_accessor :template
|
18
|
+
attr_accessor :quota
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@url = UNSET_VALUE
|
22
|
+
@username = UNSET_VALUE
|
23
|
+
@password = UNSET_VALUE
|
24
|
+
@datacenter = UNSET_VALUE
|
25
|
+
@cluster = UNSET_VALUE
|
26
|
+
@ip_command = UNSET_VALUE
|
27
|
+
|
28
|
+
# Domain specific settings.
|
29
|
+
@memory = UNSET_VALUE
|
30
|
+
@cpus = UNSET_VALUE
|
31
|
+
@template = UNSET_VALUE
|
32
|
+
@quota = UNSET_VALUE
|
33
|
+
end
|
34
|
+
|
35
|
+
def finalize!
|
36
|
+
@url = nil if @url == UNSET_VALUE
|
37
|
+
@username = nil if @username == UNSET_VALUE
|
38
|
+
@password = nil if @password == UNSET_VALUE
|
39
|
+
@datacenter = nil if @datacenter == UNSET_VALUE
|
40
|
+
@cluster = nil if @cluster == UNSET_VALUE
|
41
|
+
if @ip_command == UNSET_VALUE
|
42
|
+
@ip_command = 'arp -an | grep -i $MAC | sed "s/.*(\(.*\)).*/\1/"'
|
43
|
+
end
|
44
|
+
|
45
|
+
# Domain specific settings.
|
46
|
+
@memory = 512 if @memory == UNSET_VALUE
|
47
|
+
@cpus = 1 if @cpus == UNSET_VALUE
|
48
|
+
@template = 'Blank' if @template == UNSET_VALUE
|
49
|
+
@quota = nil if @quota == UNSET_VALUE
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate(machine)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
5
|
+
module Errors
|
6
|
+
class VagrantOVirtError < Vagrant::Errors::VagrantError
|
7
|
+
error_namespace("vagrant_ovirt.errors")
|
8
|
+
end
|
9
|
+
|
10
|
+
class FogOVirtConnectionError < VagrantOVirtError
|
11
|
+
error_key(:fog_ovirt_connection_error)
|
12
|
+
end
|
13
|
+
|
14
|
+
class NoDatacenterError < VagrantOVirtError
|
15
|
+
error_key(:no_datacenter_error)
|
16
|
+
end
|
17
|
+
|
18
|
+
class NoClusterError < VagrantOVirtError
|
19
|
+
error_key(:no_cluster_error)
|
20
|
+
end
|
21
|
+
|
22
|
+
class NoTemplateError < VagrantOVirtError
|
23
|
+
error_key(:no_template_error)
|
24
|
+
end
|
25
|
+
|
26
|
+
class NoQuotaError < VagrantOVirtError
|
27
|
+
error_key(:no_template_error)
|
28
|
+
end
|
29
|
+
|
30
|
+
class FogCreateServerError < VagrantOVirtError
|
31
|
+
error_key(:fog_create_server_error)
|
32
|
+
end
|
33
|
+
|
34
|
+
class InterfaceSlotNotAvailable < VagrantOVirtError
|
35
|
+
error_key(:interface_slot_not_available)
|
36
|
+
end
|
37
|
+
|
38
|
+
class AddInterfaceError < VagrantOVirtError
|
39
|
+
error_key(:add_interface_error)
|
40
|
+
end
|
41
|
+
|
42
|
+
class NoVMError < VagrantOVirtError
|
43
|
+
error_key(:no_vm_error)
|
44
|
+
end
|
45
|
+
|
46
|
+
class StartVMError < VagrantOVirtError
|
47
|
+
error_key(:start_vm_error)
|
48
|
+
end
|
49
|
+
|
50
|
+
class NoIpAddressError < VagrantOVirtError
|
51
|
+
error_key(:no_ip_address_error)
|
52
|
+
end
|
53
|
+
|
54
|
+
class NoNetworkError < VagrantOVirtError
|
55
|
+
error_key(:no_network_error)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant oVirt 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 oVirt plugin is only compatible with Vagrant 1.1+"
|
12
|
+
end
|
13
|
+
|
14
|
+
module VagrantPlugins
|
15
|
+
module OVirtProvider
|
16
|
+
class Plugin < Vagrant.plugin('2')
|
17
|
+
name "ovirt"
|
18
|
+
description <<-DESC
|
19
|
+
Vagrant plugin to manage oVirt machines.
|
20
|
+
DESC
|
21
|
+
|
22
|
+
config("ovirt", :provider) do
|
23
|
+
require_relative "config"
|
24
|
+
Config
|
25
|
+
end
|
26
|
+
|
27
|
+
provider "ovirt" do
|
28
|
+
# Setup logging and i18n
|
29
|
+
setup_logging
|
30
|
+
setup_i18n
|
31
|
+
|
32
|
+
require_relative "provider"
|
33
|
+
Provider
|
34
|
+
end
|
35
|
+
|
36
|
+
# This initializes the internationalization strings.
|
37
|
+
def self.setup_i18n
|
38
|
+
I18n.load_path << File.expand_path("locales/en.yml",
|
39
|
+
OVirtProvider.source_root)
|
40
|
+
I18n.reload!
|
41
|
+
end
|
42
|
+
|
43
|
+
# This sets up our log level to be whatever VAGRANT_LOG is.
|
44
|
+
def self.setup_logging
|
45
|
+
require "log4r"
|
46
|
+
|
47
|
+
level = nil
|
48
|
+
begin
|
49
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
50
|
+
rescue NameError
|
51
|
+
# This means that the logging constant wasn't found,
|
52
|
+
# which is fine. We just keep `level` as `nil`. But
|
53
|
+
# we tell the user.
|
54
|
+
level = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# Some constants, such as "true" resolve to booleans, so the
|
58
|
+
# above error checking doesn't catch it. This will check to make
|
59
|
+
# sure that the log level is an integer, as Log4r requires.
|
60
|
+
level = nil if !level.is_a?(Integer)
|
61
|
+
|
62
|
+
# Set the logging level on all "vagrant" namespaced
|
63
|
+
# logs as long as we have a valid level.
|
64
|
+
if level
|
65
|
+
logger = Log4r::Logger.new("vagrant_ovirt")
|
66
|
+
logger.outputters = Log4r::Outputter.stderr
|
67
|
+
logger.level = level
|
68
|
+
logger = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|