vagrant-ovirt3 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +211 -0
  6. data/Rakefile +7 -0
  7. data/example_box/README.md +13 -0
  8. data/example_box/Vagrantfile +18 -0
  9. data/example_box/dummy.box +0 -0
  10. data/example_box/metadata.json +4 -0
  11. data/lib/vagrant-ovirt3.rb +42 -0
  12. data/lib/vagrant-ovirt3/action.rb +131 -0
  13. data/lib/vagrant-ovirt3/action/connect_ovirt.rb +84 -0
  14. data/lib/vagrant-ovirt3/action/create_network_interfaces.rb +137 -0
  15. data/lib/vagrant-ovirt3/action/create_vm.rb +113 -0
  16. data/lib/vagrant-ovirt3/action/destroy_vm.rb +25 -0
  17. data/lib/vagrant-ovirt3/action/is_created.rb +18 -0
  18. data/lib/vagrant-ovirt3/action/message_already_created.rb +16 -0
  19. data/lib/vagrant-ovirt3/action/message_not_created.rb +16 -0
  20. data/lib/vagrant-ovirt3/action/read_ssh_info.rb +56 -0
  21. data/lib/vagrant-ovirt3/action/read_state.rb +37 -0
  22. data/lib/vagrant-ovirt3/action/resize_disk.rb +71 -0
  23. data/lib/vagrant-ovirt3/action/set_name_of_domain.rb +31 -0
  24. data/lib/vagrant-ovirt3/action/start_vm.rb +37 -0
  25. data/lib/vagrant-ovirt3/action/sync_folders.rb +65 -0
  26. data/lib/vagrant-ovirt3/action/wait_till_up.rb +94 -0
  27. data/lib/vagrant-ovirt3/config.rb +58 -0
  28. data/lib/vagrant-ovirt3/errors.rb +76 -0
  29. data/lib/vagrant-ovirt3/plugin.rb +74 -0
  30. data/lib/vagrant-ovirt3/provider.rb +76 -0
  31. data/lib/vagrant-ovirt3/util.rb +9 -0
  32. data/lib/vagrant-ovirt3/util/collection.rb +21 -0
  33. data/lib/vagrant-ovirt3/util/timer.rb +17 -0
  34. data/lib/vagrant-ovirt3/version.rb +6 -0
  35. data/locales/en.yml +90 -0
  36. data/tools/prepare_redhat_for_box.sh +132 -0
  37. data/vagrant-ovirt3.gemspec +25 -0
  38. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10423f44983ce1e613d1ff08ea44fccbe0693ab1
