vagrant-libvirt 0.0.43 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +434 -150
  3. data/lib/vagrant-libvirt/action.rb +2 -2
  4. data/lib/vagrant-libvirt/action/create_domain.rb +103 -38
  5. data/lib/vagrant-libvirt/action/create_domain_volume.rb +19 -14
  6. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +10 -5
  7. data/lib/vagrant-libvirt/action/create_networks.rb +7 -2
  8. data/lib/vagrant-libvirt/action/destroy_domain.rb +1 -1
  9. data/lib/vagrant-libvirt/action/destroy_networks.rb +5 -0
  10. data/lib/vagrant-libvirt/action/forward_ports.rb +9 -7
  11. data/lib/vagrant-libvirt/action/halt_domain.rb +1 -1
  12. data/lib/vagrant-libvirt/action/handle_box_image.rb +32 -18
  13. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +9 -4
  14. data/lib/vagrant-libvirt/action/package_domain.rb +63 -12
  15. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +3 -9
  16. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +19 -9
  17. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +2 -2
  18. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +17 -11
  19. data/lib/vagrant-libvirt/action/set_boot_order.rb +2 -2
  20. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +6 -9
  21. data/lib/vagrant-libvirt/action/start_domain.rb +3 -3
  22. data/lib/vagrant-libvirt/action/wait_till_up.rb +31 -16
  23. data/lib/vagrant-libvirt/cap/public_address.rb +16 -0
  24. data/lib/vagrant-libvirt/cap/synced_folder.rb +3 -3
  25. data/lib/vagrant-libvirt/config.rb +178 -29
  26. data/lib/vagrant-libvirt/driver.rb +31 -2
  27. data/lib/vagrant-libvirt/errors.rb +5 -1
  28. data/lib/vagrant-libvirt/plugin.rb +7 -2
  29. data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +3 -3
  30. data/lib/vagrant-libvirt/templates/domain.xml.erb +48 -8
  31. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +5 -1
  32. data/lib/vagrant-libvirt/util.rb +2 -0
  33. data/lib/vagrant-libvirt/util/erb_template.rb +6 -7
  34. data/lib/vagrant-libvirt/util/network_util.rb +33 -13
  35. data/lib/vagrant-libvirt/util/nfs.rb +17 -0
  36. data/lib/vagrant-libvirt/util/storage_util.rb +27 -0
  37. data/lib/vagrant-libvirt/util/ui.rb +23 -0
  38. data/lib/vagrant-libvirt/version +1 -0
  39. data/lib/vagrant-libvirt/version.rb +24 -1
  40. data/locales/en.yml +8 -4
  41. data/spec/support/environment_helper.rb +1 -1
  42. data/spec/support/libvirt_context.rb +1 -1
  43. data/spec/support/sharedcontext.rb +3 -3
  44. data/spec/unit/action/create_domain_spec.rb +85 -0
  45. data/spec/unit/action/create_domain_spec/default_storage_pool.xml +17 -0
  46. data/spec/unit/action/destroy_domain_spec.rb +2 -2
  47. data/spec/unit/action/set_name_of_domain_spec.rb +3 -3
  48. data/spec/unit/action/start_domain_spec.rb +49 -0
  49. data/spec/unit/action/start_domain_spec/default.xml +48 -0
  50. data/spec/unit/config_spec.rb +173 -0
  51. data/spec/unit/templates/domain_all_settings.xml +20 -4
  52. data/spec/unit/templates/domain_custom_cpu_model.xml +48 -0
  53. data/spec/unit/templates/domain_defaults.xml +2 -0
  54. data/spec/unit/templates/domain_spec.rb +26 -2
  55. metadata +34 -32
  56. data/.coveralls.yml +0 -1
  57. data/.github/issue_template.md +0 -37
  58. data/.gitignore +0 -21
  59. data/.travis.yml +0 -24
  60. data/Gemfile +0 -26
  61. data/Rakefile +0 -8
  62. data/example_box/README.md +0 -29
  63. data/example_box/Vagrantfile +0 -60
  64. data/example_box/metadata.json +0 -5
  65. data/tools/create_box.sh +0 -130
  66. data/tools/prepare_redhat_for_box.sh +0 -119
  67. data/vagrant-libvirt.gemspec +0 -54
