vagrant-libvirt 0.0.40 → 0.0.41

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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. metadata +13 -103
  3. data/.coveralls.yml +0 -1
  4. data/.github/issue_template.md +0 -37
  5. data/.gitignore +0 -21
  6. data/.travis.yml +0 -28
  7. data/CHANGELOG.md +0 -99
  8. data/Gemfile +0 -27
  9. data/LICENSE +0 -22
  10. data/README.md +0 -1311
  11. data/Rakefile +0 -8
  12. data/example_box/README.md +0 -29
  13. data/example_box/Vagrantfile +0 -60
  14. data/example_box/metadata.json +0 -5
  15. data/lib/vagrant-libvirt.rb +0 -29
  16. data/lib/vagrant-libvirt/action.rb +0 -362
  17. data/lib/vagrant-libvirt/action/create_domain.rb +0 -313
  18. data/lib/vagrant-libvirt/action/create_domain_volume.rb +0 -87
  19. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +0 -294
  20. data/lib/vagrant-libvirt/action/create_networks.rb +0 -353
  21. data/lib/vagrant-libvirt/action/destroy_domain.rb +0 -83
  22. data/lib/vagrant-libvirt/action/destroy_networks.rb +0 -95
  23. data/lib/vagrant-libvirt/action/forward_ports.rb +0 -221
  24. data/lib/vagrant-libvirt/action/halt_domain.rb +0 -35
  25. data/lib/vagrant-libvirt/action/handle_box_image.rb +0 -156
  26. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +0 -57
  27. data/lib/vagrant-libvirt/action/is_created.rb +0 -18
  28. data/lib/vagrant-libvirt/action/is_running.rb +0 -21
  29. data/lib/vagrant-libvirt/action/is_suspended.rb +0 -42
  30. data/lib/vagrant-libvirt/action/message_already_created.rb +0 -16
  31. data/lib/vagrant-libvirt/action/message_not_created.rb +0 -16
  32. data/lib/vagrant-libvirt/action/message_not_running.rb +0 -16
  33. data/lib/vagrant-libvirt/action/message_not_suspended.rb +0 -16
  34. data/lib/vagrant-libvirt/action/package_domain.rb +0 -105
  35. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +0 -94
  36. data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +0 -17
  37. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +0 -27
  38. data/lib/vagrant-libvirt/action/read_mac_addresses.rb +0 -40
  39. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +0 -20
  40. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +0 -50
  41. data/lib/vagrant-libvirt/action/resume_domain.rb +0 -34
  42. data/lib/vagrant-libvirt/action/set_boot_order.rb +0 -109
  43. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +0 -64
  44. data/lib/vagrant-libvirt/action/share_folders.rb +0 -71
  45. data/lib/vagrant-libvirt/action/start_domain.rb +0 -303
  46. data/lib/vagrant-libvirt/action/suspend_domain.rb +0 -40
  47. data/lib/vagrant-libvirt/action/wait_till_up.rb +0 -102
  48. data/lib/vagrant-libvirt/cap/mount_p9.rb +0 -42
  49. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +0 -17
  50. data/lib/vagrant-libvirt/cap/synced_folder.rb +0 -113
  51. data/lib/vagrant-libvirt/config.rb +0 -698
  52. data/lib/vagrant-libvirt/driver.rb +0 -118
  53. data/lib/vagrant-libvirt/errors.rb +0 -149
  54. data/lib/vagrant-libvirt/plugin.rb +0 -92
  55. data/lib/vagrant-libvirt/provider.rb +0 -130
  56. data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +0 -13
  57. data/lib/vagrant-libvirt/templates/domain.xml.erb +0 -229
  58. data/lib/vagrant-libvirt/templates/private_network.xml.erb +0 -34
  59. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +0 -23
  60. data/lib/vagrant-libvirt/util.rb +0 -11
  61. data/lib/vagrant-libvirt/util/collection.rb +0 -19
  62. data/lib/vagrant-libvirt/util/erb_template.rb +0 -22
  63. data/lib/vagrant-libvirt/util/error_codes.rb +0 -100
  64. data/lib/vagrant-libvirt/util/network_util.rb +0 -138
  65. data/lib/vagrant-libvirt/util/timer.rb +0 -17
  66. data/lib/vagrant-libvirt/version.rb +0 -5
  67. data/locales/en.yml +0 -159
  68. data/spec/spec_helper.rb +0 -9
  69. data/spec/support/environment_helper.rb +0 -46
  70. data/spec/support/libvirt_context.rb +0 -30
  71. data/spec/support/sharedcontext.rb +0 -34
  72. data/spec/unit/action/destroy_domain_spec.rb +0 -97
  73. data/spec/unit/action/set_name_of_domain_spec.rb +0 -21
  74. data/spec/unit/action/wait_till_up_spec.rb +0 -127
  75. data/spec/unit/config_spec.rb +0 -106
  76. data/spec/unit/templates/domain_all_settings.xml +0 -133
  77. data/spec/unit/templates/domain_defaults.xml +0 -46
  78. data/spec/unit/templates/domain_spec.rb +0 -75
  79. data/tools/create_box.sh +0 -130
  80. data/tools/prepare_redhat_for_box.sh +0 -119
  81. data/vagrant-libvirt.gemspec +0 -28
