vagrant-libvirt 0.0.41 → 0.0.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.github/issue_template.md +37 -0
  4. data/.gitignore +21 -0
  5. data/.travis.yml +24 -0
  6. data/Gemfile +26 -0
  7. data/LICENSE +22 -0
  8. data/README.md +1380 -0
  9. data/Rakefile +8 -0
  10. data/example_box/README.md +29 -0
  11. data/example_box/Vagrantfile +60 -0
  12. data/example_box/metadata.json +5 -0
  13. data/lib/vagrant-libvirt.rb +29 -0
  14. data/lib/vagrant-libvirt/action.rb +370 -0
  15. data/lib/vagrant-libvirt/action/create_domain.rb +322 -0
  16. data/lib/vagrant-libvirt/action/create_domain_volume.rb +87 -0
  17. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +302 -0
  18. data/lib/vagrant-libvirt/action/create_networks.rb +361 -0
  19. data/lib/vagrant-libvirt/action/destroy_domain.rb +83 -0
  20. data/lib/vagrant-libvirt/action/destroy_networks.rb +95 -0
  21. data/lib/vagrant-libvirt/action/forward_ports.rb +227 -0
  22. data/lib/vagrant-libvirt/action/halt_domain.rb +41 -0
  23. data/lib/vagrant-libvirt/action/handle_box_image.rb +156 -0
  24. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +57 -0
  25. data/lib/vagrant-libvirt/action/is_created.rb +18 -0
  26. data/lib/vagrant-libvirt/action/is_running.rb +21 -0
  27. data/lib/vagrant-libvirt/action/is_suspended.rb +42 -0
  28. data/lib/vagrant-libvirt/action/message_already_created.rb +16 -0
  29. data/lib/vagrant-libvirt/action/message_not_created.rb +16 -0
  30. data/lib/vagrant-libvirt/action/message_not_running.rb +16 -0
  31. data/lib/vagrant-libvirt/action/message_not_suspended.rb +16 -0
  32. data/lib/vagrant-libvirt/action/message_will_not_destroy.rb +17 -0
  33. data/lib/vagrant-libvirt/action/package_domain.rb +105 -0
  34. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +94 -0
  35. data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +17 -0
  36. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +27 -0
  37. data/lib/vagrant-libvirt/action/read_mac_addresses.rb +40 -0
  38. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +20 -0
  39. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +50 -0
  40. data/lib/vagrant-libvirt/action/resume_domain.rb +34 -0
  41. data/lib/vagrant-libvirt/action/set_boot_order.rb +109 -0
  42. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +64 -0
  43. data/lib/vagrant-libvirt/action/share_folders.rb +71 -0
  44. data/lib/vagrant-libvirt/action/start_domain.rb +307 -0
  45. data/lib/vagrant-libvirt/action/suspend_domain.rb +40 -0
  46. data/lib/vagrant-libvirt/action/wait_till_up.rb +109 -0
  47. data/lib/vagrant-libvirt/cap/mount_p9.rb +42 -0
  48. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +17 -0
  49. data/lib/vagrant-libvirt/cap/synced_folder.rb +113 -0
  50. data/lib/vagrant-libvirt/config.rb +746 -0
  51. data/lib/vagrant-libvirt/driver.rb +118 -0
  52. data/lib/vagrant-libvirt/errors.rb +153 -0
  53. data/lib/vagrant-libvirt/plugin.rb +92 -0
  54. data/lib/vagrant-libvirt/provider.rb +130 -0
  55. data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +13 -0
  56. data/lib/vagrant-libvirt/templates/domain.xml.erb +244 -0
  57. data/lib/vagrant-libvirt/templates/private_network.xml.erb +42 -0
  58. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +26 -0
  59. data/lib/vagrant-libvirt/util.rb +11 -0
  60. data/lib/vagrant-libvirt/util/collection.rb +19 -0
  61. data/lib/vagrant-libvirt/util/erb_template.rb +22 -0
  62. data/lib/vagrant-libvirt/util/error_codes.rb +100 -0
  63. data/lib/vagrant-libvirt/util/network_util.rb +151 -0
  64. data/lib/vagrant-libvirt/util/timer.rb +17 -0
  65. data/lib/vagrant-libvirt/version.rb +5 -0
  66. data/locales/en.yml +162 -0
  67. data/spec/spec_helper.rb +9 -0
  68. data/spec/support/environment_helper.rb +46 -0
  69. data/spec/support/libvirt_context.rb +30 -0
  70. data/spec/support/sharedcontext.rb +34 -0
  71. data/spec/unit/action/destroy_domain_spec.rb +97 -0
  72. data/spec/unit/action/set_name_of_domain_spec.rb +21 -0
  73. data/spec/unit/action/wait_till_up_spec.rb +127 -0
  74. data/spec/unit/config_spec.rb +113 -0
  75. data/spec/unit/templates/domain_all_settings.xml +137 -0
  76. data/spec/unit/templates/domain_defaults.xml +46 -0
  77. data/spec/unit/templates/domain_spec.rb +84 -0
  78. data/tools/create_box.sh +130 -0
  79. data/tools/prepare_redhat_for_box.sh +119 -0
  80. data/vagrant-libvirt.gemspec +54 -0
  81. metadata +93 -3