data/Rakefile DELETED
@@ -1,8 +0,0 @@
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
@@ -1,29 +0,0 @@
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.
@@ -1,60 +0,0 @@
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
-
@@ -1,5 +0,0 @@
1
- {
2
- "provider" : "libvirt",
3
- "format" : "qcow2",
4
- "virtual_size" : 16
5
- }
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env bash
2
- #set -xu
3
-
4
- error() {
5
- local msg="${1}"
6
- echo "==> ERROR: ${msg}"
7
- exit 1
8
- }
9
-
10
- usage() {
11
- echo "Usage: ${0} IMAGE [BOX] [Vagrantfile.add]"
12
- echo
13
- echo "Package a qcow2 image into a vagrant-libvirt reusable box"
14
- }
15
-
16
- # Print the image's backing file
17
- backing(){
18
- local img=${1}
19
- qemu-img info "$img" | grep 'backing file:' | cut -d ':' -f2
20
- }
21
-
22
- # Rebase the image
23
- rebase(){
24
- local img=${1}
25
- qemu-img rebase -p -b "" "$img"
26
- [[ "$?" -ne 0 ]] && error "Error during rebase"
27
- }
28
-
29
- # Is absolute path
30
- isabspath(){
31
- local path=${1}
32
- [[ "$path" =~ ^/.* ]]
33
- }
34
-
35
- if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
36
- usage
37
- exit 1
38
- fi
39
-
40
- IMG=$(readlink -e "$1")
41
- [[ "$?" -ne 0 ]] && error "'$1': No such image"
42
-
43
- IMG_DIR=$(dirname "$IMG")
44
- IMG_BASENAME=$(basename "$IMG")
45
-
46
- BOX=${2:-}
47
- # If no box name is supplied infer one from image name
48
- if [[ -z "$BOX" ]]; then
49
- BOX_NAME=${IMG_BASENAME%.*}
50
- BOX=$BOX_NAME.box
51
- else
52
- BOX_NAME=$(basename "${BOX%.*}")
53
- fi
54
-
55
- [[ -f "$BOX" ]] && error "'$BOX': Already exists"
56
-
57
- CWD=$(pwd)
58
- TMP_DIR="$CWD/_tmp_package"
59
- TMP_IMG="$TMP_DIR/box.img"
60
-
61
- mkdir -p "$TMP_DIR"
62
-
63
- [[ ! -r "$IMG" ]] && error "'$IMG': Permission denied"
64
-
65
- if [ -n "$3" ] && [ -r "$3" ]; then
66
- VAGRANTFILE_ADD="$(cat $3)"
67
- fi
68
-
69
- # We move / copy (when the image has master) the image to the tempdir
70
- # ensure that it's moved back / removed again
71
- if [[ -n $(backing "$IMG") ]]; then
72
- echo "==> Image has backing image, copying image and rebasing ..."
73
- trap "rm -rf $TMP_DIR" EXIT
74
- cp "$IMG" "$TMP_IMG"
75
- rebase "$TMP_IMG"
76
- else
77
- if fuser -s "$IMG"; then
78
- error "Image '$IMG_BASENAME' is used by another process"
79
- fi
80
-
81
- # move the image to get a speed-up and use less space on disk
82
- trap 'mv "$TMP_IMG" "$IMG"; rm -rf "$TMP_DIR"' EXIT
83
- mv "$IMG" "$TMP_IMG"
84
- fi
85
-
86
- cd "$TMP_DIR"
87
-
88
- #Using the awk int function here to truncate the virtual image size to an
89
- #integer since the fog-libvirt library does not seem to properly handle
90
- #floating point.
91
- IMG_SIZE=$(qemu-img info --output=json "$TMP_IMG" | awk '/virtual-size/{s=int($2)/(1024^3); print (s == int(s)) ? s : int(s)+1 }')
92
-
93
- echo "{$IMG_SIZE}"
94
-
95
- cat > metadata.json <<EOF
96
- {
97
- "provider": "libvirt",
98
- "format": "qcow2",
99
- "virtual_size": ${IMG_SIZE}
100
- }
101
- EOF
102
-
103
- cat > Vagrantfile <<EOF
104
- Vagrant.configure("2") do |config|
105
-
106
- config.vm.provider :libvirt do |libvirt|
107
-
108
- libvirt.driver = "kvm"
109
- libvirt.host = ""
110
- libvirt.connect_via_ssh = false
111
- libvirt.storage_pool_name = "default"
112
-
113
- end
114
-
115
- ${VAGRANTFILE_ADD:-}
116
- end
117
- EOF
118
-
119
- echo "==> Creating box, tarring and gzipping"
120
-
121
- tar cvzf "$BOX" -S --totals ./metadata.json ./Vagrantfile ./box.img
122
-
123
- # if box is in tmpdir move it to CWD before removing tmpdir
124
- if ! isabspath "$BOX"; then
125
- mv "$BOX" "$CWD"
126
- fi
127
-
128
- echo "==> ${BOX} created"
129
- echo "==> You can now add the box:"
130
- echo "==> 'vagrant box add ${BOX} --name ${BOX_NAME}'"
@@ -1,119 +0,0 @@
1
- #!/bin/bash +x
2
-
3
- # This script should help to prepare RedHat and RedHat like OS (CentOS,
4
- # Scientific Linux, ...) for Vagrant box usage.
5
-
6
- # To create new box image, just install minimal base system in VM on top of not
7
- # fully allocated qcow2 image. Then upload this script to the VM and run it.
8
- # After script has finished, nothing else than halting machine should be done.
9
-
10
- # For more info about creating custom box refer to
11
- # https://github.com/vagrant-libvirt/vagrant-libvirt/tree/master/example_box
12
-
13
- # We need to set a hostname.
14
- if [ $# -ne 1 ]; then
15
- echo "Usage: $0 <hostname>"
16
- echo "Hostname should be in format vagrant-[os-name], e.g. vagrant-redhat63."
17
- exit 1
18
- fi
19
-
20
-
21
- # On which version of RedHet are we running?
22
- RHEL_MAJOR_VERSION=$(sed 's/.*release \([0-9]\)\..*/\1/' /etc/redhat-release)
23
- if [ $? -ne 0 ]; then
24
- echo "Is this a RedHat distro?"
25
- exit 1
26
- fi
27
- echo "* Found RedHat ${RHEL_MAJOR_VERSION} version."
28
-
29
-
30
- # Setup hostname vagrant-something.
31
- FQDN="$1.vagrantup.com"
32
- if grep '^HOSTNAME=' /etc/sysconfig/network > /dev/null; then
33
- sed -i 's/HOSTNAME=\(.*\)/HOSTNAME='${FQDN}'/' /etc/sysconfig/network
34
- else
35
- echo "HOSTNAME=${FQDN}" >> /etc/sysconfig/network
36
- fi
37
-
38
-
39
- # Enable EPEL repository.
40
- yum -y install wget
41
- cd ~root
42
- if [ $RHEL_MAJOR_VERSION -eq 5 ]; then
43
- wget http://ftp.astral.ro/mirrors/fedora/pub/epel/5/i386/epel-release-5-4.noarch.rpm
44
- EPEL_PKG="epel-release-5-4.noarch.rpm"
45
- else
46
- wget http://ftp.astral.ro/mirrors/fedora/pub/epel/6/i386/epel-release-6-8.noarch.rpm
47
- EPEL_PKG="epel-release-6-8.noarch.rpm"
48
- fi
49
- rpm -i ~root/${EPEL_PKG}
50
- rm -f ~root/${EPEL_PKG}
51
-
52
-
53
- # Install some required software.
54
- yum -y install openssh-server openssh-clients sudo \
55
- ruby ruby-devel make gcc rubygems rsync
56
- chkconfig sshd on
57
-
58
-
59
- # Users, groups, passwords and sudoers.
60
- echo 'vagrant' | passwd --stdin root
61
- grep 'vagrant' /etc/passwd > /dev/null
62
- if [ $? -ne 0 ]; then
63
- echo '* Creating user vagrant.'
64
- useradd vagrant
65
- echo 'vagrant' | passwd --stdin vagrant
66
- fi
67
- grep '^admin:' /etc/group > /dev/null || groupadd admin
68
- usermod -G admin vagrant
69
-
70
- echo 'Defaults env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
71
- echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
72
- sed -i 's/Defaults\s*requiretty/Defaults !requiretty/' /etc/sudoers
73
-
74
-
75
- # SSH setup
76
- # Add Vagrant ssh key for root and vagrant accouts.
77
- sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config
78
-
79
- [ -d ~root/.ssh ] || mkdir ~root/.ssh
80
- chmod 700 ~root/.ssh
81
- cat > ~root/.ssh/authorized_keys << EOF
82
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
83
- EOF
84
- chmod 600 ~root/.ssh/authorized_keys
85
-
86
- [ -d ~vagrant/.ssh ] || mkdir ~vagrant/.ssh
87
- chmod 700 ~vagrant/.ssh
88
- cat > ~vagrant/.ssh/authorized_keys << EOF
89
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
90
- EOF
91
- chmod 600 ~vagrant/.ssh/authorized_keys
92
-
93
-
94
- # Disable firewall and switch SELinux to permissive mode.
95
- chkconfig iptables off
96
- chkconfig ip6tables off
97
-
98
-
99
- # Networking setup..
100
- # Don't fix ethX names to hw address.
101
- rm -f /etc/udev/rules.d/*persistent-net.rules
102
- rm -f /etc/udev/rules.d/*-net.rules
103
- rm -fr /var/lib/dhclient/*
104
-
105
- # Interface eth0 should get IP address via dhcp.
106
- cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
107
- DEVICE="eth0"
108
- BOOTPROTO="dhcp"
109
- ONBOOT="yes"
110
- NM_CONTROLLED="no"
111
- EOF
112
-
113
-
114
- # Do some cleanup..
115
- rm -f ~root/.bash_history
116
- rm -r "$(gem env gemdir)"/doc/*
117
- yum clean all
118
-
119
- halt
@@ -1,54 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # stub: vagrant-libvirt 0.0.41 ruby lib
3
- require File.expand_path('../lib/vagrant-libvirt/version', __FILE__)
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "vagrant-libvirt".freeze
7
- s.version = VagrantPlugins::ProviderLibvirt::VERSION
8
-
9
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
10
- s.require_paths = ["lib".freeze]
11
- s.authors = ["Lukas Stanek".freeze, "Dima Vasilets".freeze, "Brian Pitts".freeze]
12
- s.files = `git ls-files`.split($\)
13
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
-
15
- s.date = "2018-02-02"
16
- s.description = "libvirt provider for Vagrant.".freeze
17
- s.email = ["ls@elostech.cz".freeze, "pronix.service@gmail.com".freeze, "brian@polibyte.com".freeze]
18
- s.homepage = "https://github.com/vagrant-libvirt/vagrant-libvirt".freeze
19
- s.licenses = ["MIT".freeze]
20
- s.rubygems_version = "2.6.14".freeze
21
- s.summary = "libvirt provider for Vagrant.".freeze
22
-
23
- s.installed_by_version = "2.6.14" if s.respond_to? :installed_by_version
24
-
25
- if s.respond_to? :specification_version then
26
- s.specification_version = 4
27
-
28
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
- s.add_development_dependency(%q<rspec-core>.freeze, ["~> 3.5.0"])
30
- s.add_development_dependency(%q<rspec-expectations>.freeze, ["~> 3.5.0"])
31
- s.add_development_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
32
- s.add_runtime_dependency(%q<fog-libvirt>.freeze, [">= 0.3.0"])
33
- s.add_runtime_dependency(%q<nokogiri>.freeze, [">= 1.6.0"])
34
- s.add_runtime_dependency(%q<fog-core>.freeze, ["~> 1.43.0"])
35
- s.add_development_dependency(%q<rake>.freeze, [">= 0"])
36
- else
37
- s.add_dependency(%q<rspec-core>.freeze, ["~> 3.5.0"])
38
- s.add_dependency(%q<rspec-expectations>.freeze, ["~> 3.5.0"])
39
- s.add_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
40
- s.add_dependency(%q<fog-libvirt>.freeze, [">= 0.3.0"])
41
- s.add_dependency(%q<nokogiri>.freeze, [">= 1.6.0"])
42
- s.add_dependency(%q<fog-core>.freeze, ["~> 1.43.0"])
43
- s.add_dependency(%q<rake>.freeze, [">= 0"])
44
- end
45
- else
46
- s.add_dependency(%q<rspec-core>.freeze, ["~> 3.5.0"])
47
- s.add_dependency(%q<rspec-expectations>.freeze, ["~> 3.5.0"])
48
- s.add_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
49
- s.add_dependency(%q<fog-libvirt>.freeze, [">= 0.3.0"])
50
- s.add_dependency(%q<nokogiri>.freeze, [">= 1.6.0"])
51
- s.add_dependency(%q<fog-core>.freeze, ["~> 1.43.0"])
52
- s.add_dependency(%q<rake>.freeze, [">= 0"])
53
- end
54
- end