vagrant-libvirt 0.0.10 → 0.0.11
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/CHANGELOG.md +9 -0
- data/Gemfile +6 -4
- data/README.md +5 -5
- data/Rakefile +1 -0
- data/lib/vagrant-libvirt.rb +5 -5
- data/lib/vagrant-libvirt/action.rb +34 -17
- data/lib/vagrant-libvirt/action/connect_libvirt.rb +13 -1
- data/lib/vagrant-libvirt/action/destroy_domain.rb +17 -4
- data/lib/vagrant-libvirt/action/destroy_networks.rb +16 -9
- data/lib/vagrant-libvirt/action/read_state.rb +4 -4
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +3 -2
- data/lib/vagrant-libvirt/errors.rb +4 -0
- data/lib/vagrant-libvirt/version.rb +1 -1
- data/locales/en.yml +2 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 0.0.11 (Oct. 20, 2013)
|
2
|
+
|
3
|
+
* BUG FIX close #70 undefine machine id should be after all operations
|
4
|
+
* BUG FIX close #76 correct uri for different virtualizations
|
5
|
+
* BUG FIX close #72 possibility to give VMs a name
|
6
|
+
* Delete any snapshots when destroying domain (by Brian Pitts <brian@polibyte.com>)
|
7
|
+
* Add reload command (by Brian Pitts <brian@polibyte.com>)
|
8
|
+
* Update README (by <brett@apache.org>)
|
9
|
+
|
1
10
|
# 0.0.10 (Oct. 7, 2013)
|
2
11
|
|
3
12
|
* Delete files from destination to avoid confusions(by <skullzeek@gmail.com>)
|
data/Gemfile
CHANGED
@@ -4,9 +4,11 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem
|
7
|
+
gem 'rake'
|
8
|
+
gem 'rspec', '~> 2.13.0'
|
9
|
+
gem 'rspec-fire', require: 'rspec/fire'
|
10
|
+
gem 'rspec-spies', require: false
|
11
|
+
gem 'coveralls', require: false
|
12
|
+
gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git'
|
11
13
|
end
|
12
14
|
|
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# Vagrant Libvirt Provider
|
2
2
|
|
3
|
-
This is a [Vagrant](http://www.vagrantup.com) 1.
|
3
|
+
This is a [Vagrant](http://www.vagrantup.com) 1.3+ plugin that adds an
|
4
4
|
[Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to
|
5
5
|
control and provision machines via Libvirt toolkit.
|
6
6
|
|
7
|
-
**Note:** Actual version (0.0.
|
7
|
+
**Note:** Actual version (0.0.11) is still a development one. Feedback is
|
8
8
|
welcome and can help a lot :-)
|
9
9
|
|
10
|
-
## Features (Version 0.0.
|
10
|
+
## Features (Version 0.0.11)
|
11
11
|
|
12
12
|
* Controll local Libvirt hypervisors.
|
13
|
-
* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh` and `provision` commands.
|
13
|
+
* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload` and `provision` commands.
|
14
14
|
* Upload box image (qcow2 format) to Libvirt storage pool.
|
15
15
|
* Create volume as COW diff image for domains.
|
16
16
|
* Create private networks.
|
@@ -27,7 +27,7 @@ welcome and can help a lot :-)
|
|
27
27
|
|
28
28
|
## Installation
|
29
29
|
|
30
|
-
Install using standard [Vagrant 1.
|
30
|
+
Install using standard [Vagrant 1.3+](http://downloads.vagrantup.com) plugin installation methods. After
|
31
31
|
installing, `vagrant up` and specify the `libvirt` provider. An example is shown below.
|
32
32
|
|
33
33
|
```
|
data/Rakefile
CHANGED
data/lib/vagrant-libvirt.rb
CHANGED
@@ -3,10 +3,10 @@ require 'vagrant-libvirt/plugin'
|
|
3
3
|
|
4
4
|
module VagrantPlugins
|
5
5
|
module ProviderLibvirt
|
6
|
-
lib_path = Pathname.new(File.expand_path(
|
7
|
-
autoload :Action, lib_path.join(
|
8
|
-
autoload :Errors, lib_path.join(
|
9
|
-
autoload :Util, lib_path.join(
|
6
|
+
lib_path = Pathname.new(File.expand_path('../vagrant-libvirt', __FILE__))
|
7
|
+
autoload :Action, lib_path.join('action')
|
8
|
+
autoload :Errors, lib_path.join('errors')
|
9
|
+
autoload :Util, lib_path.join('util')
|
10
10
|
|
11
11
|
# Hold connection handler so there is no need to connect more times than
|
12
12
|
# one. This can be annoying when there are more machines to create, or when
|
@@ -23,7 +23,7 @@ module VagrantPlugins
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.source_root
|
26
|
-
@source_root ||= Pathname.new(File.expand_path(
|
26
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -92,6 +92,23 @@ module VagrantPlugins
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
# This is the action implements the reload command
|
96
|
+
# It uses the halt and start actions
|
97
|
+
def self.action_reload
|
98
|
+
Vagrant::Action::Builder.new.tap do |b|
|
99
|
+
b.use Call, IsCreated do |env, b2|
|
100
|
+
if !env[:result]
|
101
|
+
b2.use MessageNotCreated
|
102
|
+
next
|
103
|
+
end
|
104
|
+
|
105
|
+
b2.use ConfigValidate
|
106
|
+
b2.use action_halt
|
107
|
+
b2.use action_start
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
95
112
|
# This is the action that is primarily responsible for completely
|
96
113
|
# freeing the resources of the underlying virtual machine.
|
97
114
|
def self.action_destroy
|
@@ -251,6 +268,15 @@ module VagrantPlugins
|
|
251
268
|
|
252
269
|
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
253
270
|
autoload :ConnectLibvirt, action_root.join('connect_libvirt')
|
271
|
+
autoload :CreateDomain, action_root.join('create_domain')
|
272
|
+
autoload :CreateDomainVolume, action_root.join('create_domain_volume')
|
273
|
+
autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
|
274
|
+
autoload :CreateNetworks, action_root.join('create_networks')
|
275
|
+
autoload :DestroyDomain, action_root.join('destroy_domain')
|
276
|
+
autoload :DestroyNetworks, action_root.join('destroy_networks')
|
277
|
+
autoload :HaltDomain, action_root.join('halt_domain')
|
278
|
+
autoload :HandleBoxImage, action_root.join('handle_box_image')
|
279
|
+
autoload :HandleStoragePool, action_root.join('handle_storage_pool')
|
254
280
|
autoload :IsCreated, action_root.join('is_created')
|
255
281
|
autoload :IsRunning, action_root.join('is_running')
|
256
282
|
autoload :IsSuspended, action_root.join('is_suspended')
|
@@ -258,29 +284,20 @@ module VagrantPlugins
|
|
258
284
|
autoload :MessageNotCreated, action_root.join('message_not_created')
|
259
285
|
autoload :MessageNotRunning, action_root.join('message_not_running')
|
260
286
|
autoload :MessageNotSuspended, action_root.join('message_not_suspended')
|
261
|
-
autoload :
|
262
|
-
autoload :
|
263
|
-
autoload :
|
287
|
+
autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
|
288
|
+
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
289
|
+
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
|
290
|
+
autoload :ReadState, action_root.join('read_state')
|
291
|
+
autoload :ResumeDomain, action_root.join('resume_domain')
|
264
292
|
autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
|
265
|
-
autoload :
|
266
|
-
autoload :CreateDomain, action_root.join('create_domain')
|
267
|
-
autoload :CreateNetworks, action_root.join('create_networks')
|
268
|
-
autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
|
269
|
-
autoload :DestroyDomain, action_root.join('destroy_domain')
|
270
|
-
autoload :DestroyNetworks, action_root.join('destroy_networks')
|
293
|
+
autoload :ShareFolders, action_root.join('share_folders')
|
271
294
|
autoload :StartDomain, action_root.join('start_domain')
|
272
|
-
autoload :HaltDomain, action_root.join('halt_domain')
|
273
295
|
autoload :SuspendDomain, action_root.join('suspend_domain')
|
274
|
-
autoload :
|
275
|
-
autoload :ReadState, action_root.join('read_state')
|
276
|
-
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
|
296
|
+
autoload :SyncFolders, action_root.join('sync_folders')
|
277
297
|
autoload :TimedProvision, action_root.join('timed_provision')
|
278
298
|
autoload :WaitTillUp, action_root.join('wait_till_up')
|
279
|
-
autoload :SyncFolders, action_root.join('sync_folders')
|
280
299
|
autoload :SSHRun, 'vagrant/action/builtin/ssh_run'
|
281
|
-
autoload :
|
282
|
-
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
283
|
-
autoload :ShareFolders, action_root.join('share_folders')
|
300
|
+
autoload :HandleBoxUrl, 'vagrant/action/builtin/handle_box_url'
|
284
301
|
end
|
285
302
|
end
|
286
303
|
end
|
@@ -24,6 +24,17 @@ module VagrantPlugins
|
|
24
24
|
|
25
25
|
# Setup connection uri.
|
26
26
|
uri = config.driver
|
27
|
+
virt_path = case uri
|
28
|
+
when 'qemu', 'openvz', 'uml', 'phyp', 'parallels'
|
29
|
+
'/system'
|
30
|
+
when 'xen', 'esx'
|
31
|
+
'/'
|
32
|
+
when 'vbox', 'vmwarews', 'hyperv'
|
33
|
+
'/session'
|
34
|
+
else
|
35
|
+
raise "Require specify driver #{uri}"
|
36
|
+
end
|
37
|
+
|
27
38
|
if config.connect_via_ssh
|
28
39
|
uri << '+ssh://'
|
29
40
|
if config.username
|
@@ -40,7 +51,8 @@ module VagrantPlugins
|
|
40
51
|
uri << config.host if config.host
|
41
52
|
end
|
42
53
|
|
43
|
-
uri <<
|
54
|
+
uri << virt_path
|
55
|
+
uri << '?no_verify=1'
|
44
56
|
# set ssh key for access to libvirt host
|
45
57
|
home_dir = `echo ${HOME}`.chomp
|
46
58
|
uri << "&keyfile=#{home_dir}/.ssh/id_rsa"
|
@@ -5,17 +5,30 @@ module VagrantPlugins
|
|
5
5
|
module Action
|
6
6
|
class DestroyDomain
|
7
7
|
def initialize(app, env)
|
8
|
-
@logger = Log4r::Logger.new(
|
8
|
+
@logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_domain')
|
9
9
|
@app = app
|
10
10
|
end
|
11
11
|
|
12
12
|
def call(env)
|
13
13
|
# Destroy the server, remove the tracking ID
|
14
|
-
env[:ui].info(I18n.t(
|
14
|
+
env[:ui].info(I18n.t('vagrant_libvirt.destroy_domain'))
|
15
|
+
|
16
|
+
# Must delete any snapshots before domain can be destroyed
|
17
|
+
# Fog libvirt currently doesn't support snapshots. Use
|
18
|
+
# ruby-libvirt client directly. Note this is racy, see
|
19
|
+
# http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames
|
20
|
+
libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid(env[:machine].id)
|
21
|
+
libvirt_domain.list_snapshots.each do |name|
|
22
|
+
@logger.info("Deleting snapshot '#{name}'")
|
23
|
+
begin
|
24
|
+
libvirt_domain.lookup_snapshot_by_name(name).delete
|
25
|
+
rescue => e
|
26
|
+
raise Errors::DeleteSnapshotError, error_message: e.message
|
27
|
+
end
|
28
|
+
end
|
15
29
|
|
16
30
|
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
|
17
|
-
domain.destroy(:
|
18
|
-
env[:machine].id = nil
|
31
|
+
domain.destroy(destroy_volumes: true)
|
19
32
|
|
20
33
|
@app.call(env)
|
21
34
|
end
|
@@ -9,7 +9,7 @@ module VagrantPlugins
|
|
9
9
|
class DestroyNetworks
|
10
10
|
|
11
11
|
def initialize(app, env)
|
12
|
-
@logger = Log4r::Logger.new(
|
12
|
+
@logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_networks')
|
13
13
|
@app = app
|
14
14
|
end
|
15
15
|
|
@@ -18,45 +18,51 @@ module VagrantPlugins
|
|
18
18
|
# data directory, created_networks file holds UUIDs of each network.
|
19
19
|
created_networks_file = env[:machine].data_dir + 'created_networks'
|
20
20
|
|
21
|
+
@logger.info 'Attepmt destroy network'
|
21
22
|
# If created_networks file doesn't exist, there are no networks we
|
22
23
|
# need to remove.
|
23
|
-
|
24
|
+
unless File.exist?(created_networks_file)
|
25
|
+
env[:machine].id = nil
|
26
|
+
return @app.call(env)
|
27
|
+
end
|
28
|
+
|
29
|
+
@logger.info 'file with network exists'
|
24
30
|
|
25
31
|
# Iterate over each created network UUID and try to remove it.
|
26
32
|
created_networks = []
|
27
33
|
file = File.open(created_networks_file, 'r')
|
28
34
|
file.readlines.each do |network_uuid|
|
35
|
+
@logger.info network_uuid
|
29
36
|
begin
|
30
37
|
libvirt_network = env[:libvirt_compute].client.lookup_network_by_uuid(
|
31
38
|
network_uuid)
|
32
39
|
rescue
|
40
|
+
raise network_uuid
|
33
41
|
next
|
34
42
|
end
|
35
43
|
|
36
44
|
# Maybe network doesn't exist anymore.
|
37
|
-
next
|
45
|
+
next unless libvirt_network
|
38
46
|
|
39
47
|
# Skip removing if network has still active connections.
|
40
48
|
xml = Nokogiri::XML(libvirt_network.xml_desc)
|
41
49
|
connections = xml.xpath('/network/@connections').first
|
50
|
+
@logger.info connections
|
42
51
|
if connections != nil
|
43
52
|
created_networks << network_uuid
|
44
53
|
next
|
45
54
|
end
|
46
55
|
|
47
56
|
# Shutdown network first.
|
48
|
-
|
49
|
-
libvirt_network.destroy
|
50
|
-
rescue => e
|
51
|
-
end
|
57
|
+
libvirt_network.destroy
|
52
58
|
|
53
59
|
# Undefine network.
|
54
60
|
begin
|
55
61
|
libvirt_network.undefine
|
56
62
|
rescue => e
|
57
63
|
raise Error::DestroyNetworkError,
|
58
|
-
:
|
59
|
-
:
|
64
|
+
network_name: libvirt_network.name,
|
65
|
+
error_message: e.message
|
60
66
|
end
|
61
67
|
end
|
62
68
|
file.close
|
@@ -72,6 +78,7 @@ module VagrantPlugins
|
|
72
78
|
File.delete(created_networks_file)
|
73
79
|
end
|
74
80
|
|
81
|
+
env[:machine].id = nil
|
75
82
|
@app.call(env)
|
76
83
|
end
|
77
84
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'log4r'
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module ProviderLibvirt
|
@@ -8,7 +8,7 @@ module VagrantPlugins
|
|
8
8
|
class ReadState
|
9
9
|
def initialize(app, env)
|
10
10
|
@app = app
|
11
|
-
@logger = Log4r::Logger.new(
|
11
|
+
@logger = Log4r::Logger.new('vagrant_libvirt::action::read_state')
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
@@ -21,9 +21,9 @@ module VagrantPlugins
|
|
21
21
|
|
22
22
|
# Find the machine
|
23
23
|
server = libvirt.servers.get(machine.id)
|
24
|
-
if server.nil? || [:
|
24
|
+
if server.nil? || [:'shutting-down', :terminated].include?(server.state.to_sym)
|
25
25
|
# The machine can't be found
|
26
|
-
@logger.info(
|
26
|
+
@logger.info('Machine not found or terminated, assuming it got destroyed.')
|
27
27
|
machine.id = nil
|
28
28
|
return :not_created
|
29
29
|
end
|
@@ -11,8 +11,9 @@ module VagrantPlugins
|
|
11
11
|
def call(env)
|
12
12
|
require 'securerandom'
|
13
13
|
env[:domain_name] = env[:root_path].basename.to_s.dup
|
14
|
-
env[:domain_name].gsub!(/[^-a-z0-9_]/i,
|
15
|
-
env[:domain_name] <<
|
14
|
+
env[:domain_name].gsub!(/[^-a-z0-9_]/i, '')
|
15
|
+
env[:domain_name] << '_'
|
16
|
+
env[:domain_name] << env[:machine].name.to_s
|
16
17
|
|
17
18
|
# Check if the domain name is not already taken
|
18
19
|
domain = ProviderLibvirt::Util::Collection.find_matching(
|
data/locales/en.yml
CHANGED
@@ -115,6 +115,8 @@ en:
|
|
115
115
|
Error while setting up autostart on network: %{error_message}.
|
116
116
|
destroy_network_error: |-
|
117
117
|
Error while removing network %{network_name}. %{error_message}.
|
118
|
+
delete_snapshot_error: |-
|
119
|
+
Error while deleting snapshot: %{error_message}.
|
118
120
|
|
119
121
|
states:
|
120
122
|
short_paused: |-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-libvirt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fog
|