vagrant-libvirt 0.1.2 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 531920cd3f0420b7e66b8524d4999ae76bdd7b72b25112cb7d5d4ad91e3b151c
4
- data.tar.gz: fd8e444a917769d361e022bbf0278e5df263decec5e45672f69e1d95e5d68669
3
+ metadata.gz: accf8b1ee506fd707b7e81a973e150e7663a7c2e4e40f21f63444faf3b0f88fc
4
+ data.tar.gz: 73b24cb64924caabce7813433f066cd8f74f39eaf28291a17e27c5ee112b0d80
5
5
  SHA512:
6
- metadata.gz: ab2759ad2755cf174a2f4c9f855f2237dabdb2543fe3f3fad54edd70a27cdf6f8b8357279617efb02487ef04d5a5f3aa7b3e1ec047d8a4b2fda15ba84fca9dea
7
- data.tar.gz: ad85d67c9f592a481bba252b3c820f677a8635bcb5f11be83be760245edea5d50745228d8034a61efd63897c1089390a1e6459d8f31c3957aaa6cbe61705b32e
6
+ metadata.gz: 4e9d4668fbc56a6836d88a86ee069c808ec9d3cd1b2d1afda127ffd21787a2b83cce29227d7a42f79e64a8201a3ed11dec13a01fa16d42223c2dae20981107ac
7
+ data.tar.gz: e3c2f7a56a0c909d851e989554092630715e9b35095131d3945ea0406f1b56cade9b5645405babd43d834a5a12cacfb853b06a7631cb8b1e68f8220cf3826a9f
data/README.md CHANGED
@@ -16,54 +16,55 @@ can help a lot :-)
16
16
  <!-- note in vim set "let g:vmt_list_item_char='-'" to generate the correct output -->
17
17
  <!-- vim-markdown-toc GFM -->
18
18
 