@@ -0,0 +1,8 @@
1
+ #require 'rubygems'
2
+ #require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
+ Bundler::GemHelper.install_tasks
5
+ task default: [:deftask]
6
+ task :deftask do
7
+ puts 'call rake -T'
8
+ end
@@ -0,0 +1,29 @@
1
+ # Vagrant Libvirt 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 `libvirt` provider.
5
+ To turn this into a box create a vagrant image according documentation (don't
6
+ forget to install rsync command) and create box with following command:
7
+
8
+ ```
9
+ $ tar cvzf custom_box.box ./metadata.json ./Vagrantfile ./box.img
10
+ ```
11
+
12
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
13
+ defaults for Libvirt. These defaults can easily be overwritten by higher-level
14
+ Vagrantfiles (such as project root Vagrantfiles).
15
+
16
+ ## Box Metadata
17
+
18
+ Libvirt box should define at least three data fields in `metadata.json` file.
19
+
20
+ * provider - Provider name is libvirt.
21
+ * format - Currently supported format is qcow2.
22
+ * virtual_size - Virtual size of image in GBytes.
23
+
24
+ ## Converting Boxes
25
+
26
+ Instead of creating a box from scratch, you can use
27
+ [vagrant-mutate](https://github.com/sciurus/vagrant-mutate)
28
+ to take boxes created for other Vagrant providers and use them
29
+ with vagrant-libvirt.
@@ -0,0 +1,60 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+
6
+ # Example configuration of new VM..
7
+ #
8
+ #config.vm.define :test_vm do |test_vm|
9
+ # Box name
10
+ #
11
+ #test_vm.vm.box = "centos64"
12
+
13
+ # Domain Specific Options
14
+ #
15
+ # See README for more info.
16
+ #
17
+ #test_vm.vm.provider :libvirt do |domain|
18
+ # domain.memory = 2048
19
+ # domain.cpus = 2
20
+ #end
21
+
22
+ # Interfaces for VM
23
+ #
24
+ # Networking features in the form of `config.vm.network`
25
+ #
26
+ #test_vm.vm.network :private_network, :ip => '10.20.30.40'
27
+ #test_vm.vm.network :public_network, :ip => '10.20.30.41'
28
+ #end
29
+
30
+ # Options for libvirt vagrant provider.
31
+ config.vm.provider :libvirt do |libvirt|
32
+
33
+ # A hypervisor name to access. Different drivers can be specified, but
34
+ # this version of provider creates KVM machines only. Some examples of
35
+ # drivers are kvm (qemu hardware accelerated), qemu (qemu emulated),
36
+ # xen (Xen hypervisor), lxc (Linux Containers),
37
+ # esx (VMware ESX), vmwarews (VMware Workstation) and more. Refer to
38
+ # documentation for available drivers (http://libvirt.org/drivers.html).
39
+ libvirt.driver = "kvm"
40
+
41
+ # The name of the server, where libvirtd is running.
42
+ # libvirt.host = "localhost"
43
+
44
+ # If use ssh tunnel to connect to Libvirt.
45
+ libvirt.connect_via_ssh = false
46
+
47
+ # The username and password to access Libvirt. Password is not used when
48
+ # connecting via ssh.
49
+ libvirt.username = "root"
50
+ #libvirt.password = "secret"
51
+
52
+ # Libvirt storage pool name, where box image and instance snapshots will
53
+ # be stored.
54
+ libvirt.storage_pool_name = "default"
55
+
56
+ # Set a prefix for the machines that's different than the project dir name.
57
+ #libvirt.default_prefix = ''
58
+ end
59
+ end
60
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "provider" : "libvirt",
3
+ "format" : "qcow2",
4
+ "virtual_size" : 16
5
+ }
@@ -0,0 +1,29 @@
1
+ require 'pathname'
2
+
3
+ module VagrantPlugins
4
+ module ProviderLibvirt
5
+ lib_path = Pathname.new(File.expand_path('../vagrant-libvirt', __FILE__))
6
+ autoload :Action, lib_path.join('action')
7
+ autoload :Errors, lib_path.join('errors')
8
+ autoload :Util, lib_path.join('util')
9
+
10
+ def self.source_root
11
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
12
+ end
13
+ end
14
+ end
15
+
16
+ begin
17
+ require 'vagrant'
18
+ rescue LoadError
19
+ raise 'The Vagrant Libvirt plugin must be run within Vagrant.'
20
+ end
21
+
22
+ # This is a sanity check to make sure no one is attempting to install
23
+ # this into an early Vagrant version.
24
+ if Vagrant::VERSION < '1.5.0'
25
+ raise 'The Vagrant Libvirt plugin is only compatible with Vagrant 1.5+.'
26
+ end
27
+
28
+ # make sure base module class defined before loading plugin
29
+ require 'vagrant-libvirt/plugin'
@@ -0,0 +1,370 @@
1
+ require 'vagrant/action/builder'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module ProviderLibvirt
6
+ module Action
7
+ # Include the built-in modules so we can use them as top-level things.
8
+ include Vagrant::Action::Builtin
9
+ @logger = Log4r::Logger.new('vagrant_libvirt::action')
10
+
11
+ # remove image from libvirt storage pool
12
+ def self.remove_libvirt_image
13
+ Vagrant::Action::Builder.new.tap do |b|
14
+ b.use RemoveLibvirtImage
15
+ end
16
+ end
17
+
18
+ # This action is called to bring the box up from nothing.
19
+ def self.action_up
20
+ Vagrant::Action::Builder.new.tap do |b|
21
+ b.use ConfigValidate
22
+ b.use Call, IsCreated do |env, b2|
23
+ # Create VM if not yet created.
24
+ if !env[:result]
25
+ b2.use SetNameOfDomain
26
+ if !env[:machine].config.vm.box
27
+ b2.use CreateDomain
28
+ b2.use CreateNetworks
29
+ b2.use CreateNetworkInterfaces
30
+ b2.use SetBootOrder
31
+ b2.use StartDomain
32
+ else
33
+ b2.use HandleStoragePool
34
+ b2.use HandleBox
35
+ b2.use HandleBoxImage
36
+ b2.use CreateDomainVolume
37
+ b2.use CreateDomain
38
+
39
+ b2.use Provision
40
+ b2.use PrepareNFSValidIds
41
+ b2.use SyncedFolderCleanup
42
+ b2.use SyncedFolders
43
+ b2.use PrepareNFSSettings
44
+ b2.use ShareFolders
45
+ b2.use CreateNetworks
46
+ b2.use CreateNetworkInterfaces
47
+ b2.use SetBootOrder
48
+
49
+ b2.use StartDomain
50
+ b2.use WaitTillUp
51
+
52
+ b2.use ForwardPorts
53
+ b2.use SetHostname
54
+ # b2.use SyncFolders
55
+ end
56
+ else
57
+ env[:halt_on_error] = true
58
+ b2.use action_start
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ # Assuming VM is created, just start it. This action is not called
65
+ # directly by any subcommand. VM can be suspended, already running or in
66
+ # poweroff state.
67
+ def self.action_start
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use Call, IsRunning do |env, b2|
71
+ # If the VM is running, run the necessary provisioners
72
+ if env[:result]
73
+ b2.use action_provision
74
+ next
75
+ end
76
+
77
+ b2.use Call, IsSuspended do |env2, b3|
78
+ # if vm is suspended resume it then exit
79
+ if env2[:result]
80
+ b3.use CreateNetworks
81
+ b3.use ResumeDomain
82
+ next
83
+ end
84
+
85
+ if !env[:machine].config.vm.box
86
+ # With no box, we just care about network creation and starting it
87
+ b3.use CreateNetworks
88
+ b3.use SetBootOrder
89
+ b3.use StartDomain
90
+ else
91
+ # VM is not running or suspended.
92
+
93
+ b3.use Provision
94
+
95
+ # Ensure networks are created and active
96
+ b3.use CreateNetworks
97
+ b3.use SetBootOrder
98
+
99
+ b3.use PrepareNFSValidIds
100
+ b3.use SyncedFolderCleanup
101
+ b3.use SyncedFolders
102
+
103
+ # Start it..
104
+ b3.use StartDomain
105
+
106
+ # Machine should gain IP address when comming up,
107
+ # so wait for dhcp lease and store IP into machines data_dir.
108
+ b3.use WaitTillUp
109
+
110
+ b3.use ForwardPorts
111
+ b3.use PrepareNFSSettings
112
+ b3.use ShareFolders
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ # This is the action that is primarily responsible for halting the
120
+ # virtual machine.
121
+ def self.action_halt
122
+ Vagrant::Action::Builder.new.tap do |b|
123
+ b.use ConfigValidate
124
+ b.use ClearForwardedPorts
125
+ b.use Call, IsCreated do |env, b2|
126
+ unless env[:result]
127
+ b2.use MessageNotCreated
128
+ next
129
+ end
130
+
131
+ b2.use Call, IsSuspended do |env2, b3|
132
+ b3.use CreateNetworks if env2[:result]
133
+ b3.use ResumeDomain if env2[:result]
134
+ end
135
+
136
+ b2.use Call, IsRunning do |env2, b3|
137
+ next unless env2[:result]
138
+
139
+ # VM is running, halt it.
140
+ b3.use HaltDomain
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ # This is the action implements the reload command
147
+ # It uses the halt and start actions
148
+ def self.action_reload
149
+ Vagrant::Action::Builder.new.tap do |b|
150
+ b.use Call, IsCreated do |env, b2|
151
+ unless env[:result]
152
+ b2.use MessageNotCreated
153
+ next
154
+ end
155
+
156
+ b2.use ConfigValidate
157
+ b2.use action_halt
158
+ b2.use action_start
159
+ end
160
+ end
161
+ end
162
+
163
+ # not implemented and looks like not require
164
+ def self.action_package
165
+ Vagrant::Action::Builder.new.tap do |b|
166
+ b.use ConfigValidate
167
+ b.use PackageDomain
168
+ end
169
+ end
170
+
171
+ # This is the action that is primarily responsible for completely
172
+ # freeing the resources of the underlying virtual machine.
173
+ def self.action_destroy
174
+ Vagrant::Action::Builder.new.tap do |b|
175
+ b.use ConfigValidate
176
+ b.use Call, IsCreated do |env, b2|
177
+ unless env[:result]
178
+ # Try to remove stale volumes anyway
179
+ b2.use SetNameOfDomain
180
+ b2.use RemoveStaleVolume if env[:machine].config.vm.box
181
+ b2.use MessageNotCreated unless env[:result]
182
+
183
+ next
184
+ end
185
+
186
+ b2.use Call, DestroyConfirm do |env2, b3|
187
+ if env2[:result]
188
+ b3.use ClearForwardedPorts
189
+ # b3.use PruneNFSExports
190
+ b3.use DestroyDomain
191
+ b3.use DestroyNetworks
192
+ b3.use ProvisionerCleanup
193
+ else
194
+ b3.use MessageWillNotDestroy
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ # This action is called to SSH into the machine.
202
+ def self.action_ssh
203
+ Vagrant::Action::Builder.new.tap do |b|
204
+ b.use ConfigValidate
205
+ b.use Call, IsCreated do |env, b2|
206
+ unless env[:result]
207
+ b2.use MessageNotCreated
208
+ next
209
+ end
210
+
211
+ b2.use Call, IsRunning do |env2, b3|
212
+ unless env2[:result]
213
+ b3.use MessageNotRunning
214
+ next
215
+ end
216
+
217
+ b3.use SSHExec
218
+ end
219
+ end
220
+ end
221
+ end
222
+
223
+ # This action is called when `vagrant provision` is called.
224
+ def self.action_provision
225
+ Vagrant::Action::Builder.new.tap do |b|
226
+ b.use ConfigValidate
227
+ b.use Call, IsCreated do |env, b2|
228
+ unless env[:result]
229
+ b2.use MessageNotCreated
230
+ next
231
+ end
232
+
233
+ b2.use Call, IsRunning do |env2, b3|
234
+ unless env2[:result]
235
+ b3.use MessageNotRunning
236
+ next
237
+ end
238
+
239
+ b3.use Provision
240
+ # b3.use SyncFolders
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ # This is the action that is primarily responsible for suspending
247
+ # the virtual machine.
248
+ def self.action_suspend
249
+ Vagrant::Action::Builder.new.tap do |b|
250
+ b.use ConfigValidate
251
+ b.use Call, IsCreated do |env, b2|
252
+ unless env[:result]
253
+ b2.use MessageNotCreated
254
+ next
255
+ end
256
+
257
+ b2.use Call, IsRunning do |env2, b3|
258
+ unless env2[:result]
259
+ b3.use MessageNotRunning
260
+ next
261
+ end
262
+ b3.use SuspendDomain
263
+ end
264
+ end
265
+ end
266
+ end
267
+
268
+ # This is the action that is primarily responsible for resuming
269
+ # suspended machines.
270
+ def self.action_resume
271
+ Vagrant::Action::Builder.new.tap do |b|
272
+ b.use ConfigValidate
273
+ b.use Call, IsCreated do |env, b2|
274
+ unless env[:result]
275
+ b2.use MessageNotCreated
276
+ next
277
+ end
278
+
279
+ b2.use Call, IsSuspended do |env2, b3|
280
+ unless env2[:result]
281
+ b3.use MessageNotSuspended
282
+ next
283
+ end
284
+ b3.use CreateNetworks
285
+ b3.use ResumeDomain
286
+ end
287
+ end
288
+ end
289
+ end
290
+
291
+ def self.action_read_mac_addresses
292
+ Vagrant::Action::Builder.new.tap do |b|
293
+ b.use ConfigValidate
294
+ b.use ReadMacAddresses
295
+ end
296
+ end
297
+
298
+ # This is the action that will run a single SSH command.
299
+ def self.action_ssh_run
300
+ Vagrant::Action::Builder.new.tap do |b|
301
+ b.use ConfigValidate
302
+ b.use Call, IsCreated do |env, b2|
303
+ unless env[:result]
304
+ b2.use MessageNotCreated
305
+ next
306
+ end
307
+
308
+ b2.use Call, IsRunning do |env2, b3|
309
+ unless env2[:result]
310
+ b3.use MessageNotRunning
311
+ next
312
+ end
313
+
314
+ b3.use SSHRun
315
+ end
316
+ end
317
+ end
318
+ end
319
+
320
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
321
+ autoload :PackageDomain, action_root.join('package_domain')
322
+ autoload :CreateDomain, action_root.join('create_domain')
323
+ autoload :CreateDomainVolume, action_root.join('create_domain_volume')
324
+ autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
325
+ autoload :CreateNetworks, action_root.join('create_networks')
326
+ autoload :DestroyDomain, action_root.join('destroy_domain')
327
+ autoload :DestroyNetworks, action_root.join('destroy_networks')
328
+ autoload :ForwardPorts, action_root.join('forward_ports')
329
+ autoload :ClearForwardedPorts, action_root.join('forward_ports')
330
+ autoload :HaltDomain, action_root.join('halt_domain')
331
+ autoload :HandleBoxImage, action_root.join('handle_box_image')
332
+ autoload :HandleStoragePool, action_root.join('handle_storage_pool')
333
+ autoload :RemoveLibvirtImage, action_root.join('remove_libvirt_image')
334
+ autoload :IsCreated, action_root.join('is_created')
335
+ autoload :IsRunning, action_root.join('is_running')
336
+ autoload :IsSuspended, action_root.join('is_suspended')
337
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
338
+ autoload :MessageNotCreated, action_root.join('message_not_created')
339
+ autoload :MessageNotRunning, action_root.join('message_not_running')
340
+ autoload :MessageNotSuspended, action_root.join('message_not_suspended')
341
+ autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
342
+
343
+ autoload :RemoveStaleVolume, action_root.join('remove_stale_volume')
344
+
345
+ autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
346
+ autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
347
+ autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
348
+
349
+ autoload :ReadMacAddresses, action_root.join('read_mac_addresses')
350
+ autoload :ResumeDomain, action_root.join('resume_domain')
351
+ autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
352
+ autoload :SetBootOrder, action_root.join('set_boot_order')
353
+
354
+ # I don't think we need it anymore
355
+ autoload :ShareFolders, action_root.join('share_folders')
356
+ autoload :StartDomain, action_root.join('start_domain')
357
+ autoload :SuspendDomain, action_root.join('suspend_domain')
358
+ autoload :TimedProvision, action_root.join('timed_provision')
359
+
360
+ autoload :WaitTillUp, action_root.join('wait_till_up')
361
+ autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
362
+
363
+ autoload :SSHRun, 'vagrant/action/builtin/ssh_run'
364
+ autoload :HandleBox, 'vagrant/action/builtin/handle_box'
365
+ autoload :SyncedFolders, 'vagrant/action/builtin/synced_folders'
366
+ autoload :SyncedFolderCleanup, 'vagrant/action/builtin/synced_folder_cleanup'
367
+ autoload :ProvisionerCleanup, 'vagrant/action/builtin/provisioner_cleanup'
368
+ end
369
+ end
370
+ end