@@ -1,18 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- # This can be used with "Call" built-in to check if the machine
5
- # is created and branch in the middleware.
6
- class IsCreated
7
- def initialize(app, _env)
8
- @app = app
9
- end
10
-
11
- def call(env)
12
- env[:result] = env[:machine].state.id != :not_created
13
- @app.call(env)
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- # This can be used with "Call" built-in to check if the machine
5
- # is running and branch in the middleware.
6
- class IsRunning
7
- def initialize(app, _env)
8
- @app = app
9
- end
10
-
11
- def call(env)
12
- domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
13
- raise Errors::NoDomainError if domain.nil?
14
- env[:result] = domain.state.to_s == 'running'
15
-
16
- @app.call(env)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,42 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- # This can be used with "Call" built-in to check if the machine
5
- # is suspended and branch in the middleware.
6
- class IsSuspended
7
- def initialize(app, _env)
8
- @app = app
9
- end
10
-
11
- def call(env)
12
- domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
13
- raise Errors::NoDomainError if domain.nil?
14
-
15
- config = env[:machine].provider_config
16
- libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
17
- if config.suspend_mode == 'managedsave'
18
- if libvirt_domain.has_managed_save?
19
- env[:result] = libvirt_domain.has_managed_save?
20
- else
21
- env[:result] = domain.state.to_s == 'paused'
22
- if env[:result]
23
- env[:ui].warn('One time switching to pause suspend mode, found a paused VM.')
24
- config.suspend_mode = 'pause'
25
- end
26
- end
27
- else
28
- if libvirt_domain.has_managed_save?
29
- env[:ui].warn('One time switching to managedsave suspend mode, state found.')
30
- env[:result] = true
31
- config.suspend_mode = 'managedsave'
32
- else
33
- env[:result] = domain.state.to_s == 'paused'
34
- end
35
- end
36
-
37
- @app.call(env)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,16 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- class MessageAlreadyCreated
5
- def initialize(app, _env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- env[:ui].info(I18n.t('vagrant_libvirt.already_created'))
11
- @app.call(env)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- class MessageNotCreated
5
- def initialize(app, _env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- env[:ui].info(I18n.t('vagrant_libvirt.not_created'))
11
- @app.call(env)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- class MessageNotRunning
5
- def initialize(app, _env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- env[:ui].info(I18n.t('vagrant_libvirt.not_running'))
11
- @app.call(env)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- class MessageNotSuspended
5
- def initialize(app, _env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- env[:ui].info(I18n.t('vagrant_libvirt.not_suspended'))
11
- @app.call(env)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,105 +0,0 @@
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[:machine].provider.driver.connection.client.lookup_domain_by_uuid(
18
- env[:machine].id
19
- )
20
- domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
21
- root_disk = domain.volumes.select do |x|
22
- x.name == libvirt_domain.name + '.img'
23
- end.first
24
- boxname = env['package.output']
25
- raise "#{boxname}: Already exists" if File.exist?(boxname)
26
- @tmp_dir = Dir.pwd + '/_tmp_package'
27
- @tmp_img = @tmp_dir + '/box.img'
28
- Dir.mkdir(@tmp_dir)
29
- if File.readable?(root_disk.path)
30
- backing = `qemu-img info "#{root_disk.path}" | grep 'backing file:' | cut -d ':' -f2`.chomp
31
- else
32
- env[:ui].error("Require set read access to #{root_disk.path}. sudo chmod a+r #{root_disk.path}")
33
- FileUtils.rm_rf(@tmp_dir)
34
- raise 'Have no access'
35
- end
36
- env[:ui].info('Image has backing image, copying image and rebasing ...')
37
- FileUtils.cp(root_disk.path, @tmp_img)
38
- `qemu-img rebase -p -b "" #{@tmp_img}`
39
- # remove hw association with interface
40
- # working for centos with lvs default disks
41
- `virt-sysprep --no-logfile --operations defaults,-ssh-userdir -a #{@tmp_img}`
42
- # add any user provided file
43
- extra = ''
44
- @tmp_include = @tmp_dir + '/_include'
45
- if env['package.include']
46
- extra = './_include'
47
- Dir.mkdir(@tmp_include)
48
- env['package.include'].each do |f|
49
- env[:ui].info("Including user file: #{f}")
50
- FileUtils.cp(f, @tmp_include)
51
- end
52
- end
53
- if env['package.vagrantfile']
54
- extra = './_include'
55
- Dir.mkdir(@tmp_include) unless File.directory?(@tmp_include)
56
- env[:ui].info('Including user Vagrantfile')
57
- FileUtils.cp(env['package.vagrantfile'], @tmp_include + '/Vagrantfile')
58
- end
59
- Dir.chdir(@tmp_dir)
60
- info = JSON.parse(`qemu-img info --output=json #{@tmp_img}`)
61
- img_size = (Float(info['virtual-size'])/(1024**3)).ceil
62
- File.write(@tmp_dir + '/metadata.json', metadata_content(img_size))
63
- File.write(@tmp_dir + '/Vagrantfile', vagrantfile_content)
64
- assemble_box(boxname, extra)
65
- FileUtils.mv(@tmp_dir + '/' + boxname, '../' + boxname)
66
- FileUtils.rm_rf(@tmp_dir)
67
- env[:ui].info('Box created')
68
- env[:ui].info('You can now add the box:')
69
- env[:ui].info("vagrant box add #{boxname} --name any_comfortable_name")
70
- @app.call(env)
71
- end
72
-
73
- def assemble_box(boxname, extra)
74
- `tar cvzf "#{boxname}" --totals ./metadata.json ./Vagrantfile ./box.img #{extra}`
75
- end
76
-
77
- def vagrantfile_content
78
- <<-EOF
79
- Vagrant.configure("2") do |config|
80
- config.vm.provider :libvirt do |libvirt|
81
- libvirt.driver = "kvm"
82
- libvirt.host = ""
83
- libvirt.connect_via_ssh = false
84
- libvirt.storage_pool_name = "default"
85
- end
86
- end
87
-
88
- user_vagrantfile = File.expand_path('../_include/Vagrantfile', __FILE__)
89
- load user_vagrantfile if File.exists?(user_vagrantfile)
90
- EOF
91
- end
92
-
93
- def metadata_content(filesize)
94
- <<-EOF
95
- {
96
- "provider": "libvirt",
97
- "format": "qcow2",
98
- "virtual_size": #{filesize}
99
- }
100
- EOF
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,94 +0,0 @@
1
- require 'nokogiri'
2
- require 'socket'
3
- require 'timeout'
4
-
5
- module VagrantPlugins
6
- module ProviderLibvirt
7
- module Action
8
- class PrepareNFSSettings
9
- include Vagrant::Action::Builtin::MixinSyncedFolders
10
-
11
- def initialize(app, _env)
12
- @app = app
13
- @logger = Log4r::Logger.new('vagrant::action::vm::nfs')
14
- end
15
-
16
- def call(env)
17
- @machine = env[:machine]
18
- @app.call(env)
19
-
20
- if using_nfs?
21
- @logger.info('Using NFS, preparing NFS settings by reading host IP and machine IP')
22
- env[:nfs_machine_ip] = read_machine_ip(env[:machine])
23
- env[:nfs_host_ip] = read_host_ip(env[:nfs_machine_ip])
24
-
25
- @logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}")
26
-
27
- raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] || !env[:nfs_host_ip]
28
- end
29
- end
30
-
31
- # We're using NFS if we have any synced folder with NFS configured. If
32
- # we are not using NFS we don't need to do the extra work to
33
- # populate these fields in the environment.
34
- def using_nfs?
35
- !!synced_folders(@machine)[:nfs]
36
- end
37
-
38
- # Returns the IP address of the host
39
- #
40
- # @param [Machine] machine
41
- # @return [String]
42
- def read_host_ip(ip)
43
- UDPSocket.open do |s|
44
- if ip.is_a?(Array)
45
- s.connect(ip.last, 1)
46
- else
47
- s.connect(ip, 1)
48
- end
49
- s.addr.last
50
- end
51
- end
52
-
53
- # Returns the IP address of the guest
54
- #
55
- # @param [Machine] machine
56
- # @return [String]
57
- def read_machine_ip(machine)
58
- # check host only ip
59
- ssh_host = machine.ssh_info[:host]
60
- return ssh_host if ping(ssh_host)
61
-
62
- # check other ips
63
- command = "ip=$(which ip); ${ip:-/sbin/ip} addr show | grep -i 'inet ' | grep -v '127.0.0.1' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1"
64
- result = ''
65
- machine.communicate.execute(command) do |type, data|
66
- result << data if type == :stdout
67
- end
68
-
69
- ips = result.chomp.split("\n").uniq
70
- @logger.info("guest IPs: #{ips.join(', ')}")
71
- ips.each do |ip|
72
- next if ip == ssh_host
73
- return ip if ping(ip)
74
- end
75
- end
76
-
77
- private
78
-
79
- # Check if we can open a connection to the host
80
- def ping(host, timeout = 3)
81
- ::Timeout.timeout(timeout) do
82
- s = TCPSocket.new(host, 'echo')
83
- s.close
84
- end
85
- true
86
- rescue Errno::ECONNREFUSED
87
- true
88
- rescue Timeout::Error, StandardError
89
- false
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,17 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- class PrepareNFSValidIds
5
- def initialize(app, _env)
6
- @app = app
7
- @logger = Log4r::Logger.new('vagrant::action::vm::nfs')
8
- end
9
-
10
- def call(env)
11
- env[:nfs_valid_ids] = env[:machine].provider.driver.connection.servers.all.map(&:id)
12
- @app.call(env)
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,27 +0,0 @@
1
- require 'yaml'
2
- module VagrantPlugins
3
- module ProviderLibvirt
4
- module Action
5
- class PruneNFSExports
6
- def initialize(app, _env)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- if env[:host]
12
- uuid = env[:machine].id
13
- # get all uuids
14
- uuids = env[:machine].provider.driver.connection.servers.all.map(&:id)
15
- # not exiisted in array will removed from nfs
16
- uuids.delete(uuid)
17
- env[:host].capability(
18
- :nfs_prune, env[:machine].ui, uuids
19
- )
20
- end
21
-
22
- @app.call(env)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,40 +0,0 @@
1
- require 'log4r'
2
-
3
- module VagrantPlugins
4
- module ProviderLibvirt
5
- module Action
6
- class ReadMacAddresses
7
- def initialize(app, _env)
8
- @app = app
9
- @logger = Log4r::Logger.new('vagrant_libvirt::action::read_mac_addresses')
10
- end
11
-
12
- def call(env)
13
- env[:machine_mac_addresses] = read_mac_addresses(env[:machine].provider.driver.connection, env[:machine])
14
- end
15
-
16
- def read_mac_addresses(libvirt, machine)
17
- return nil if machine.id.nil?
18
-
19
- domain = libvirt.client.lookup_domain_by_uuid(machine.id)
20
-
21
- if domain.nil?
22
- @logger.info('Machine could not be found, assuming it got destroyed')
23
- machine.id = nil
24
- return nil
25
- end
26
-
27
- xml = Nokogiri::XML(domain.xml_desc)
28
- mac = xml.xpath('/domain/devices/interface/mac/@address')
29
-
30
- return {} if mac.empty?
31
-
32
- Hash[mac.each_with_index.map do |x, i|
33
- @logger.debug("interface[#{i}] = #{x.value}")
34
- [i, x.value]
35
- end]
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,20 +0,0 @@
1
- require 'log4r'
2
-
3
- module VagrantPlugins
4
- module ProviderLibvirt
5
- module Action
6
- class RemoveLibvirtImage
7
- def initialize(app, _env)
8
- @logger = Log4r::Logger.new('vagrant_libvirt::action::remove_libvirt_image')
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- env[:ui].info('Vagrant-libvirt plugin removed box only from you LOCAL ~/.vagrant/boxes directory')
14
- env[:ui].info('From libvirt storage pool you have to delete image manually(virsh, virt-manager or by any other tool)')
15
- @app.call(env)
16
- end
17
- end
18
- end
19
- end
20
- end