vagrant-libvirt 0.0.45 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +253 -109
  3. data/lib/vagrant-libvirt/action.rb +2 -2
  4. data/lib/vagrant-libvirt/action/create_domain.rb +59 -29
  5. data/lib/vagrant-libvirt/action/create_domain_volume.rb +14 -8
  6. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +7 -5
  7. data/lib/vagrant-libvirt/action/create_networks.rb +2 -2
  8. data/lib/vagrant-libvirt/action/destroy_domain.rb +1 -1
  9. data/lib/vagrant-libvirt/action/forward_ports.rb +6 -5
  10. data/lib/vagrant-libvirt/action/halt_domain.rb +1 -1
  11. data/lib/vagrant-libvirt/action/handle_box_image.rb +22 -57
  12. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +4 -4
  13. data/lib/vagrant-libvirt/action/package_domain.rb +58 -12
  14. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +3 -9
  15. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +18 -9
  16. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +2 -2
  17. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +17 -11
  18. data/lib/vagrant-libvirt/action/set_boot_order.rb +2 -2
  19. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +6 -9
  20. data/lib/vagrant-libvirt/action/start_domain.rb +2 -2
  21. data/lib/vagrant-libvirt/action/wait_till_up.rb +7 -9
  22. data/lib/vagrant-libvirt/cap/synced_folder.rb +3 -3
  23. data/lib/vagrant-libvirt/config.rb +62 -11
  24. data/lib/vagrant-libvirt/driver.rb +3 -3
  25. data/lib/vagrant-libvirt/errors.rb +5 -5
  26. data/lib/vagrant-libvirt/plugin.rb +2 -2
  27. data/lib/vagrant-libvirt/templates/domain.xml.erb +18 -5
  28. data/lib/vagrant-libvirt/util/network_util.rb +6 -1
  29. data/lib/vagrant-libvirt/util/nfs.rb +17 -0
  30. data/lib/vagrant-libvirt/version.rb +1 -1
  31. data/locales/en.yml +6 -6
  32. data/spec/unit/action/set_name_of_domain_spec.rb +1 -1
  33. data/spec/unit/templates/domain_all_settings.xml +12 -2
  34. data/spec/unit/templates/domain_spec.rb +10 -2
  35. metadata +21 -34
  36. data/.coveralls.yml +0 -1
  37. data/.github/issue_template.md +0 -37
  38. data/.gitignore +0 -21
  39. data/.travis.yml +0 -24
  40. data/Gemfile +0 -26
  41. data/Rakefile +0 -8
  42. data/example_box/README.md +0 -29
  43. data/example_box/Vagrantfile +0 -60
  44. data/example_box/metadata.json +0 -5
  45. data/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb +0 -14
  46. data/tools/create_box.sh +0 -130
  47. data/tools/prepare_redhat_for_box.sh +0 -119
  48. data/vagrant-libvirt.gemspec +0 -51
@@ -1 +0,0 @@
1
- service_name: travis-ci
@@ -1,37 +0,0 @@
1
- <!--
2
- Thank you for reporting issues to vagrant-libvirt.
3
-
4
- To make it possible for us to help you quickly, we kindly request that you use the template below to report issues. If the issue you are reporting does not fit the template (a feature request for example) please feel free to adapt it to your needs.
5
-
6
- Please be aware that we are not actively testing previous versions of both Vagrant and Vagrant-libvirt, so before reporting an issue, please install the latest Vagrant version from Vagrantup.com, run `vagrant plugin update` and reproduce the issue.
7
- -->
8
- ### Steps to reproduce
9
- 1.
10
- 2.
11
- 3.
12
-
13
- ### Expected behaviour
14
- Tell us what should happen
15
-
16
- ### Actual behaviour
17
- Tell us what happens instead
18
-
19
- ### System configuration
20
- **OS/Distro version:**:
21
-
22
- **Libvirt version:**
23
-
24
- **Output of `vagrant version; vagrant plugin list`:**
25
-
26
- **Output of `VAGRANT_LOG=debug vagrant ... --provider=libvirt`**
27
- ```
28
- Insert debug output inside quotes here (replace ... with whatever command you use to trigger the issue)
29
- ```
30
-
31
- **A Vagrantfile to reproduce the issue:**
32
- ```
33
- Insert Vagrantfile inside quotes here (remove sensitive data if needed)
34
- ```
35
-
36
- **Are you using upstream vagrant package or your distros package?**
37
- Upstream / Distro
data/.gitignore DELETED
@@ -1,21 +0,0 @@
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
21
- *.swp
@@ -1,24 +0,0 @@
1
- ---
2
- language: ruby
3
- dist: trusty
4
- before_install:
5
- - sudo apt-get update -qq
6
- - sudo apt-get install -y libvirt-dev
7
- - gem update --system
8
- - gem install bundler
9
- install: bundle install
10
- script: bundle exec rspec --color --format documentation
11
- notifications:
12
- email: false
13
- rvm:
14
- - 2.2.5
15
- - 2.3.3
16
- env:
17
- global:
18
- - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
19
- matrix:
20
- - VAGRANT_VERSION=v2.0.1
21
- matrix:
22
- allow_failures:
23
- - env: VAGRANT_VERSION=master
24
- rvm: 2.3.3
data/Gemfile DELETED
@@ -1,26 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in vagrant-libvirt.gemspec
4
- gemspec
5
-
6
- group :development do
7
- # We depend on Vagrant for development, but we don't add it as a
8
- # gem dependency because we expect to be installed within the
9
- # Vagrant environment itself using `vagrant plugin`.
10
- if ENV['VAGRANT_VERSION']
11
- gem 'vagrant', :git => 'https://github.com/hashicorp/vagrant.git',
12
- tag: ENV['VAGRANT_VERSION']
13
- else
14
- gem 'vagrant', :git => 'https://github.com/hashicorp/vagrant.git'
15
- end
16
-
17
- gem 'vagrant-spec', :github => 'hashicorp/vagrant-spec'
18
-
19
- gem 'pry'
20
- end
21
-
22
- group :plugins do
23
- gemspec
24
- end
25
-
26
- gem 'coveralls', require: false
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,14 +0,0 @@
1
- <volume>
2
- <name><%= @name %></name>
3
- <allocation unit="<%= split_size_unit(@allocation)[1] %>"><%= split_size_unit(@allocation)[0] %></allocation>
4
- <capacity unit="<%= split_size_unit(@capacity)[1] %>"><%= split_size_unit(@capacity)[0] %></capacity>
5
- <target>
6
- <format type="<%= @format_type %>"/>
7
- <permissions>
8
- <owner><%= @storage_volume_uid %></owner>
9
- <group><%= @storage_volume_gid %></group>
10
- <mode>0744</mode>
11
- <label>virt_image_t</label>
12
- </permissions>
13
- </target>
14
- </volume>
@@ -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