19
- - [Features](#features)
20
- - [Future work](#future-work)
21
- - [Installation](#installation)
22
- - [Possible problems with plugin installation on Linux](#possible-problems-with-plugin-installation-on-linux)
23
- - [Vagrant Project Preparation](#vagrant-project-preparation)
24
- - [Add Box](#add-box)
25
- - [Create Vagrantfile](#create-vagrantfile)
26
- - [Start VM](#start-vm)
27
- - [How Project Is Created](#how-project-is-created)
28
- - [Libvirt Configuration](#libvirt-configuration)
29
- - [Provider Options](#provider-options)
30
- - [Domain Specific Options](#domain-specific-options)
31
- - [Reload behavior](#reload-behavior)
32
- - [Networks](#networks)
33
- - [Private Network Options](#private-network-options)
34
- - [Public Network Options](#public-network-options)
35
- - [Management Network](#management-network)
36
- - [Additional Disks](#additional-disks)
37
- - [Reload behavior](#reload-behavior-1)
38
- - [CDROMs](#cdroms)
39
- - [Input](#input)
40
- - [PCI device passthrough](#pci-device-passthrough)
41
- - [Using USB Devices](#using-usb-devices)
42
- - [USB Controller Configuration](#usb-controller-configuration)
43
- - [USB Device Passthrough](#usb-device-passthrough)
44
- - [USB Redirector Devices](#usb-redirector-devices)
45
- - [Filter for USB Redirector Devices](#filter-for-usb-redirector-devices)
46
- - [Random number generator passthrough](#random-number-generator-passthrough)
47
- - [Watchdog device](#watchdog-device)
48
- - [Smartcard device](#smartcard-device)
49
- - [Hypervisor Features](#hypervisor-features)
50
- - [CPU features](#cpu-features)
51
- - [Memory Backing](#memory-backing)
52
- - [No box and PXE boot](#no-box-and-pxe-boot)
53
- - [SSH Access To VM](#ssh-access-to-vm)
54
- - [Forwarded Ports](#forwarded-ports)
55
- - [Synced Folders](#synced-folders)
56
- - [QEMU Session Support](#qemu-session-support)
57
- - [Customized Graphics](#customized-graphics)
58
- - [TPM Devices](#tpm-devices)
59
- - [Libvirt communication channels](#libvirt-communication-channels)
60
- - [Custom command line arguments and environment variables](#custom-command-line-arguments-and-environment-variables)
61
- - [Box Format](#box-format)
62
- - [Create Box](#create-box)
63
- - [Package Box from VM](#package-box-from-vm)
64
- - [Troubleshooting VMs](#troubleshooting-vms)
65
- - [Development](#development)
66
- - [Contributing](#contributing)
19
+ * [Features](#features)
20
+ * [Future work](#future-work)
21
+ * [Using Docker based Installation](#using-docker-based-installation)
22
+ * [Installation](#installation)
23
+ * [Possible problems with plugin installation on Linux](#possible-problems-with-plugin-installation-on-linux)
24
+ * [Vagrant Project Preparation](#vagrant-project-preparation)
25
+ * [Add Box](#add-box)
26
+ * [Create Vagrantfile](#create-vagrantfile)
27
+ * [Start VM](#start-vm)
28
+ * [How Project Is Created](#how-project-is-created)
29
+ * [Libvirt Configuration](#libvirt-configuration)
30
+ * [Provider Options](#provider-options)
31
+ * [Domain Specific Options](#domain-specific-options)
32
+ * [Reload behavior](#reload-behavior)
33
+ * [Networks](#networks)
34
+ * [Private Network Options](#private-network-options)
35
+ * [Public Network Options](#public-network-options)
36
+ * [Management Network](#management-network)
37
+ * [Additional Disks](#additional-disks)
38
+ * [Reload behavior](#reload-behavior-1)
39
+ * [CDROMs](#cdroms)
40
+ * [Input](#input)
41
+ * [PCI device passthrough](#pci-device-passthrough)
42
+ * [Using USB Devices](#using-usb-devices)
43
+ * [USB Controller Configuration](#usb-controller-configuration)
44
+ * [USB Device Passthrough](#usb-device-passthrough)
45
+ * [USB Redirector Devices](#usb-redirector-devices)
46
+ * [Filter for USB Redirector Devices](#filter-for-usb-redirector-devices)
47
+ * [Random number generator passthrough](#random-number-generator-passthrough)
48
+ * [Watchdog device](#watchdog-device)
49
+ * [Smartcard device](#smartcard-device)
50
+ * [Hypervisor Features](#hypervisor-features)
51
+ * [CPU features](#cpu-features)
52
+ * [Memory Backing](#memory-backing)
53
+ * [No box and PXE boot](#no-box-and-pxe-boot)
54
+ * [SSH Access To VM](#ssh-access-to-vm)
55
+ * [Forwarded Ports](#forwarded-ports)
56
+ * [Synced Folders](#synced-folders)
57
+ * [QEMU Session Support](#qemu-session-support)
58
+ * [Customized Graphics](#customized-graphics)
59
+ * [TPM Devices](#tpm-devices)
60
+ * [Libvirt communication channels](#libvirt-communication-channels)
61
+ * [Custom command line arguments and environment variables](#custom-command-line-arguments-and-environment-variables)
62
+ * [Box Format](#box-format)
63
+ * [Create Box](#create-box)
64
+ * [Package Box from VM](#package-box-from-vm)
65
+ * [Troubleshooting VMs](#troubleshooting-vms)
66
+ * [Development](#development)
67
+ * [Contributing](#contributing)
67
68
 
68
69
  <!-- vim-markdown-toc -->
69
70
 
@@ -92,6 +93,39 @@ can help a lot :-)
92
93
  * Take a look at [open
93
94
  issues](https://github.com/vagrant-libvirt/vagrant-libvirt/issues?state=open).
94
95
 
96
+ ## Using Docker based Installation
97
+
98
+ Due to the number of issues encountered around compatibility between the ruby runtime environment
99
+ that is part of the upstream vagrant installation and the library dependencies of libvirt that
100
+ this project requires to communicate with libvirt, there is a docker image build and published.
101
+
102
+ This should allow users to execute vagrant with vagrant-libvirt without needing to deal with
103
+ the compatibility issues, though you may need to extend the image for your own needs should
104
+ you make use of additional plugins.
105
+
106
+ To get the image:
107
+ ```bash
108
+ docker pull vagrantlibvirt/vagrant-libvirt:latest
109
+ ```
110
+
111
+ Running the image:
112
+ ```bash
113
+ docker run -it -rm \
114
+ -e LIBVIRT_DEFAULT_URI \
115
+ -v /var/run/libvirt/:/var/run/libvirt/ \
116
+ -v ~/.vagrant.d:/.vagrant.d \
117
+ -v $(pwd):$(pwd) \
118
+ -w $(pwd) \
119
+ vagrantlibvirt/vagrant-libvirt:latest \
120
+ vagrant status
121
+ ```
122
+
123
+ Note that if you are connecting to a remote system libvirt, you may omit the
124
+ `-v /var/run/libvirt/:/var/run/libvirt/` mount bind. Some distributions patch the local
125
+ vagrant environment to ensure vagrant-libvirt uses `qemu:///session`, which means you
126
+ may need to set the environment variable `LIBVIRT_DEFAULT_URI` to the same value if
127
+ looking to use this in place of your distribution provided installation.
128
+
95
129
  ## Installation
96
130
 
97
131
  First, you should have both QEMU and Libvirt installed if you plan to run VMs
@@ -210,7 +244,7 @@ You can find more Libvirt-ready boxes at
210
244
  example:
211
245
 
212
246
  ```shell
213
- vagrant init fedora/24-cloud-base
247
+ vagrant init fedora/32-cloud-base
214
248
  ```
215
249
 
216
250
  ### Create Vagrantfile
@@ -221,7 +255,7 @@ information where necessary. For example:
221
255
  ```ruby
222
256
  Vagrant.configure("2") do |config|
223
257
  config.vm.define :test_vm do |test_vm|
224
- test_vm.vm.box = "fedora/24-cloud-base"
258
+ test_vm.vm.box = "fedora/32-cloud-base"
225
259
  end
226
260
  end
227
261
  ```
@@ -285,7 +319,10 @@ URI](http://libvirt.org/uri.html):
285
319
  Connection-independent options:
286
320
 
287
321
  * `storage_pool_name` - Libvirt storage pool name, where box image and instance
288
- snapshots will be stored.
322
+ snapshots (if `snapshot_pool_name` is not set) will be stored.
323
+ * `snapshot_pool_name` - Libvirt storage pool name. If set, the created
324
+ snapshot of the instance will be stored at this location instead of
325
+ `storage_pool_name`.
289
326
 
290
327
  For example:
291
328
 
@@ -299,6 +336,8 @@ end
299
336
 
300
337
  ### Domain Specific Options
301
338
 
339
+ * `title` - A short description of the domain.
340
+ * `description` - A human readable description of the virtual machine.
302
341
  * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not
303
342
  set. Possible values are documented in Libvirt's [description for
304
343
  _target_](http://libvirt.org/formatdomain.html#elementsDisks). NOTE: this
@@ -774,6 +813,7 @@ It has a number of options:
774
813
  Disks with this option set to true need to be removed manually.
775
814
  * `shareable` - Set to true if you want to simulate shared SAN storage.
776
815
  * `serial` - Serial number of the disk device.
816
+ * `wwn` - WWN number of the disk device.
777
817
 
778
818
  The following example creates two additional disks.
779
819
 
@@ -1395,7 +1435,7 @@ For example:
1395
1435
 
1396
1436
  ```ruby
1397
1437
  Vagrant.configure(2) do |config|
1398
- config.vm.box = "fedora/24-cloud-base"
1438
+ config.vm.box = "fedora/32-cloud-base"
1399
1439
  config.vm.provider :libvirt do |libvirt|
1400
1440
  libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
1401
1441
  end
@@ -31,6 +31,8 @@ module VagrantPlugins
31
31
 
32
32
  # Gather some info about domain
33
33
  @name = env[:domain_name]
34
+ @title = config.title
35
+ @description = config.description
34
36
  @uuid = config.uuid
35
37
  @cpus = config.cpus.to_i
36
38
  @cpuset = config.cpuset
@@ -195,6 +197,8 @@ module VagrantPlugins
195
197
  # Output the settings we're going to use to the user
196
198
  env[:ui].info(I18n.t('vagrant_libvirt.creating_domain'))
197
199
  env[:ui].info(" -- Name: #{@name}")
200
+ env[:ui].info(" -- Title: #{@title}") if @title != ''
201
+ env[:ui].info(" -- Description: #{@description}") if @description != ''
198
202
  env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != ''
199
203
  env[:ui].info(" -- Domain type: #{@domain_type}")
200
204
  env[:ui].info(" -- Cpus: #{@cpus}")
@@ -51,7 +51,6 @@ module VagrantPlugins
51
51
  xml.permissions do
52
52
  xml.owner storage_uid(env)
53
53
  xml.group storage_gid(env)
54
- xml.mode '0600'
55
54
  xml.label 'virt_image_t'
56
55
  end
57
56
  end
@@ -61,7 +60,6 @@ module VagrantPlugins
61
60
  xml.permissions do
62
61
  xml.owner storage_uid(env)
63
62
  xml.group storage_gid(env)
64
- xml.mode '0600'
65
63
  xml.label 'virt_image_t'
66
64
  end
67
65
  end
@@ -98,6 +98,7 @@ module VagrantPlugins
98
98
  Port=#{ssh_info[:port]}
99
99
  UserKnownHostsFile=/dev/null
100
100
  ExitOnForwardFailure=yes
101
+ ControlMaster=no
101
102
  StrictHostKeyChecking=no
102
103
  PasswordAuthentication=no
103
104
  ForwardX11=#{ssh_info[:forward_x11] ? 'yes' : 'no'}
@@ -109,7 +110,7 @@ module VagrantPlugins
109
110
  options += " -o ProxyCommand=\"#{ssh_info[:proxy_command]}\"" if machine.provider_config.connect_via_ssh
110
111
 
111
112
  # TODO: instead of this, try and lock and get the stdin from spawn...
112
- ssh_cmd = 'exec '
113
+ ssh_cmd = ''
113
114
  if host_port <= 1024
114
115
  @@lock.synchronize do
115
116
  # TODO: add i18n
@@ -127,7 +128,7 @@ module VagrantPlugins
127
128
  log_file = ssh_forward_log_file(host_ip, host_port,
128
129
  guest_ip, guest_port)
129
130
  @logger.info "Logging to #{log_file}"
130
- spawn(ssh_cmd, [:out, :err] => [log_file, 'w'])
131
+ spawn(ssh_cmd, [:out, :err] => [log_file, 'w'], :pgroup => true)
131
132
  end
132
133
 
133
134
  def ssh_forward_log_file(host_ip, host_port, guest_ip, guest_port)
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module ProviderLibvirt
3
+ module Cap
4
+ class PublicAddress
5
+ def self.public_address(machine)
6
+ # This does not need to be a globally routable address, it
7
+ # only needs to be accessible from the machine running
8
+ # Vagrant.
9
+ ssh_info = machine.ssh_info
10
+ return nil if !ssh_info
11
+ ssh_info[:host]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -67,6 +67,8 @@ module VagrantPlugins
67
67
  attr_accessor :default_prefix
68
68
 
69
69
  # Domain specific settings used while creating new domain.
70
+ attr_accessor :title
71
+ attr_accessor :description
70
72
  attr_accessor :uuid
71
73
  attr_accessor :memory
72
74
  attr_accessor :nodeset
@@ -197,6 +199,8 @@ module VagrantPlugins
197
199
  @system_uri = UNSET_VALUE
198
200
 
199
201
  # Domain specific settings.
202
+ @title = UNSET_VALUE
203
+ @description = UNSET_VALUE
200
204
  @uuid = UNSET_VALUE
201
205
  @memory = UNSET_VALUE
202
206
  @nodeset = UNSET_VALUE
@@ -600,7 +604,8 @@ module VagrantPlugins
600
604
  cache: options[:cache] || 'default',
601
605
  allow_existing: options[:allow_existing],
602
606
  shareable: options[:shareable],
603
- serial: options[:serial]
607
+ serial: options[:serial],
608
+ wwn: options[:wwn]
604
609
  }
605
610
 
606
611
  @disks << disk # append
@@ -618,14 +623,21 @@ module VagrantPlugins
618
623
  @qemu_env.merge!(options)
619
624
  end
620
625
 
621
- # code to generate URI from a config moved out of the connect action
622
- def _generate_uri
626
+ # code to generate URI from from either the LIBVIRT_URI environment
627
+ # variable or a config moved out of the connect action
628
+ def _generate_uri(qemu_use_session)
629
+
630
+ # If the LIBVIRT_DEFAULT_URI var is set, we'll use that
631
+ if ENV.fetch('LIBVIRT_DEFAULT_URI', '') != ""
632
+ return ENV['LIBVIRT_DEFAULT_URI']
633
+ end
634
+
623
635
  # builds the Libvirt connection URI from the given driver config
624
636
  # Setup connection uri.
625
637
  uri = @driver.dup
626
638
  virt_path = case uri
627
639
  when 'qemu', 'kvm'
628
- @qemu_use_session ? '/session' : '/system'
640
+ qemu_use_session ? '/session' : '/system'
629
641
  when 'openvz', 'uml', 'phyp', 'parallels'
630
642
  '/system'
631
643
  when '@en', 'esx'
@@ -643,31 +655,37 @@ module VagrantPlugins
643
655
  uri << '+ssh://'
644
656
  uri << @username + '@' if @username
645
657
 
646
- uri << if @host
647
- @host
648
- else
649
- 'localhost'
650
- end
658
+ uri << ( @host ? @host : 'localhost' )
651
659
  else
652
660
  uri << '://'
653
661
  uri << @host if @host
654
662
  end
655
663
 
656
664
  uri << virt_path
657
- uri << '?no_verify=1'
665
+
666
+ params = {'no_verify' => '1'}
658
667
 
659
668
  if @id_ssh_key_file
660
669
  # set ssh key for access to Libvirt host
661
- uri << "\&keyfile="
662
670
  # if no slash, prepend $HOME/.ssh/
663
- @id_ssh_key_file.prepend("#{`echo ${HOME}`.chomp}/.ssh/") if @id_ssh_key_file !~ /\A\//
664
- uri << @id_ssh_key_file
671
+ @id_ssh_key_file.prepend("#{ENV['HOME']}/.ssh/") if @id_ssh_key_file !~ /\A\//
672
+ params['keyfile'] = @id_ssh_key_file
665
673
  end
666
674
  # set path to Libvirt socket
667
- uri << "\&socket=" + @socket if @socket
675
+ params['socket'] = @socket if @socket
676
+
677
+ uri << "?" + params.map{|pair| pair.join('=')}.join('&')
668
678
  uri
669
679
  end
670
680
 
681
+ def _parse_uri(uri)
682
+ begin
683
+ URI.parse(uri)
684
+ rescue
685
+ raise "@uri set to invalid uri '#{uri}'"
686
+ end
687
+ end
688
+
671
689
  def finalize!
672
690
  @driver = 'kvm' if @driver == UNSET_VALUE
673
691
  @host = nil if @host == UNSET_VALUE
@@ -691,12 +709,25 @@ module VagrantPlugins
691
709
  @management_network_domain = nil if @management_network_domain == UNSET_VALUE
692
710
  @system_uri = 'qemu:///system' if @system_uri == UNSET_VALUE
693
711
 
694
- @qemu_use_session = false if @qemu_use_session == UNSET_VALUE
712
+ # If uri isn't set then let's build one from various sources.
713
+ # Default to passing false for qemu_use_session if it's not set.
714
+ if @uri == UNSET_VALUE
715
+ @uri = _generate_uri(@qemu_use_session == UNSET_VALUE ? false : @qemu_use_session)
716
+ end
695
717
 
696
- # generate a URI if none is supplied
697
- @uri = _generate_uri if @uri == UNSET_VALUE
718
+ # Set qemu_use_session based on the URI if it wasn't set by the user
719
+ if @qemu_use_session == UNSET_VALUE
720
+ uri = _parse_uri(@uri)
721
+ if (uri.scheme.start_with? "qemu") && (uri.path.include? "session")
722
+ @qemu_use_session = true
723
+ else
724
+ @qemu_use_session = false
725
+ end
726
+ end
698
727
 
699
728
  # Domain specific settings.
729
+ @title = '' if @title == UNSET_VALUE
730
+ @description = '' if @description == UNSET_VALUE
700
731
  @uuid = '' if @uuid == UNSET_VALUE
701
732
  @memory = 512 if @memory == UNSET_VALUE
702
733
  @nodeset = nil if @nodeset == UNSET_VALUE
@@ -814,6 +845,14 @@ module VagrantPlugins
814
845
  def validate(machine)
815
846
  errors = _detected_errors
816
847
 
848
+ # The @uri and @qemu_use_session should not conflict
849
+ uri = _parse_uri(@uri)
850
+ if (uri.scheme.start_with? "qemu") && (uri.path.include? "session")
851
+ if @qemu_use_session != true
852
+ errors << "the URI and qemu_use_session configuration conflict: uri:'#{@uri}' qemu_use_session:'#{@qemu_use_session}'"
853
+ end
854
+ end
855
+
817
856
  machine.provider_config.disks.each do |disk|
818
857
  if disk[:path] && (disk[:path][0] == '/')
819
858
  errors << "absolute volume paths like '#{disk[:path]}' not yet supported"
@@ -39,6 +39,11 @@ module VagrantPlugins
39
39
  Cap::NicMacAddresses
40
40
  end
41
41
 
42
+ provider_capability(:libvirt, :public_address) do
43
+ require_relative 'cap/public_address'
44
+ Cap::PublicAddress
45
+ end
46
+
42
47
  # lower priority than nfs or rsync
43
48
  # https://github.com/vagrant-libvirt/vagrant-libvirt/pull/170
44
49
  synced_folder('9p', 4) do
@@ -1,5 +1,7 @@
1
1
  <domain type='<%= @domain_type %>' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
2
2
  <name><%= @name %></name>
3
+ <title><%= @title %></title>
4
+ <description><%= @description %></description>
3
5
  <uuid><%= @uuid %></uuid>
4
6
  <memory><%= @memory_size %></memory>
5
7
  <vcpu<% if @cpuset %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %></vcpu>
@@ -127,6 +129,9 @@
127
129
  <% if d[:serial] %>
128
130
  <serial><%= d[:serial] %></serial>
129
131
  <% end %>
132
+ <% if d[:wwn] %>
133
+ <wwn><%= d[:wwn] %></wwn>
134
+ <% end %>
130
135
  <%# this will get auto generated by Libvirt
131
136
  <address type='pci' domain='0x0000' bus='0x00' slot='???' function='0x0'/>
132
137
  -%>
@@ -1,20 +1,19 @@
1
- require 'erubis'
2
-
3
1
  module VagrantPlugins
4
2
  module ProviderLibvirt
5
3
  module Util
6
4
  module ErbTemplate
7
5
  # TODO: remove and use nokogiri builder
8
- # TODO: might be a chance to use vagrant template system according to https://github.com/mitchellh/vagrant/issues/3231
9
6
  def to_xml(template_name = nil, data = binding)
10
7
  erb = template_name || self.class.to_s.split('::').last.downcase
11
- path = File.join(File.dirname(__FILE__), '..', 'templates',
12
- "#{erb}.xml.erb")
13
- template = File.read(path)
8
+ path = File.join(File.dirname(__FILE__), '..', 'templates')
9
+ template = "#{erb}.xml"
14
10
 
15
11
  # TODO: according to erubis documentation, we should rather use evaluate and forget about
16
12
  # binding since the template may then change variables values
17
- Erubis::Eruby.new(template, trim: true).result(data)
13
+ Vagrant::Util::TemplateRenderer.render_with(:render, template, template_root: path) do |renderer|
14
+ iv = data.eval ("instance_variables.collect {|i| [i, instance_variable_get(i.to_sym)]}")
15
+ iv.each {|k, v| renderer.instance_variable_set(k, v)}
16
+ end
18
17
  end
19
18
  end
20
19
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProviderLibvirt
3
- VERSION = '0.1.2'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
@@ -25,6 +25,6 @@ shared_context 'libvirt' do
25
25
  # return some information for domain when needed
26
26
  allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
27
27
 
28
- machine.stub(id: id)
28
+ allow(machine).to receive(:id).and_return(id)
29
29
  end
30
30
  end
@@ -28,7 +28,7 @@ shared_context 'unit' do
28
28
  let(:plugin) { register_plugin }
29
29
 
30
30
  before (:each) do
31
- machine.stub(guest: guest)
32
- machine.stub(communicator: communicator)
31
+ allow(machine).to receive(:guest).and_return(guest)
32
+ allow(machine).to receive(:communicator).and_return(communicator)
33
33
  end
34
34
  end
@@ -33,7 +33,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
33
33
  before do
34
34
  allow(libvirt_domain).to receive(:list_snapshots).and_return([])
35
35
  allow(libvirt_domain).to receive(:has_managed_save?).and_return(nil)
36
- root_disk.stub(name: 'test.img')
36
+ allow(root_disk).to receive(:name).and_return('test.img')
37
37
  end
38
38
 
39
39
  context 'when only has root disk' do
@@ -57,7 +57,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
57
57
 
58
58
  let(:extra_disk) { double('libvirt_extra_disk') }
59
59
  before do
60
- extra_disk.stub(name: 'test-vdb.qcow2')
60
+ allow(extra_disk).to receive(:name).and_return('test-vdb.qcow2')
61
61
  end
62
62
 
63
63
  it 'destroys disks individually' do
@@ -10,12 +10,12 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
10
10
  dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
11
11
  first = dmn.build_domain_name(@env)
12
12
  second = dmn.build_domain_name(@env)
13
- first.should_not eq(second)
13
+ expect(first).to_not eq(second)
14
14
  end
15
15
 
16
16
  it 'builds simple domain name' do
17
17
  @env.default_prefix = 'pre_'
18
18
  dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
19
- dmn.build_domain_name(@env).should eq('pre_')
19
+ expect(dmn.build_domain_name(@env)).to eq('pre_')
20
20
  end
21
21
  end
@@ -6,12 +6,185 @@ require 'vagrant-libvirt/config'
6
6
  describe VagrantPlugins::ProviderLibvirt::Config do
7
7
  include_context 'unit'
8
8
 
9
+ let(:fake_env) { Hash.new }
10
+
11
+ describe '#finalize!' do
12
+ it 'is valid with defaults' do
13
+ subject.finalize!
14
+ end
15
+
16
+ context '@uri' do
17
+ before(:example) do
18
+ stub_const("ENV", fake_env)
19
+ end
20
+
21
+ context 'when LIBVIRT_DEFAULT_URI is defined' do
22
+ it 'should always use this value' do
23
+ fake_env['LIBVIRT_DEFAULT_URI'] = "custom:///custom_path"
24
+
25
+ subject.finalize!
26
+ expect(subject.uri).to eq("custom:///custom_path")
27
+ expect(subject.qemu_use_session).to eq(false)
28
+ end
29
+
30
+ context 'when LIBVIRT_DEFAULT_URI contains "qemu"' do
31
+ [
32
+ [
33
+ 'set qemu_use_session if "session" present',
34
+ 'qemu:///session',
35
+ true,
36
+ ],
37
+ [
38
+ 'handle different protocol additions',
39
+ 'qemu+ssh:///session',
40
+ true,
41
+ ],
42
+ [
43
+ 'handle options before and after path',
44
+ 'qemu://remote/session?keyfile=my_id_rsa',
45
+ true,
46
+ ],
47
+ [
48
+ 'identify when session not set',
49
+ 'qemu://remote/system',
50
+ false,
51
+ ],
52
+ [
53
+ 'handle session appearing elsewhere',
54
+ 'qemu://remote/system?keyfile=my_session_id',
55
+ false,
56
+ ],
57
+ ].each do |title, uri, session|
58
+ it "should #{title}" do
59
+ fake_env['LIBVIRT_DEFAULT_URI'] = uri
60
+
61
+ subject.finalize!
62
+ expect(subject.uri).to eq(uri)
63
+ expect(subject.qemu_use_session).to eq(session)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'when @driver is defined' do
70
+ defaults = {'id_ssh_key_file' => nil}
71
+ [
72
+ [
73
+ {'driver' => 'kvm'},
74
+ 'qemu:///system?no_verify=1',
75
+ false,
76
+ ],
77
+ [
78
+ {'driver' => 'qemu'},
79
+ 'qemu:///system?no_verify=1',
80
+ false,
81
+ ],
82
+ [
83
+ {'driver' => 'qemu', 'qemu_use_session' => true},
84
+ 'qemu:///session?no_verify=1',
85
+ true,
86
+ ],
87
+ [
88
+ {'driver' => 'openvz'},
89
+ 'openvz:///system?no_verify=1',
90
+ false,
91
+ ],
92
+ [
93
+ {'driver' => 'vbox'},
94
+ 'vbox:///session?no_verify=1',
95
+ false,
96
+ ],
97
+ ].each do |inputs, output_uri, output_session|
98
+ it "should detect #{inputs}" do
99
+ inputs.merge(defaults).each do |k, v|
100
+ subject.instance_variable_set("@#{k}", v)
101
+ end
102
+
103
+ subject.finalize!
104
+ expect(subject.uri).to eq(output_uri)
105
+ expect(subject.qemu_use_session).to eq(output_session)
106
+ end
107
+ end
108
+
109
+ it "should raise exception for unrecognized" do
110
+ subject.driver = "bad-driver"
111
+
112
+ expect { subject.finalize! }.to raise_error("Require specify driver bad-driver")
113
+ end
114
+ end
115
+
116
+ context 'when @connect_via_ssh defined' do
117
+ defaults = {'driver' => 'qemu', 'id_ssh_key_file' => nil}
118
+ [
119
+ [
120
+ {'connect_via_ssh' => true},
121
+ 'qemu+ssh://localhost/system?no_verify=1',
122
+ ],
123
+ [
124
+ {'connect_via_ssh' => true, 'username' => 'my_user'},
125
+ 'qemu+ssh://my_user@localhost/system?no_verify=1',
126
+ ],
127
+ [
128
+ {'connect_via_ssh' => true, 'host' => 'remote_server'},
129
+ 'qemu+ssh://remote_server/system?no_verify=1',
130
+ ],
131
+ ].each do |inputs, output_uri|
132
+ it "should detect #{inputs}" do
133
+ inputs.merge(defaults).each do |k, v|
134
+ subject.instance_variable_set("@#{k}", v)
135
+ end
136
+
137
+ subject.finalize!
138
+ expect(subject.uri).to eq(output_uri)
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'when @id_ssh_key_file defined' do
144
+ defaults = {'driver' => 'qemu'}
145
+ [
146
+ [
147
+ {},
148
+ 'qemu:///system?no_verify=1&keyfile=/home/user/.ssh/id_rsa',
149
+ ],
150
+ [
151
+ {'id_ssh_key_file' => '/path/to/keyfile'},
152
+ 'qemu:///system?no_verify=1&keyfile=/path/to/keyfile',
153
+ ],
154
+ ].each do |inputs, output_uri|
155
+ it "should detect #{inputs}" do
156
+ inputs.merge(defaults).each do |k, v|
157
+ subject.instance_variable_set("@#{k}", v)
158
+ end
159
+
160
+ fake_env['HOME'] = '/home/user'
161
+
162
+ subject.finalize!
163
+ expect(subject.uri).to eq(output_uri)
164
+ end
165
+ end
166
+ end
167
+
168
+ context 'when @socket defined' do
169
+ it "should detect @socket set" do
170
+ subject.socket = '/var/run/libvirt/libvirt-sock'
171
+ subject.id_ssh_key_file = false
172
+
173
+ subject.finalize!
174
+ expect(subject.uri).to eq('qemu:///system?no_verify=1&socket=/var/run/libvirt/libvirt-sock')
175
+ end
176
+ end
177
+ end
178
+ end
179
+
9
180
  def assert_invalid
181
+ subject.finalize!
10
182
  errors = subject.validate(machine)
11
183
  raise "No errors: #{errors.inspect}" if errors.values.all?(&:empty?)
12
184
  end
13
185
 
14
186
  def assert_valid
187
+ subject.finalize!
15
188
  errors = subject.validate(machine)
16
189
  raise "Errors: #{errors.inspect}" unless errors.values.all?(&:empty?)
17
190
  end
@@ -1,5 +1,7 @@
1
1
  <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
2
2
  <name></name>
3
+ <title>title</title>
4
+ <description>description</description>
3
5
  <uuid></uuid>
4
6
  <memory></memory>
5
7
  <vcpu cpuset='1-4,^3,6'>1</vcpu>
@@ -1,5 +1,7 @@
1
1
  <domain type='' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
2
2
  <name></name>
3
+ <title></title>
4
+ <description></description>
3
5
  <uuid></uuid>
4
6
  <memory></memory>
5
7
  <vcpu>1</vcpu>
@@ -1,5 +1,7 @@
1
1
  <domain type='' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
2
2
  <name></name>
3
+ <title></title>
4
+ <description></description>
3
5
  <uuid></uuid>
4
6
  <memory></memory>
5
7
  <vcpu>1</vcpu>
@@ -27,6 +27,8 @@ describe 'templates/domain' do
27
27
 
28
28
  context 'when all settings enabled' do
29
29
  before do
30
+ domain.title = 'title'
31
+ domain.description = 'description'
30
32
  domain.instance_variable_set('@domain_type', 'kvm')
31
33
  domain.cpu_mode = 'custom'
32
34
  domain.cpu_feature(name: 'AAA', policy: 'required')
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.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-12 00:00:00.000000000 Z
13
+ date: 2020-10-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-core
@@ -130,7 +130,6 @@ files:
130
130
  - lib/vagrant-libvirt/action/destroy_domain.rb
131
131
  - lib/vagrant-libvirt/action/destroy_networks.rb
132
132
  - lib/vagrant-libvirt/action/forward_ports.rb
133
- - lib/vagrant-libvirt/action/halt_confirm.rb
134
133
  - lib/vagrant-libvirt/action/halt_domain.rb
135
134
  - lib/vagrant-libvirt/action/handle_box_image.rb
136
135
  - lib/vagrant-libvirt/action/handle_storage_pool.rb
@@ -158,6 +157,7 @@ files:
158
157
  - lib/vagrant-libvirt/action/wait_till_up.rb
159
158
  - lib/vagrant-libvirt/cap/mount_p9.rb
160
159
  - lib/vagrant-libvirt/cap/nic_mac_addresses.rb
160
+ - lib/vagrant-libvirt/cap/public_address.rb
161
161
  - lib/vagrant-libvirt/cap/synced_folder.rb
162
162
  - lib/vagrant-libvirt/config.rb
163
163
  - lib/vagrant-libvirt/driver.rb
@@ -209,20 +209,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubygems_version: 3.0.6
212
+ rubygems_version: 3.0.3
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: libvirt provider for Vagrant.
216
216
  test_files:
217
- - spec/support/libvirt_context.rb
218
- - spec/support/sharedcontext.rb
219
- - spec/support/environment_helper.rb
220
- - spec/unit/templates/domain_all_settings.xml
221
- - spec/unit/templates/domain_custom_cpu_model.xml
222
- - spec/unit/templates/domain_defaults.xml
223
- - spec/unit/templates/domain_spec.rb
224
217
  - spec/unit/action/wait_till_up_spec.rb
225
218
  - spec/unit/action/destroy_domain_spec.rb
226
219
  - spec/unit/action/set_name_of_domain_spec.rb
227
220
  - spec/unit/config_spec.rb
221
+ - spec/unit/templates/domain_defaults.xml
222
+ - spec/unit/templates/domain_all_settings.xml
223
+ - spec/unit/templates/domain_spec.rb
224
+ - spec/unit/templates/domain_custom_cpu_model.xml
225
+ - spec/support/libvirt_context.rb
226
+ - spec/support/environment_helper.rb
227
+ - spec/support/sharedcontext.rb
228
228
  - spec/spec_helper.rb
@@ -1,20 +0,0 @@
1
- module VagrantPlugins
2
- module ProviderLibvirt
3
- module Action
4
- # This class asks the user to confirm the destruction of a machine
5
- # that Vagrant manages. This is provided as a built-in on top of
6
- # {Confirm} because it sets up the proper keys and such so that
7
- # `vagrant destroy -f` works properly.
8
- class HaltConfirm < Vagrant::Action::Builtin::Confirm
9
- def initialize(app, env)
10
- force_key = :force_confirm_halt
11
- message = I18n.t("vagrant_libvirt.package_confirm_halt",
12
- name: env[:machine].name)
13
-
14
- super(app, env, message, force_key, allowed: ["y", "n", "Y", "N"])
15
- end
16
- end
17
- end
18
- end
19
- end
20
-