vagrant-libvirt 0.0.28 → 0.0.29
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.
- checksums.yaml +13 -5
- data/README.md +18 -4
- data/lib/vagrant-libvirt/action.rb +9 -11
- data/lib/vagrant-libvirt/action/create_domain.rb +1 -0
- data/lib/vagrant-libvirt/action/destroy_domain.rb +24 -7
- data/lib/vagrant-libvirt/action/package_domain.rb +83 -0
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +43 -23
- data/lib/vagrant-libvirt/action/read_ssh_info.rb +2 -2
- data/lib/vagrant-libvirt/cap/synced_folder.rb +28 -39
- data/lib/vagrant-libvirt/config.rb +4 -1
- data/lib/vagrant-libvirt/templates/domain.xml.erb +13 -5
- data/lib/vagrant-libvirt/templates/filesystem.xml.erb +2 -2
- data/lib/vagrant-libvirt/version.rb +1 -1
- data/tools/create_box.sh +1 -1
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWQxNDI3NzdkZmM1ZTBlNjZjOWQyODk4MmU1Mjk3YzEwOWNjYjhkOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGEzYjM1YTYyZjE1ZGUxNDlhYzIzMDZhMDRjN2VhNjFlN2FjZjA5Yg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Nzc4ZTMyODA1ZmFjNjNiZTU5ODU1MzBlN2FiODQ2YmFmMDRmMTViN2VjY2Vl
|
10
|
+
NTNjZDkxYTE0NjdjOGNhMWIxNjUxN2Y5YzQ0MzZmN2I0ZThmMTVkMTNmNTI2
|
11
|
+
YzgyOTQ3ZWVkYTNiZjhiYTVlMzVjMjI0NDA2NmZkMWQ5MDQ5MTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmYzNWExNWI2NjdkNGM4ZjliMTc4YzFmOWU0N2UyYjY0YjkyZGRlN2EzYmMw
|
14
|
+
NGI5Yjk4NjY5YTVhYzQ2NjhlYmNhYzhiZmQwMGE5ZDY2ZDc4ODNmOTAyMGQx
|
15
|
+
MGFlNjE4ZDgxM2ZlOGIzOWU5ODZiOGI2NjAyOWVmYTJiMTU0ZWI=
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ welcome and can help a lot :-)
|
|
10
10
|
## Features
|
11
11
|
|
12
12
|
* Control local Libvirt hypervisors.
|
13
|
-
* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload` and `provision` commands.
|
13
|
+
* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh`, `reload`, `package` 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.
|
@@ -51,7 +51,14 @@ $ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev
|
|
51
51
|
|
52
52
|
In RedHat, Centos, Fedora, ...
|
53
53
|
```
|
54
|
-
# yum install libxslt-devel libxml2-devel libvirt-devel
|
54
|
+
# yum install libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c
|
55
|
+
```
|
56
|
+
|
57
|
+
If have problem with installation - check your linker. It should be ld.gold:
|
58
|
+
```
|
59
|
+
sudo alternatives --set ld /usr/bin/ld.gold
|
60
|
+
# OR
|
61
|
+
sudo ln -fs /usr/bin/ld.gold /usr/bin/ld
|
55
62
|
```
|
56
63
|
|
57
64
|
## Vagrant Project Preparation
|
@@ -64,7 +71,7 @@ a `config.vm.provider` block. So first, add Libvirt box using any name you
|
|
64
71
|
want. This is just an example of Libvirt CentOS 6.4 box available:
|
65
72
|
|
66
73
|
```
|
67
|
-
vagrant box add
|
74
|
+
vagrant box add fedora21 http://citozin.com/fedora21.box
|
68
75
|
# or
|
69
76
|
vagrant box add centos64 http://citozin.com/centos64.box
|
70
77
|
```
|
@@ -162,6 +169,7 @@ end
|
|
162
169
|
* `keymap` - Set keymap for vm. default: en-us
|
163
170
|
* `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216.
|
164
171
|
* `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines.
|
172
|
+
* `machine_arch` - Sets machine architecture. This helps libvirt to determine the correct emulator type. Possible values depend on your version of qemu. For possible values, see which emulator executable `qemu-system-*` your system provides. Common examples are `aarch64`, `alpha`, `arm`, `cris`, `i386`, `lm32`, `m68k`, `microblaze`, `microblazeel`, `mips`, `mips64`, `mips64el`, `mipsel`, `moxie`, `or32`, `ppc`, `ppc64`, `ppcemb`, `s390x`, `sh4`, `sh4eb`, `sparc`, `sparc64`, `tricore`, `unicore32`, `x86_64`, `xtensa`, `xtensaeb`.
|
165
173
|
|
166
174
|
|
167
175
|
Specific domain settings can be set for each domain separately in multi-VM
|
@@ -369,6 +377,13 @@ it an setting the type, e.g.
|
|
369
377
|
|
370
378
|
config.vm.synced_folder './', '/vagrant', type: 'rsync'
|
371
379
|
|
380
|
+
or
|
381
|
+
|
382
|
+
config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant"
|
383
|
+
|
384
|
+
**SECURITY NOTE:** for remote libvirt, nfs synced folders requires a bridged public network interface and you must connect to libvirt via ssh.
|
385
|
+
|
386
|
+
|
372
387
|
## Customized Graphics
|
373
388
|
|
374
389
|
vagrant-libvirt supports customizing the display and video settings of the
|
@@ -448,4 +463,3 @@ IMPORTANT NOTE: bundle is crucial. You need to use bundled vagrant.
|
|
448
463
|
3. Commit your changes (`git commit -am 'Add some feature'`).
|
449
464
|
4. Push to the branch (`git push origin my-new-feature`).
|
450
465
|
5. Create new Pull Request.
|
451
|
-
|
@@ -31,23 +31,18 @@ module VagrantPlugins
|
|
31
31
|
b2.use CreateDomain
|
32
32
|
|
33
33
|
b2.use Provision
|
34
|
-
b2.use CreateNetworks
|
35
|
-
b2.use CreateNetworkInterfaces
|
36
|
-
|
37
34
|
b2.use PrepareNFSValidIds
|
38
35
|
b2.use SyncedFolderCleanup
|
39
36
|
b2.use SyncedFolders
|
40
|
-
|
41
|
-
b2.use
|
42
|
-
b2.use
|
37
|
+
b2.use PrepareNFSSettings
|
38
|
+
b2.use ShareFolders
|
39
|
+
b2.use CreateNetworks
|
40
|
+
b2.use CreateNetworkInterfaces
|
43
41
|
|
44
42
|
b2.use StartDomain
|
45
43
|
b2.use WaitTillUp
|
46
44
|
|
47
45
|
b2.use ForwardPorts
|
48
|
-
|
49
|
-
b2.use PrepareNFSSettings
|
50
|
-
b2.use ShareFolders
|
51
46
|
b2.use SetHostname
|
52
47
|
# b2.use SyncFolders
|
53
48
|
else
|
@@ -147,8 +142,10 @@ module VagrantPlugins
|
|
147
142
|
|
148
143
|
# not implemented and looks like not require
|
149
144
|
def self.action_package
|
150
|
-
|
151
|
-
|
145
|
+
Vagrant::Action::Builder.new.tap do |b|
|
146
|
+
b.use ConfigValidate
|
147
|
+
b.use ConnectLibvirt
|
148
|
+
b.use PackageDomain
|
152
149
|
end
|
153
150
|
end
|
154
151
|
|
@@ -320,6 +317,7 @@ module VagrantPlugins
|
|
320
317
|
|
321
318
|
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
322
319
|
autoload :ConnectLibvirt, action_root.join('connect_libvirt')
|
320
|
+
autoload :PackageDomain, action_root.join('package_domain')
|
323
321
|
autoload :CreateDomain, action_root.join('create_domain')
|
324
322
|
autoload :CreateDomainVolume, action_root.join('create_domain_volume')
|
325
323
|
autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
|
@@ -4,7 +4,7 @@ module VagrantPlugins
|
|
4
4
|
module ProviderLibvirt
|
5
5
|
module Action
|
6
6
|
class DestroyDomain
|
7
|
-
def initialize(app,
|
7
|
+
def initialize(app, _env)
|
8
8
|
@logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_domain')
|
9
9
|
@app = app
|
10
10
|
end
|
@@ -17,7 +17,8 @@ module VagrantPlugins
|
|
17
17
|
# Fog libvirt currently doesn't support snapshots. Use
|
18
18
|
# ruby-libvirt client directly. Note this is racy, see
|
19
19
|
# http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames
|
20
|
-
libvirt_domain =
|
20
|
+
libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid(
|
21
|
+
env[:machine].id)
|
21
22
|
libvirt_domain.list_snapshots.each do |name|
|
22
23
|
@logger.info("Deleting snapshot '#{name}'")
|
23
24
|
begin
|
@@ -36,14 +37,30 @@ module VagrantPlugins
|
|
36
37
|
domain.destroy(destroy_volumes: false)
|
37
38
|
|
38
39
|
env[:machine].provider_config.disks.each do |disk|
|
39
|
-
|
40
|
-
|
40
|
+
# shared disks remove only manualy or ???
|
41
|
+
next if disk[:allow_existing]
|
42
|
+
diskname = libvirt_domain.name + '-' + disk[:device] + '.' + disk[:type].to_s
|
41
43
|
# diskname is uniq
|
42
|
-
|
44
|
+
libvirt_disk = domain.volumes.select do |x|
|
45
|
+
x.name == diskname
|
46
|
+
end.first
|
47
|
+
if libvirt_disk
|
48
|
+
libvirt_disk.destroy
|
49
|
+
elsif disk[:path]
|
50
|
+
poolname = env[:machine].provider_config.storage_pool_name
|
51
|
+
libvirt_disk = domain.volumes.select do |x|
|
52
|
+
# FIXME can remove pool/target.img and pool/123/target.img
|
53
|
+
x.path =~ /\/#{disk[:path]}$/ && x.pool_name == poolname
|
54
|
+
end.first
|
55
|
+
libvirt_disk.destroy if libvirt_disk
|
56
|
+
end
|
43
57
|
end
|
44
58
|
|
45
|
-
#remove root storage
|
46
|
-
|
59
|
+
# remove root storage
|
60
|
+
root_disk = domain.volumes.select do |x|
|
61
|
+
x.name == libvirt_domain.name + '.img'
|
62
|
+
end.first
|
63
|
+
root_disk.destroy if root_disk
|
47
64
|
end
|
48
65
|
|
49
66
|
@app.call(env)
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderLibvirt
|
5
|
+
module Action
|
6
|
+
# Action for create new box for libvirt provider
|
7
|
+
class PackageDomain
|
8
|
+
def initialize(app, env)
|
9
|
+
@logger = Log4r::Logger.new('vagrant_libvirt::action::package_domain')
|
10
|
+
@app = app
|
11
|
+
env['package.files'] ||= {}
|
12
|
+
env['package.output'] ||= 'package.box'
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:ui].info(I18n.t('vagrant_libvirt.package_domain'))
|
17
|
+
libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid(
|
18
|
+
env[:machine].id)
|
19
|
+
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
|
20
|
+
root_disk = domain.volumes.select do |x|
|
21
|
+
x.name == libvirt_domain.name + '.img'
|
22
|
+
end.first
|
23
|
+
boxname = env['package.output']
|
24
|
+
raise "#{boxname}: Already exists" if File.exists?(boxname)
|
25
|
+
@tmp_dir = Dir.pwd + '/_tmp_package'
|
26
|
+
@tmp_img = @tmp_dir + '/box.img'
|
27
|
+
Dir.mkdir(@tmp_dir)
|
28
|
+
if File.readable?(root_disk.path)
|
29
|
+
backing = `qemu-img info "#{root_disk.path}" | grep 'backing file:' | cut -d ':' -f2`.chomp
|
30
|
+
else
|
31
|
+
env[:ui].error("Require set read access to #{root_disk.path}. sudo chmod a+r #{root_disk.path}")
|
32
|
+
FileUtils.rm_rf(@tmp_dir)
|
33
|
+
raise 'Have no access'
|
34
|
+
end
|
35
|
+
env[:ui].info('Image has backing image, copying image and rebasing ...')
|
36
|
+
FileUtils.cp(root_disk.path, @tmp_img)
|
37
|
+
`qemu-img rebase -p -b "" #{@tmp_img}`
|
38
|
+
# remove hw association with interface
|
39
|
+
# working for centos with lvs default disks
|
40
|
+
`virt-sysprep --no-logfile -a #{@tmp_img} `
|
41
|
+
Dir.chdir(@tmp_dir)
|
42
|
+
img_size = `qemu-img info #{@tmp_img} | grep 'virtual size' | awk '{print $3;}' | tr -d 'G'`.chomp
|
43
|
+
File.write(@tmp_dir + '/metadata.json', metadata_content(img_size))
|
44
|
+
File.write(@tmp_dir + '/Vagrantfile',vagrantfile_content)
|
45
|
+
assebmle_box(boxname)
|
46
|
+
FileUtils.mv(@tmp_dir + '/' + boxname, '../' + boxname)
|
47
|
+
FileUtils.rm_rf(@tmp_dir)
|
48
|
+
env[:ui].info('Box created')
|
49
|
+
env[:ui].info('You can now add the box:')
|
50
|
+
env[:ui].info("vagrant box add #{boxname} --name any_comfortable_name")
|
51
|
+
@app.call(env)
|
52
|
+
end
|
53
|
+
|
54
|
+
def assebmle_box(boxname)
|
55
|
+
`tar cvzf "#{boxname}" --totals ./metadata.json ./Vagrantfile ./box.img`
|
56
|
+
end
|
57
|
+
|
58
|
+
def vagrantfile_content
|
59
|
+
<<-EOF
|
60
|
+
Vagrant.configure("2") do |config|
|
61
|
+
config.vm.provider :libvirt do |libvirt|
|
62
|
+
libvirt.driver = "kvm"
|
63
|
+
libvirt.host = ""
|
64
|
+
libvirt.connect_via_ssh = false
|
65
|
+
libvirt.storage_pool_name = "default"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
EOF
|
69
|
+
end
|
70
|
+
|
71
|
+
def metadata_content(filesize)
|
72
|
+
<<-EOF
|
73
|
+
{
|
74
|
+
"provider": "libvirt",
|
75
|
+
"format": "qcow2",
|
76
|
+
"virtual_size": #{filesize}
|
77
|
+
}
|
78
|
+
EOF
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'socket'
|
3
|
+
require 'timeout'
|
4
|
+
|
2
5
|
module VagrantPlugins
|
3
6
|
module ProviderLibvirt
|
4
7
|
module Action
|
5
8
|
class PrepareNFSSettings
|
6
9
|
include Vagrant::Action::Builtin::MixinSyncedFolders
|
7
|
-
|
10
|
+
|
8
11
|
def initialize(app,env)
|
9
12
|
@app = app
|
10
13
|
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
|
@@ -16,8 +19,8 @@ module VagrantPlugins
|
|
16
19
|
|
17
20
|
if using_nfs?
|
18
21
|
@logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
|
19
|
-
env[:nfs_host_ip] = read_host_ip(env[:machine]
|
20
|
-
env[:nfs_machine_ip] = env[:machine]
|
22
|
+
env[:nfs_host_ip] = read_host_ip(env[:machine])
|
23
|
+
env[:nfs_machine_ip] = read_machine_ip(env[:machine])
|
21
24
|
|
22
25
|
@logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}")
|
23
26
|
|
@@ -32,37 +35,54 @@ module VagrantPlugins
|
|
32
35
|
!!synced_folders(@machine)[:nfs]
|
33
36
|
end
|
34
37
|
|
35
|
-
# Returns the IP address of the
|
38
|
+
# Returns the IP address of the host
|
36
39
|
#
|
37
40
|
# @param [Machine] machine
|
38
41
|
# @return [String]
|
39
|
-
def read_host_ip(machine
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
domain = env[:libvirt_compute].servers.get(machine.id.to_s)
|
45
|
-
xml=Nokogiri::XML(domain.to_xml)
|
46
|
-
networkname = xml.xpath('/domain/devices/interface/source').first.attributes['network'].value.to_s
|
47
|
-
@logger.info("Using network named #{networkname}")
|
48
|
-
net = env[:libvirt_compute].list_networks.find {|netw| netw[:name] == networkname}
|
42
|
+
def read_host_ip(machine)
|
43
|
+
UDPSocket.open do |s|
|
44
|
+
s.connect(machine.ssh_info[:host], 1)
|
45
|
+
s.addr.last
|
49
46
|
end
|
50
|
-
# FIXME better implement by libvirt xml parsing
|
51
|
-
`ip addr show | grep -A 2 #{net[:bridge_name]} | grep -i 'inet ' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1`.chomp
|
52
47
|
end
|
53
48
|
|
54
|
-
# Returns the IP address of the guest
|
55
|
-
# enabled host only network.
|
49
|
+
# Returns the IP address of the guest
|
56
50
|
#
|
51
|
+
# @param [Machine] machine
|
57
52
|
# @return [String]
|
58
53
|
def read_machine_ip(machine)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
# check host only ip
|
55
|
+
ssh_host = machine.ssh_info[:host]
|
56
|
+
return ssh_host if ping(ssh_host)
|
57
|
+
|
58
|
+
# check other ips
|
59
|
+
command = "ip addr show | grep -i 'inet ' | grep -v '127.0.0.1' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1"
|
60
|
+
result = ""
|
61
|
+
machine.communicate.execute(command) do |type, data|
|
62
|
+
result << data if type == :stdout
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
ips = result.chomp.split("\n")
|
66
|
+
@logger.info("guest IPs: #{ips.join(', ')}")
|
67
|
+
ips.each do |ip|
|
68
|
+
next if ip == ssh_host
|
69
|
+
return ip if ping(ip)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# Check if we can open a connection to the host
|
76
|
+
def ping(host, timeout = 3)
|
77
|
+
timeout(timeout) do
|
78
|
+
s = TCPSocket.new(host, 'echo')
|
79
|
+
s.close
|
80
|
+
end
|
81
|
+
true
|
82
|
+
rescue Errno::ECONNREFUSED
|
83
|
+
true
|
84
|
+
rescue Timeout::Error, StandardError
|
85
|
+
false
|
66
86
|
end
|
67
87
|
end
|
68
88
|
end
|
@@ -48,8 +48,8 @@ module VagrantPlugins
|
|
48
48
|
:forward_agent => machine.config.ssh.forward_agent,
|
49
49
|
:forward_x11 => machine.config.ssh.forward_x11,
|
50
50
|
}
|
51
|
-
|
52
|
-
ssh_info[:proxy_command] = "ssh '#{machine.provider_config.host}' -l '#{machine.provider_config.username}' nc %h %p" if machine.provider_config.connect_via_ssh
|
51
|
+
|
52
|
+
ssh_info[:proxy_command] = "ssh '#{machine.provider_config.host}' -l '#{machine.provider_config.username}' -i '#{machine.provider_config.id_ssh_key_file}' nc %h %p" if machine.provider_config.connect_via_ssh
|
53
53
|
|
54
54
|
ssh_info
|
55
55
|
end
|
@@ -1,74 +1,65 @@
|
|
1
|
-
require
|
1
|
+
require 'log4r'
|
2
2
|
require 'ostruct'
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
|
-
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require "vagrant-libvirt/errors"
|
5
|
+
require 'vagrant/util/subprocess'
|
6
|
+
require 'vagrant/errors'
|
7
|
+
require 'vagrant-libvirt/errors'
|
9
8
|
# require_relative "helper"
|
10
9
|
|
11
10
|
module VagrantPlugins
|
12
11
|
module SyncedFolder9p
|
13
|
-
class SyncedFolder < Vagrant.plugin(
|
12
|
+
class SyncedFolder < Vagrant.plugin('2', :synced_folder)
|
14
13
|
include Vagrant::Util
|
15
14
|
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
16
15
|
|
17
16
|
def initialize(*args)
|
18
17
|
super
|
19
|
-
|
20
|
-
@logger = Log4r::Logger.new("vagrant_libvirt::synced_folders::9p")
|
18
|
+
@logger = Log4r::Logger.new('vagrant_libvirt::synced_folders::9p')
|
21
19
|
end
|
22
20
|
|
23
|
-
def usable?(machine, raise_error=false)
|
21
|
+
def usable?(machine, raise_error = false)
|
24
22
|
# bail now if not using libvirt since checking version would throw error
|
25
23
|
return false unless machine.provider_name == :libvirt
|
26
24
|
|
27
25
|
# <filesystem/> support in device attach/detach introduced in 1.2.2
|
28
26
|
# version number format is major * 1,000,000 + minor * 1,000 + release
|
29
27
|
libvirt_version = ProviderLibvirt.libvirt_connection.client.libversion
|
30
|
-
|
31
|
-
return true
|
32
|
-
else
|
33
|
-
return false
|
34
|
-
end
|
28
|
+
libvirt_version >= 1_002_002
|
35
29
|
end
|
36
30
|
|
37
|
-
def prepare(machine, folders,
|
38
|
-
|
39
|
-
raise Vagrant::Errors::Error("No libvirt connection") if ProviderLibvirt.libvirt_connection.nil?
|
40
|
-
|
31
|
+
def prepare(machine, folders, _opts)
|
32
|
+
raise Vagrant::Errors::Error('No libvirt connection') if ProviderLibvirt.libvirt_connection.nil?
|
41
33
|
@conn = ProviderLibvirt.libvirt_connection.client
|
42
34
|
|
43
35
|
begin
|
44
36
|
# loop through folders
|
45
37
|
folders.each do |id, folder_opts|
|
46
|
-
folder_opts.merge!({
|
47
|
-
|
38
|
+
folder_opts.merge!({ target: id,
|
39
|
+
accessmode: 'passthrough',
|
40
|
+
readonly: nil }) { |_k, ov, _nv| ov }
|
48
41
|
machine.ui.info "================\nMachine id: #{machine.id}\nShould be mounting folders\n #{id}, opts: #{folder_opts}"
|
49
|
-
|
50
|
-
xml = to_xml('filesystem', folder_opts )
|
42
|
+
xml = to_xml('filesystem', folder_opts)
|
51
43
|
# puts "<<<<< XML:\n #{xml}\n >>>>>"
|
52
44
|
@conn.lookup_domain_by_uuid(machine.id).attach_device(xml, 0)
|
53
|
-
|
54
|
-
end
|
45
|
+
end
|
55
46
|
rescue => e
|
56
47
|
machine.ui.error("could not attach device because: #{e}")
|
57
|
-
raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError
|
48
|
+
raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError,
|
49
|
+
error_message: e.message
|
58
50
|
end
|
59
51
|
end
|
60
52
|
|
61
|
-
|
62
53
|
# TODO once up, mount folders
|
63
54
|
def enable(machine, folders, _opts)
|
64
55
|
# Go through each folder and mount
|
65
|
-
machine.ui.info(
|
56
|
+
machine.ui.info('mounting p9 share in guest')
|
66
57
|
# Only mount folders that have a guest path specified.
|
67
58
|
mount_folders = {}
|
68
59
|
folders.each do |id, opts|
|
69
60
|
mount_folders[id] = opts.dup if opts[:guestpath]
|
70
61
|
# merge common options if not given
|
71
|
-
mount_folders[id].merge!(:
|
62
|
+
mount_folders[id].merge!(version: '9p2000.L') { |_k, ov, _nv| ov }
|
72
63
|
end
|
73
64
|
# Mount the actual folder
|
74
65
|
machine.guest.capability(
|
@@ -76,27 +67,25 @@ module VagrantPlugins
|
|
76
67
|
end
|
77
68
|
|
78
69
|
def cleanup(machine, _opts)
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
if ProviderLibvirt.libvirt_connection.nil?
|
71
|
+
raise Vagrant::Errors::Error('No libvirt connection')
|
72
|
+
end
|
82
73
|
@conn = ProviderLibvirt.libvirt_connection.client
|
83
|
-
|
84
74
|
begin
|
85
|
-
if machine.id && machine.id !=
|
75
|
+
if machine.id && machine.id != ''
|
86
76
|
dom = @conn.lookup_domain_by_uuid(machine.id)
|
87
|
-
Nokogiri::XML(dom.xml_desc).xpath(
|
77
|
+
Nokogiri::XML(dom.xml_desc).xpath(
|
78
|
+
'/domain/devices/filesystem').each do |xml|
|
88
79
|
dom.detach_device(xml.to_s)
|
89
|
-
|
90
|
-
machine.ui.info "Cleaned up shared folders"
|
80
|
+
machine.ui.info 'Cleaned up shared folders'
|
91
81
|
end
|
92
82
|
end
|
93
83
|
rescue => e
|
94
84
|
machine.ui.error("could not detach device because: #{e}")
|
95
|
-
raise VagrantPlugins::ProviderLibvirt::Errors::DetachDeviceError
|
85
|
+
raise VagrantPlugins::ProviderLibvirt::Errors::DetachDeviceError,
|
86
|
+
error_message: e.message
|
96
87
|
end
|
97
|
-
|
98
88
|
end
|
99
|
-
|
100
89
|
end
|
101
90
|
end
|
102
91
|
end
|
@@ -56,6 +56,7 @@ module VagrantPlugins
|
|
56
56
|
attr_accessor :cpus
|
57
57
|
attr_accessor :cpu_mode
|
58
58
|
attr_accessor :machine_type
|
59
|
+
attr_accessor :machine_arch
|
59
60
|
attr_accessor :disk_bus
|
60
61
|
attr_accessor :nic_model_type
|
61
62
|
attr_accessor :nested
|
@@ -95,6 +96,7 @@ module VagrantPlugins
|
|
95
96
|
@cpus = UNSET_VALUE
|
96
97
|
@cpu_mode = UNSET_VALUE
|
97
98
|
@machine_type = UNSET_VALUE
|
99
|
+
@machine_arch = UNSET_VALUE
|
98
100
|
@disk_bus = UNSET_VALUE
|
99
101
|
@nic_model_type = UNSET_VALUE
|
100
102
|
@nested = UNSET_VALUE
|
@@ -248,7 +250,7 @@ module VagrantPlugins
|
|
248
250
|
# set ssh key for access to libvirt host
|
249
251
|
uri << "\&keyfile="
|
250
252
|
# if no slash, prepend $HOME/.ssh/
|
251
|
-
|
253
|
+
@id_ssh_key_file.prepend("#{`echo ${HOME}`.chomp}/.ssh/") if @id_ssh_key_file !~ /\A\//
|
252
254
|
uri << @id_ssh_key_file
|
253
255
|
end
|
254
256
|
# set path to libvirt socket
|
@@ -277,6 +279,7 @@ module VagrantPlugins
|
|
277
279
|
@cpus = 1 if @cpus == UNSET_VALUE
|
278
280
|
@cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
|
279
281
|
@machine_type = nil if @machine_type == UNSET_VALUE
|
282
|
+
@machine_arch = nil if @machine_arch == UNSET_VALUE
|
280
283
|
@disk_bus = 'virtio' if @disk_bus == UNSET_VALUE
|
281
284
|
@nic_model_type = 'virtio' if @nic_model_type == UNSET_VALUE
|
282
285
|
@nested = false if @nested == UNSET_VALUE
|
@@ -14,11 +14,19 @@
|
|
14
14
|
<% end %>
|
15
15
|
|
16
16
|
<os>
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
<% if @machine_type %>
|
18
|
+
<% if @machine_arch %>
|
19
|
+
<type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
|
20
|
+
<% else %>
|
21
|
+
<type machine='<%= @machine_type %>'>hvm</type>
|
22
|
+
<% end %>
|
23
|
+
<% else %>
|
24
|
+
<% if @machine_arch %>
|
25
|
+
<type arch='<%= @machine_arch %>'>hvm</type>
|
26
|
+
<% else %>
|
27
|
+
<type>hvm</type>
|
28
|
+
<% end %>
|
29
|
+
<% end %>
|
22
30
|
<boot dev='hd'/>
|
23
31
|
<kernel><%= @kernel %></kernel>
|
24
32
|
<initrd><%= @initrd %></initrd>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<filesystem type='mount' accessmode='<%= accessmode %>'>
|
2
2
|
<driver type='path' wrpolicy='immediate'/>
|
3
3
|
<source dir='<%= hostpath %>'/>
|
4
|
-
<target dir='<%=
|
4
|
+
<target dir='<%= target %>'/>
|
5
5
|
<% unless readonly.nil? %>
|
6
6
|
<readonly />
|
7
7
|
<% end %>
|
8
|
-
</filesystem>
|
8
|
+
</filesystem>
|
data/tools/create_box.sh
CHANGED
@@ -60,7 +60,7 @@ TMP_IMG="$TMP_DIR/box.img"
|
|
60
60
|
|
61
61
|
mkdir -p "$TMP_DIR"
|
62
62
|
|
63
|
-
[[ ! -
|
63
|
+
[[ ! -r "$IMG" ]] && error "'$IMG': Permission denied"
|
64
64
|
|
65
65
|
# We move / copy (when the image has master) the image to the tempdir
|
66
66
|
# ensure that it's moved back / removed again
|
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.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Stanek
|
@@ -10,90 +10,90 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-05-
|
13
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec-core
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 2.12.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 2.12.2
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rspec-expectations
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: 2.12.1
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 2.12.1
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rspec-mocks
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 2.12.1
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ~>
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 2.12.1
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: fog-libvirt
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ~>
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 0.0.1
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ~>
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: 0.0.1
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: nokogiri
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.6.0
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - ~>
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: 1.6.0
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: rake
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- -
|
96
|
+
- - ! '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
description: libvirt provider for Vagrant.
|
@@ -105,7 +105,7 @@ executables: []
|
|
105
105
|
extensions: []
|
106
106
|
extra_rdoc_files: []
|
107
107
|
files:
|
108
|
-
-
|
108
|
+
- .gitignore
|
109
109
|
- CHANGELOG.md
|
110
110
|
- Gemfile
|
111
111
|
- LICENSE
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/vagrant-libvirt/action/message_not_created.rb
|
135
135
|
- lib/vagrant-libvirt/action/message_not_running.rb
|
136
136
|
- lib/vagrant-libvirt/action/message_not_suspended.rb
|
137
|
+
- lib/vagrant-libvirt/action/package_domain.rb
|
137
138
|
- lib/vagrant-libvirt/action/prepare_nfs_settings.rb
|
138
139
|
- lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb
|
139
140
|
- lib/vagrant-libvirt/action/prune_nfs_exports.rb
|
@@ -185,12 +186,12 @@ require_paths:
|
|
185
186
|
- lib
|
186
187
|
required_ruby_version: !ruby/object:Gem::Requirement
|
187
188
|
requirements:
|
188
|
-
- -
|
189
|
+
- - ! '>='
|
189
190
|
- !ruby/object:Gem::Version
|
190
191
|
version: '0'
|
191
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
193
|
requirements:
|
193
|
-
- -
|
194
|
+
- - ! '>='
|
194
195
|
- !ruby/object:Gem::Version
|
195
196
|
version: '0'
|
196
197
|
requirements: []
|