4
+ data.tar.gz: 11d9e3f5839ab31db9081fa4c1779054ddd91a0e
5
+ SHA512:
6
+ metadata.gz: fcf97503453de8e5647540903cf3e173d7a072b901bc771c288b5230f0e0cda0d124129a9f471e9e5fae77ae8ddcdecf52855018065c0837d898d536bd574ffd
7
+ data.tar.gz: 477d34d88e332da8034ec5127291b1ce0ba54c03219d1f246f45801406823bb9a60a7ba7765dbd776a335d60f23f853975f59533ba430d63fdfe56fa70382d47
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ Vagrantfile
19
+ !example_box/Vagrantfile
20
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-ovirt.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Marcus Young
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # Vagrant oVirt/RHEV v3 Provider
2
+
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that adds an
4
+ [oVirt v3](http://ovirt.org) and
5
+ [rhev v3](http://www.redhat.com/products/virtualization/) provider to Vagrant,
6
+ allowing Vagrant to control and provision machines in oVirt and RHEV.
7
+
8
+ In this document, both oVirt and RHEV names are used interchangeably and
9
+ represent the same platform on top of which this provider should work.
10
+
11
+ ## Version 1.0.0
12
+ * Complete overhaul of naming schemes. Vagrant-ovirt upstream is deprecated. The provider going forward is 'ovirt3' to allow gem/plugin availability.
13
+ * Volumes are automatically resized
14
+
15
+ ## Version 0.2.1
16
+ * Removed automatic resizing, will be readded when upstream fog changes are committed to rubygems.org
17
+
18
+ ## Features (Version 0.2.0)
19
+ * ~~Volumes are automatically resized~~
20
+ * Replaced configuration to get IP configuration with REST API usage
21
+
22
+ ## Features (Version 0.1.0)
23
+
24
+ * Vagrant `up` and `destroy` commands.
25
+ * Create and boot oVirt machines from templates.
26
+ * SSH into domains.
27
+ * Provision domains with any built-in Vagrant provisioner.
28
+ * Minimal synced folder support via `rsync`.
29
+
30
+ ## Future work
31
+
32
+ * Validation of configuration parameters.
33
+ * Test it on other versions of oVirt and RHEV.
34
+ * Template preparation scripts for other distros than RHEL.
35
+ * Vagrant commands `halt`, `resume`, `ssh`, `provision`, `suspend` and `resume`.
36
+ * Take a look at [open issues](https://github.com/myoung34/vagrant-ovirt3/issues?state=open).
37
+
38
+ ## Installation
39
+
40
+ ```
41
+ $ vagrant plugin install vagrant-ovirt3
42
+ $ vagrant up --provider=ovirt3
43
+ ```
44
+
45
+ ## Vagrant Project Preparation
46
+
47
+ Create a Vagrantfile that looks like the following, filling in
48
+ your information where necessary.
49
+
50
+ ```ruby
51
+ Vagrant.configure('2') do |config|
52
+ config.vm.box = 'ovirt'
53
+ config.vm.box_url = 'https://raw.github.com/myoung34/vagrant-ovirt3/master/example_box/ovirt.box'
54
+
55
+ config.vm.network :private_network,
56
+ :ip => '192.168.56.100', :nictype => 'virtio', :netmask => '255.255.255.0', #normal network configuration
57
+ :ovirt__ip => '10.101.55.72', :ovirt__network_name => 'ovirtmgmt', :ovirt__gateway => '10.101.55.1' # oVirt specific information, overwrites previous on oVirt provider
58
+
59
+ config.vm.provider :ovirt3 do |ovirt|
60
+ ovirt.template = 'template'
61
+ ovirt.cpus = 1
62
+ ovirt.memory = 1024
63
+ ovirt.console = 'vnc' #could also be 'spice'
64
+ ovirt.url = 'https://youroVirtmaster:443'
65
+ ovirt.username = 'username'
66
+ ovirt.password = 'password'
67
+ ovirt.datacenter = 'datacenter'
68
+ end
69
+ end
70
+ ```
71
+
72
+ ### RHEV/oVirt Configuration Options
73
+
74
+ This provider exposes quite a few provider-specific configuration options:
75
+
76
+ * `url` - URL to management interface.
77
+ * `username` - Username to access oVirt.
78
+ * `password` - Password to access oVirt.
79
+ * `datacenter` - oVirt datacenter name, where machines will be created.
80
+ * `cluster` - oVirt cluster name. Defaults to first cluster found.
81
+
82
+ ### Domain Specific Options
83
+
84
+ * `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
85
+ * `cpus` - Number of virtual cpus. Defaults to 1 if not set.
86
+ * `template` - Name of template from which new VM should be created.
87
+ * `console` - Console type to use. Can be 'vnc' or 'spice'. Default is 'spice'
88
+ * `disk_size` - If set, the first volume of the VM will automatically be resized
89
+ to the specified value. disk_size is in GB
90
+
91
+ Specific domain settings can be set for each domain separately in multi-VM
92
+ environment. Example below shows a part of Vagrantfile, where specific options
93
+ are set for dbserver domain.
94
+
95
+ ```ruby
96
+ Vagrant.configure("2") do |config|
97
+ config.vm.define :dbserver do |dbserver|
98
+ dbserver.vm.box = "ovirt"
99
+ dbserver.vm.provider :ovirt3 do |vm|
100
+ vm.memory = 2048
101
+ vm.cpus = 2
102
+ vm.template = "centos63-vagrant-base"
103
+ end
104
+ end
105
+
106
+ # ...
107
+ ```
108
+
109
+ ## Multiple provider Vagrantfile with Provisioners Example
110
+
111
+ This example allows you to spin up a box under virtualbox using `$ vagrant up` as well as a VM under oVirt using a template with `$ vagrant up --provider=ovirt`
112
+ Note, the network information will differ between the two. Under virtualbox, it should come up with an IP of `192.168.56.100`. Under oVirt it should come up as `10.101.55.72` if successful.
113
+
114
+ ```ruby
115
+ Vagrant.configure('2') do |config|
116
+ config.vm.box = 'mybox'
117
+
118
+ config.vm.network :private_network,
119
+ :ip => '192.168.56.100', :nictype => 'virtio', :netmask => '255.255.255.0' #normal network configuration
120
+ :ovirt__ip => '10.101.55.72', :ovirt__network_name => 'ovirtmgmt', :ovirt__gateway => '10.101.55.1', # oVirt specific information, overwrites previous on oVirt provider
121
+
122
+ config.vm.provider :virtualbox do |vb|
123
+ vb.customize [
124
+ # Key Value
125
+ 'modifyvm', :id,
126
+ '--cpuexecutioncap', '90',
127
+ '--memory', '1376',
128
+ '--nictype2', 'virtio',
129
+ ]
130
+ end
131
+
132
+
133
+ config.vm.provider :ovirt3 do |ovirt|
134
+ ovirt.template = 'template'
135
+ ovirt.cpus = 1
136
+ ovirt.memory = 1024
137
+ ovirt.console = 'vnc' #could also be 'spice'
138
+ ovirt.url = 'https://youroVirtmaster:443'
139
+ ovirt.username = 'username'
140
+ ovirt.password = 'password'
141
+ ovirt.datacenter = 'datacenter'
142
+ end
143
+
144
+ config.vm.provision 'shell' do |shell|
145
+ shell.inline = 'uname -a > /var/log/something.log 2>&1'
146
+ end
147
+
148
+ config.vm.provision :puppet do |puppet|
149
+ puppet.options = [
150
+ "--environment development",
151
+ '--hiera_config=/etc/puppet/hiera/hiera.yaml',
152
+ ]
153
+ puppet.manifests_path = './manifests'
154
+ puppet.manifest_file = 'default.pp'
155
+ end
156
+ ```
157
+
158
+ ### How Project Is Created
159
+
160
+ Vagrant goes through steps below when creating new project:
161
+
162
+ 1. Connect to oVirt via REST API on every REST query.
163
+ 2. Create new oVirt machine from template with additional network interfaces.
164
+ 3. Start oVirt machine.
165
+ 4. Check for IP address of VM using the REST API.
166
+ 5. Wait till SSH is available.
167
+ 6. Sync folders via `rsync` and run Vagrant provisioner on new domain if
168
+ setup in Vagrantfile.
169
+
170
+ ## Network Interfaces
171
+
172
+ Networking features in the form of `config.vm.network` support private networks
173
+ concept. No public network or port forwarding are supported in current version
174
+ of provider.
175
+
176
+ An examples of network interface definitions:
177
+
178
+ ```ruby
179
+ config.vm.define :test_vm1 do |test_vm1|
180
+ test_vm1.vm.network :private_network,
181
+ :ip => "10.20.30.40",
182
+ :netmask => "255.255.255.0",
183
+ :ovirt__network_name => "ovirt_networkname"
184
+ end
185
+ ```
186
+
187
+ In example below, one additional network interface is created for VM test_vm1.
188
+ Interface is connected to `ovirt_networkname` network and configured to ip
189
+ address `10.20.30.40/24`. If you omit ip address, interface will be configured
190
+ dynamically via dhcp.
191
+
192
+ ## Box Format
193
+
194
+ Every provider in Vagrant must introduce a custom box format. This provider
195
+ introduces oVirt boxes. You can view an example box in the
196
+ [example_box](https://github.com/myoung34/vagrant-ovirt3/tree/master/example_box)
197
+ directory. That directory also contains instructions on how to build a box.
198
+
199
+ The box is a tarball containing:
200
+
201
+ * `metadata.json` file describing box image (just a provider name).
202
+ * `Vagrantfile` that does default settings for the provider-specific configuration for this provider.
203
+
204
+ ## Contributing
205
+
206
+ 1. Fork it
207
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
208
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
209
+ 4. Push to the branch (`git push origin my-new-feature`)
210
+ 5. Create new Pull Request
211
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+
3
+ #require 'rubygems'
4
+ #require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+ Bundler::GemHelper.install_tasks
7
+
@@ -0,0 +1,13 @@
1
+ # Vagrant oVirt3 Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `ovirt3` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf dummy.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for oVirt. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,18 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = 'ovirt3'
6
+ config.vm.box_url = 'https://raw.github.com/myoung34/vagrant-ovirt3/master/example_box/dummy.box'
7
+
8
+ config.vm.provider :ovirt3 do |ovirt|
9
+ ovirt.url = "https://ovirt.example.com:443"
10
+ ovirt.username = "username"
11
+ ovirt.password = "secret"
12
+ ovirt.datacenter = "Datacenter name"
13
+ ovirt.template = "Template name"
14
+ ovirt.quota = "Quota name"
15
+ ovirt.cpus = 1
16
+ ovirt.memory = 512
17
+ end
18
+ end
Binary file
@@ -0,0 +1,4 @@
1
+ {
2
+ "provider": "ovirt3"
3
+ }
4
+
@@ -0,0 +1,42 @@
1
+ require 'pathname'
2
+ require 'vagrant-ovirt3/plugin'
3
+
4
+ module VagrantPlugins
5
+ module OVirtProvider
6
+ lib_path = Pathname.new(File.expand_path("../vagrant-ovirt3", __FILE__))
7
+ autoload :Action, lib_path.join("action")
8
+ autoload :Errors, lib_path.join("errors")
9
+ autoload :Util, lib_path.join("util")
10
+
11
+ @@ovirt_connection = nil
12
+ @@ovirt_client = nil
13
+ def self.ovirt_connection
14
+ @@ovirt_connection
15
+ end
16
+
17
+ def self.ovirt_connection=(conn)
18
+ @@ovirt_connection = conn
19
+ end
20
+
21
+ def self.ovirt_client
22
+ @@ovirt_client
23
+ end
24
+
25
+ def self.ovirt_client=(conn)
26
+ @@ovirt_client = conn
27
+ end
28
+
29
+
30
+ def self.source_root
31
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
32
+ end
33
+ end
34
+ end
35
+
36
+ # Set default provider with bash environment variable like this:
37
+ # export VAGRANT_DEFAULT_PROVIDER=ovirt3
38
+ Vagrant::Environment.class_eval do
39
+ def default_provider
40
+ (ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
41
+ end
42
+ end
@@ -0,0 +1,131 @@
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
+ b2.use SetNameOfDomain
21
+ b2.use CreateVM
22
+ b2.use ResizeDisk
23
+
24
+ b2.use Provision
25
+ b2.use CreateNetworkInterfaces
26
+
27
+ b2.use SetHostname
28
+ b2.use StartVM
29
+ b2.use WaitTillUp
30
+ b2.use SyncFolders
31
+ end
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 ConnectOVirt
47
+ b2.use DestroyVM
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 ConnectOVirt
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 ConnectOVirt
69
+ b.use ReadSSHInfo
70
+ end
71
+ end
72
+
73
+ def self.action_ssh
74
+ Vagrant::Action::Builder.new.tap do |b|
75
+ b.use ConfigValidate
76
+ b.use Call, IsCreated do |env, b2|
77
+ if !env[:result]
78
+ b2.use MessageNotCreated
79
+ next
80
+ end
81
+ b2.use SSHExec
82
+ end
83
+ end
84
+ end
85
+
86
+ def self.action_ssh_run
87
+ Vagrant::Action::Builder.new.tap do |b|
88
+ b.use ConfigValidate
89
+ b.use Call, IsCreated do |env, b2|
90
+ if !env[:result]
91
+ b2.use MessageNotCreated
92
+ next
93
+ end
94
+ b2.use SSHRun
95
+ end
96
+ end
97
+ end
98
+
99
+ def self.action_provision
100
+ Vagrant::Action::Builder.new.tap do |b|
101
+ b.use ConfigValidate
102
+ b.use Call, IsCreated do |env, b2|
103
+ if !env[:result]
104
+ b2.use MessageNotCreated
105
+ next
106
+ end
107
+ b2.use Provision
108
+ b2.use SyncFolders
109
+ end
110
+ end
111
+ end
112
+
113
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
114
+ autoload :ConnectOVirt, action_root.join("connect_ovirt")
115
+ autoload :IsCreated, action_root.join("is_created")
116
+ autoload :SetNameOfDomain, action_root.join("set_name_of_domain")
117
+ autoload :CreateVM, action_root.join("create_vm")
118
+ autoload :CreateNetworkInterfaces, action_root.join("create_network_interfaces")
119
+ autoload :ResizeDisk, action_root.join("resize_disk")
120
+ autoload :StartVM, action_root.join("start_vm")
121
+ autoload :MessageNotCreated, action_root.join("message_not_created")
122
+ autoload :DestroyVM, action_root.join("destroy_vm")
123
+ autoload :ReadState, action_root.join("read_state")
124
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
125
+ autoload :WaitTillUp, action_root.join("wait_till_up")
126
+ autoload :SyncFolders, action_root.join("sync_folders")
127
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
128
+ end
129
+ end
130
+ end
131
+