vagrant-ovirt3 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +211 -0
- data/Rakefile +7 -0
- data/example_box/README.md +13 -0
- data/example_box/Vagrantfile +18 -0
- data/example_box/dummy.box +0 -0
- data/example_box/metadata.json +4 -0
- data/lib/vagrant-ovirt3.rb +42 -0
- data/lib/vagrant-ovirt3/action.rb +131 -0
- data/lib/vagrant-ovirt3/action/connect_ovirt.rb +84 -0
- data/lib/vagrant-ovirt3/action/create_network_interfaces.rb +137 -0
- data/lib/vagrant-ovirt3/action/create_vm.rb +113 -0
- data/lib/vagrant-ovirt3/action/destroy_vm.rb +25 -0
- data/lib/vagrant-ovirt3/action/is_created.rb +18 -0
- data/lib/vagrant-ovirt3/action/message_already_created.rb +16 -0
- data/lib/vagrant-ovirt3/action/message_not_created.rb +16 -0
- data/lib/vagrant-ovirt3/action/read_ssh_info.rb +56 -0
- data/lib/vagrant-ovirt3/action/read_state.rb +37 -0
- data/lib/vagrant-ovirt3/action/resize_disk.rb +71 -0
- data/lib/vagrant-ovirt3/action/set_name_of_domain.rb +31 -0
- data/lib/vagrant-ovirt3/action/start_vm.rb +37 -0
- data/lib/vagrant-ovirt3/action/sync_folders.rb +65 -0
- data/lib/vagrant-ovirt3/action/wait_till_up.rb +94 -0
- data/lib/vagrant-ovirt3/config.rb +58 -0
- data/lib/vagrant-ovirt3/errors.rb +76 -0
- data/lib/vagrant-ovirt3/plugin.rb +74 -0
- data/lib/vagrant-ovirt3/provider.rb +76 -0
- data/lib/vagrant-ovirt3/util.rb +9 -0
- data/lib/vagrant-ovirt3/util/collection.rb +21 -0
- data/lib/vagrant-ovirt3/util/timer.rb +17 -0
- data/lib/vagrant-ovirt3/version.rb +6 -0
- data/locales/en.yml +90 -0
- data/tools/prepare_redhat_for_box.sh +132 -0
- data/vagrant-ovirt3.gemspec +25 -0
- metadata +129 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant oVirt v3 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 v3 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 "ovirt3"
|
18
|
+
description <<-DESC
|
19
|
+
Vagrant plugin to manage oVirt v3 machines.
|
20
|
+
DESC
|
21
|
+
|
22
|
+
config("ovirt3", :provider) do
|
23
|
+
require_relative "config"
|
24
|
+
Config
|
25
|
+
end
|
26
|
+
|
27
|
+
provider "ovirt3" 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_ovirt3")
|
66
|
+
logger.outputters = Log4r::Outputter.stderr
|
67
|
+
logger.level = level
|
68
|
+
logger = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OVirtProvider
|
5
|
+
|
6
|
+
# This is the base class for a provider for the V2 API. A provider
|
7
|
+
# is responsible for creating compute resources to match the
|
8
|
+
# needs of a Vagrant-configured system.
|
9
|
+
class Provider < Vagrant.plugin('2', :provider)
|
10
|
+
def initialize(machine)
|
11
|
+
@machine = machine
|
12
|
+
end
|
13
|
+
|
14
|
+
# This should return an action callable for the given name.
|
15
|
+
def action(name)
|
16
|
+
# Attempt to get the action method from the Action class if it
|
17
|
+
# exists, otherwise return nil to show that we don't support the
|
18
|
+
# given action.
|
19
|
+
action_method = "action_#{name}"
|
20
|
+
return Action.send(action_method) if Action.respond_to?(action_method)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# This method is called if the underying machine ID changes. Providers
|
25
|
+
# can use this method to load in new data for the actual backing
|
26
|
+
# machine or to realize that the machine is now gone (the ID can
|
27
|
+
# become `nil`).
|
28
|
+
def machine_id_changed
|
29
|
+
end
|
30
|
+
|
31
|
+
# This should return a hash of information that explains how to
|
32
|
+
# SSH into the machine. If the machine is not at a point where
|
33
|
+
# SSH is even possible, then `nil` should be returned.
|
34
|
+
def ssh_info
|
35
|
+
# Run a custom action called "read_ssh_info" which does what it says
|
36
|
+
# and puts the resulting SSH info into the `:machine_ssh_info` key in
|
37
|
+
# the environment.
|
38
|
+
#
|
39
|
+
# Ssh info has following format..
|
40
|
+
#
|
41
|
+
#{
|
42
|
+
# :host => "1.2.3.4",
|
43
|
+
# :port => "22",
|
44
|
+
# :username => "mitchellh",
|
45
|
+
# :private_key_path => "/path/to/my/key"
|
46
|
+
#}
|
47
|
+
env = @machine.action("read_ssh_info")
|
48
|
+
env[:machine_ssh_info]
|
49
|
+
end
|
50
|
+
|
51
|
+
# This should return the state of the machine within this provider.
|
52
|
+
# The state must be an instance of {MachineState}.
|
53
|
+
def state
|
54
|
+
# Run a custom action we define called "read_state" which does
|
55
|
+
# what it says. It puts the state in the `:machine_state_id`
|
56
|
+
# key in the environment.
|
57
|
+
env = @machine.action("read_state")
|
58
|
+
|
59
|
+
state_id = env[:machine_state_id]
|
60
|
+
|
61
|
+
# Get the short and long description
|
62
|
+
short = I18n.t("vagrant_ovirt3.states.short_#{state_id}")
|
63
|
+
long = I18n.t("vagrant_ovirt3.states.long_#{state_id}")
|
64
|
+
|
65
|
+
# Return the MachineState object
|
66
|
+
Vagrant::MachineState.new(state_id, short, long)
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s
|
70
|
+
id = @machine.id.nil? ? "new" : @machine.id
|
71
|
+
"oVirt (#{id})"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OVirtProvider
|
3
|
+
module Util
|
4
|
+
module Collection
|
5
|
+
# This method finds a matching _thing_ in a collection of
|
6
|
+
# _things_. This works matching if the ID or NAME equals to
|
7
|
+
# `name`. Or, if `name` is a regexp, a partial match is chosen
|
8
|
+
# as well.
|
9
|
+
def self.find_matching(collection, name)
|
10
|
+
collection.each do |single|
|
11
|
+
return single if single.name == name
|
12
|
+
return single if single.id == name
|
13
|
+
end
|
14
|
+
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OVirtProvider
|
3
|
+
module Util
|
4
|
+
class Timer
|
5
|
+
# A basic utility method that times the execution of the given
|
6
|
+
# block and returns it.
|
7
|
+
def self.time
|
8
|
+
start_time = Time.now.to_f
|
9
|
+
yield
|
10
|
+
end_time = Time.now.to_f
|
11
|
+
|
12
|
+
end_time - start_time
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_ovirt3:
|
3
|
+
creating_vm: |-
|
4
|
+
Creating VM with the following settings...
|
5
|
+
destroy_vm: |-
|
6
|
+
Removing VM...
|
7
|
+
not_created: |-
|
8
|
+
VM is not created. Please run `vagrant up` first.
|
9
|
+
starting_vm: |-
|
10
|
+
Starting VM.
|
11
|
+
error_recovering: |-
|
12
|
+
An error occured. Recovering..
|
13
|
+
waiting_for_ip: |-
|
14
|
+
Waiting for VM to get an IP address...
|
15
|
+
waiting_for_ssh: |-
|
16
|
+
Waiting for SSH to become available...
|
17
|
+
rsync_folder: |-
|
18
|
+
Rsyncing folder: %{hostpath} => %{guestpath}
|
19
|
+
wait_for_ready_vm: |-
|
20
|
+
Waiting for VM to become "ready" to start...
|
21
|
+
already_created: |-
|
22
|
+
VM is already created.
|
23
|
+
ready: |-
|
24
|
+
Machine is booted and ready for use!
|
25
|
+
wait_for_ready_volume: |-
|
26
|
+
Waiting for VM volume to become "ready" to start...
|
27
|
+
|
28
|
+
errors:
|
29
|
+
fog_ovirt_connection_error: |-
|
30
|
+
Error while connecting to oVirt: %{error_message}
|
31
|
+
no_datacenter_error: |-
|
32
|
+
No usable datacenter found! Please check if datacenter specified in
|
33
|
+
configuration is avaliable.
|
34
|
+
no_cluster_error: |-
|
35
|
+
No usable cluster found! Please check if cluster specified in
|
36
|
+
configuration is avaliable.
|
37
|
+
no_quota_error: |-
|
38
|
+
No usable quota found! Please check if quota specified in
|
39
|
+
configuration is avaliable.
|
40
|
+
no_template_error: |-
|
41
|
+
No template %{template_name} found!
|
42
|
+
fog_create_server_error: |-
|
43
|
+
Error while creating domain: %{error_message}
|
44
|
+
interface_slot_not_available: |-
|
45
|
+
Interface adapter number is already in use. Please specify other adapter
|
46
|
+
number.
|
47
|
+
add_interface_error: |-
|
48
|
+
Error while adding new interface to VM. %{error_message}
|
49
|
+
no_vm_error: |-
|
50
|
+
No VM %{vm_name} found.
|
51
|
+
no_network_error: |-
|
52
|
+
No network %{network_name} found.
|
53
|
+
start_vm_error: |-
|
54
|
+
Unable to start VM: %{error_message}
|
55
|
+
wait_for_ready_vm_timeout: |-
|
56
|
+
Timeout occurred while waiting for VM to become ready to start
|
57
|
+
no_ip_address_error: |-
|
58
|
+
No IP address found.
|
59
|
+
rsync_error: |-
|
60
|
+
There was an error when attemping to rsync a share folder.
|
61
|
+
Please inspect the error message below for more info.
|
62
|
+
|
63
|
+
Host path: %{hostpath}
|
64
|
+
Guest path: %{guestpath}
|
65
|
+
Error: %{stderr}
|
66
|
+
update_volume_error: |-
|
67
|
+
Error while updating volume. %{error_message}
|
68
|
+
wait_for_ready_resized_volume_timeout: |-
|
69
|
+
Timeout occurred while waiting for resized volume to become ready
|
70
|
+
|
71
|
+
states:
|
72
|
+
short_paused: |-
|
73
|
+
pause
|
74
|
+
short_shutoff: |-
|
75
|
+
shutoff
|
76
|
+
long_shutoff: |-
|
77
|
+
The oVirt machine is not running. Run `vagrant up` to start it.
|
78
|
+
short_down: |-
|
79
|
+
shutoff
|
80
|
+
long_down: |-
|
81
|
+
The oVirt machine is not running. Run `vagrant up` to start it.
|
82
|
+
short_not_created: |-
|
83
|
+
not created
|
84
|
+
long_not_created: |-
|
85
|
+
The oVirt domain is not created. Run `vagrant up` to create it.
|
86
|
+
short_running: |-
|
87
|
+
running
|
88
|
+
long_running: |-
|
89
|
+
The oVirt domain is running. To stop this machine, you can run
|
90
|
+
`vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
|
@@ -0,0 +1,132 @@
|
|
1
|
+
#!/bin/bash +x
|
2
|
+
|
3
|
+
# This script should help to prepare RedHat and RedHat like OS (CentOS,
|
4
|
+
# Scientific Linux, ...) for Vagrant usage.
|
5
|
+
|
6
|
+
# To create new box image, just install minimal base system in VM. Then upload
|
7
|
+
# this script to the VM and run it. After script has finished, halt the machine
|
8
|
+
# and then create an oVirt template, which will be used for creating new
|
9
|
+
# vagrant machines.
|
10
|
+
|
11
|
+
|
12
|
+
# We need a hostname.
|
13
|
+
if [ $# -ne 1 ]; then
|
14
|
+
echo "Usage: $0 <hostname>"
|
15
|
+
echo "Hostname should be in format vagrant-[os-name], e.g. vagrant-redhat63."
|
16
|
+
exit 1
|
17
|
+
fi
|
18
|
+
|
19
|
+
|
20
|
+
# On which version of RedHet are we running?
|
21
|
+
RHEL_MAJOR_VERSION=$(sed 's/.*release \([0-9]\)\..*/\1/' /etc/redhat-release)
|
22
|
+
if [ $? -ne 0 ]; then
|
23
|
+
echo "Is this a RedHat distro?"
|
24
|
+
exit 1
|
25
|
+
fi
|
26
|
+
echo "* Found RedHat ${RHEL_MAJOR_VERSION} version."
|
27
|
+
|
28
|
+
|
29
|
+
# Setup hostname vagrant-something.
|
30
|
+
FQDN="$1.vagrantup.com"
|
31
|
+
if grep '^HOSTNAME=' /etc/sysconfig/network > /dev/null; then
|
32
|
+
sed -i 's/HOSTNAME=\(.*\)/HOSTNAME='${FQDN}'/' /etc/sysconfig/network
|
33
|
+
else
|
34
|
+
echo "HOSTNAME=${FQDN}" >> /etc/sysconfig/network
|
35
|
+
fi
|
36
|
+
|
37
|
+
|
38
|
+
# Enable EPEL and Puppet repositories.
|
39
|
+
if [[ $RHEL_MAJOR_VERSION -eq 5 ]]; then
|
40
|
+
yum install -y \
|
41
|
+
http://ftp.astral.ro/mirrors/fedora/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm \
|
42
|
+
https://yum.puppetlabs.com/puppetlabs-release-el-5.noarch.rpm
|
43
|
+
elif [[ $RHEL_MAJOR_VERSION -eq 6 ]]; then
|
44
|
+
yum install -y \
|
45
|
+
http://ftp.astral.ro/mirrors/fedora/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm \
|
46
|
+
https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
|
47
|
+
elif [[ $RHEL_MAJOR_VERSION -eq 7 ]]; then
|
48
|
+
yum install -y \
|
49
|
+
http://ftp.astral.ro/mirrors/fedora/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm \
|
50
|
+
https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
|
51
|
+
else
|
52
|
+
echo "Is this a valid major release?"
|
53
|
+
exit 1
|
54
|
+
fi
|
55
|
+
|
56
|
+
# Install some required software.
|
57
|
+
yum -y install openssh-server openssh-clients sudo curl \
|
58
|
+
ruby ruby-devel make gcc rubygems rsync puppet ovirt-guest-agent
|
59
|
+
chkconfig sshd on
|
60
|
+
|
61
|
+
# Users, groups, passwords and sudoers.
|
62
|
+
grep 'vagrant' /etc/passwd > /dev/null
|
63
|
+
if [ $? -ne 0 ]; then
|
64
|
+
echo '* Creating user vagrant.'
|
65
|
+
useradd vagrant
|
66
|
+
echo 'vagrant' | passwd --stdin vagrant
|
67
|
+
fi
|
68
|
+
grep '^admin:' /etc/group > /dev/null || groupadd admin
|
69
|
+
usermod -G admin vagrant
|
70
|
+
|
71
|
+
echo 'Defaults env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
|
72
|
+
echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
|
73
|
+
sed -i 's/Defaults\s*requiretty/Defaults !requiretty/' /etc/sudoers
|
74
|
+
|
75
|
+
|
76
|
+
# SSH setup
|
77
|
+
# Add Vagrant ssh key for root accout.
|
78
|
+
sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config
|
79
|
+
|
80
|
+
vagrant_home=/home/vagrant
|
81
|
+
[ -d $vagrant_home/.ssh ] || mkdir $vagrant_home/.ssh
|
82
|
+
chmod 700 $vagrant_home/.ssh
|
83
|
+
curl https://raw2.github.com/mitchellh/vagrant/master/keys/vagrant.pub > $vagrant_home/.ssh/authorized_keys
|
84
|
+
chmod 600 $vagrant_home/.ssh/authorized_keys
|
85
|
+
chown -R vagrant:vagrant $vagrant_home/.ssh
|
86
|
+
|
87
|
+
|
88
|
+
# Disable firewall and switch SELinux to permissive mode.
|
89
|
+
chkconfig iptables off
|
90
|
+
chkconfig ip6tables off
|
91
|
+
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux
|
92
|
+
[ -f /etc/selinux/config ] && sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
|
93
|
+
|
94
|
+
|
95
|
+
# Networking setup..
|
96
|
+
|
97
|
+
# Problem situation: Two interfaces are connected to same network. One interface
|
98
|
+
# wants to renew DHCP lease and asks server for address. DHCPACK message from
|
99
|
+
# server arrives, client moves to BOUND state. The client performs a check on
|
100
|
+
# the suggested address to ensure that the address is not already in use. On
|
101
|
+
# arping for specified IP address, other interface replies and that's why
|
102
|
+
# dhclient-script replies with DHCPDECLINE message. (See RFC2131, 4.4.1.).
|
103
|
+
# Solution: Set sysctl to reply only if the target IP address is local address
|
104
|
+
# configured on the incoming interface. (See kernel documentation
|
105
|
+
# Documentation/networking/ip-sysctl.txt)
|
106
|
+
set_sysctl()
|
107
|
+
{
|
108
|
+
grep $1 /etc/sysctl.conf > /dev/null
|
109
|
+
[ $? -eq 0 ] && sed -i '/'$1'/d' /etc/sysctl.conf
|
110
|
+
echo "$1 = $2" >> /etc/sysctl.conf
|
111
|
+
}
|
112
|
+
set_sysctl 'net.ipv4.conf.all.arp_ignore' 1
|
113
|
+
set_sysctl 'net.ipv4.conf.all.arp_announce' 2
|
114
|
+
set_sysctl 'net.ipv4.conf.all.rp_filter' 3
|
115
|
+
|
116
|
+
# Don't fix ethX names to hw address.
|
117
|
+
rm -f /etc/udev/rules.d/*persistent-net.rules
|
118
|
+
rm -f /etc/udev/rules.d/*-net.rules
|
119
|
+
rm -fr /var/lib/dhclient/*
|
120
|
+
|
121
|
+
# Interface eth0 should always get IP address via dhcp.
|
122
|
+
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
|
123
|
+
DEVICE="eth0"
|
124
|
+
BOOTPROTO="dhcp"
|
125
|
+
ONBOOT="yes"
|
126
|
+
NM_CONTROLLED="no"
|
127
|
+
EOF
|
128
|
+
|
129
|
+
|
130
|
+
# Do some cleanup..
|
131
|
+
rm -f ~root/.bash_history
|
132
|
+
yum clean all
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/vagrant-ovirt3/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Marcus Young"]
|
6
|
+
gem.email = ["myoung34@my.apsu.edu"]
|
7
|
+
gem.description = %q{Vagrant provider for oVirt and RHEV v3}
|
8
|
+
gem.summary = %q{This vagrant plugin provides the ability to create, control, and destroy virtual machines under oVirt/RHEV}
|
9
|
+
gem.homepage = "https://github.com/myoung34/vagrant-ovirt3"
|
10
|
+
gem.licenses = ['MIT']
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "vagrant-ovirt3"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = VagrantPlugins::OVirtProvider::VERSION
|
18
|
+
|
19
|
+
gem.add_runtime_dependency "fog", "~> 1.25"
|
20
|
+
gem.add_runtime_dependency 'rbovirt', '~> 0.0', '>= 0.0.30'
|
21
|
+
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake', '~> 0'
|
24
|
+
end
|
25
|
+
|