vagrant-libvirt 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba233a0a466eeb2f28c391c799b1f3bb95f8299a
4
- data.tar.gz: eb0fb23c0bbca79c7c30d39e5b1f813ceb78c3c5
3
+ metadata.gz: 24d1c8176e644a03b313514b4f507fa6732a7f16
4
+ data.tar.gz: 8230dcd9f90c3f22c1877a31a52cb185ec04e84d
5
5
  SHA512:
6
- metadata.gz: 69f3a3f978ebdcc97186caa6bc73642b1fe023f0925bbcda6a343d15a4384f8a79dd8ab17c900d12d6fad99168b83f9ccf59823ef85a7d6784dbb955c8cea6a1
7
- data.tar.gz: d850270fcf613717d7e1365ae0d786e35edc137bd6cb02c63307c84f536c927897743dd1202c90ac895ed0c59edcb55de45ba55433e293fcbdad0dafe5e90114
6
+ metadata.gz: ad12e81a184aad835859c3812ba631c2469d08db9eb82585c677f3c6ea2b906a099ec1d1bbe5edb51239d58d03d1c6d11c498ba9f0c8483ce0cb09fcadd0b80f
7
+ data.tar.gz: fe5b77722c4665f9d319b4bf2f7ee9150ad774f4f0a83cac560a09021bc8964e7f5b0c7ec023aff2ee4a7ebb47df831f6ffc2b2a69b5a43d5fbff43d116693f0
data/README.md CHANGED
@@ -7,34 +7,36 @@ control and provision machines via Libvirt toolkit.
7
7
  **Note:** Actual version is still a development one. Feedback is
8
8
  welcome and can help a lot :-)
9
9
 
10
- - [Features](#)
11
- - [Future work](#)
12
- - [Installation](#)
13
- - [Possible problems with plugin installation on Linux](#)
14
- - [Vagrant Project Preparation](#)
15
- - [Add Box](#)
16
- - [Create Vagrantfile](#)
17
- - [Start VM](#)
18
- - [How Project Is Created](#)
19
- - [Libvirt Configuration](#)
20
- - [Provider Options](#)
21
- - [Domain Specific Options](#)
22
- - [Networks](#)
23
- - [Private Network Options](#)
24
- - [Public Network Options](#)
25
- - [Management Network](#)
26
- - [Additional Disks](#)
27
- - [CDROMs](#)
28
- - [Input](#)
29
- - [No box and PXE boot](#)
30
- - [SSH Access To VM](#)
31
- - [Forwarded Ports](#)
32
- - [Synced Folders](#)
33
- - [Customized Graphics](#)
34
- - [Box Format](#)
35
- - [Create Box](#)
36
- - [Development](#)
37
- - [Contributing](#)
10
+ - [Features](#features)
11
+ - [Future work](#future-work)
12
+ - [Installation](#installation)
13
+ - [Possible problems with plugin installation on Linux](#possible-problems-with-plugin-installation-on-linux)
14
+ - [Vagrant Project Preparation](#vagrant-project-preparation)
15
+ - [Add Box](#add-box)
16
+ - [Create Vagrantfile](#create-vagrantfile)
17
+ - [Start VM](#start-vm)
18
+ - [How Project Is Created](#how-project-is-created)
19
+ - [Libvirt Configuration](#libvirt-configuration)
20
+ - [Provider Options](#provider-options)
21
+ - [Domain Specific Options](#domain-specific-options)
22
+ - [Reload behavior](#reload-behavior)
23
+ - [Networks](#networks)
24
+ - [Private Network Options](#private-network-options)
25
+ - [Public Network Options](#public-network-options)
26
+ - [Management Network](#management-network)
27
+ - [Additional Disks](#additional-disks)
28
+ - [Reload behavior](#reload-behavior-1)
29
+ - [CDROMs](#cdroms)
30
+ - [Input](#input)
31
+ - [No box and PXE boot](#no-box-and-pxe-boot)
32
+ - [SSH Access To VM](#ssh-access-to-vm)
33
+ - [Forwarded Ports](#forwarded-ports)
34
+ - [Synced Folders](#synced-folders)
35
+ - [Customized Graphics](#customized-graphics)
36
+ - [Box Format](#box-format)
37
+ - [Create Box](#create-box)
38
+ - [Development](#development)
39
+ - [Contributing](#contributing)
38
40
 
39
41
  ## Features
40
42
 
@@ -157,7 +159,7 @@ Although it should work without any configuration for most people, this provider
157
159
 
158
160
  * `driver` - A hypervisor name to access. For now only kvm and qemu are supported.
159
161
  * `host` - The name of the server, where libvirtd is running.
160
- * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt.
162
+ * `connect_via_ssh` - If use ssh tunnel to connect to Libvirt. Absolutely needed to access libvirt on remote host. It will not be able to get the IP address of a started VM otherwise.
161
163
  * `username` - Username and password to access Libvirt.
162
164
  * `password` - Password to access Libvirt.
163
165
  * `id_ssh_key_file` - If not nil, uses this ssh private key to access Libvirt. Default is $HOME/.ssh/id_rsa. Prepends $HOME/.ssh/ if no directory.
@@ -181,11 +183,11 @@ end
181
183
  ### Domain Specific Options
182
184
 
183
185
  * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not set. Possible values are documented in libvirt's [description for _target_](http://libvirt.org/formatdomain.html#elementsDisks).
184
- * `nic_model_type` - parameter specifies the model of the network adapter when you create a domain value by default virtio KVM believe possible values, see the documentation for libvirt
186
+ * `nic_model_type` - parameter specifies the model of the network adapter when you create a domain value by default virtio KVM believe possible values, see the [documentation for libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel).
185
187
  * `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
186
188
  * `cpus` - Number of virtual cpus. Defaults to 1 if not set.
187
189
  * `nested` - [Enable nested virtualization](https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/nested-vmx.txt). Default is false.
188
- * `cpu_mode` - [What cpu type to emulate](https://libvirt.org/formatdomain.html#elementsCPU). Defaults to 'host-model' if not set. Allowed values: host-model, host-passthrough.
190
+ * `cpu_mode` - [CPU emulation mode](https://libvirt.org/formatdomain.html#elementsCPU). Defaults to 'host-model' if not set. Allowed values: host-model, host-passthrough.
189
191
  * `loader` - Sets path to custom UEFI loader.
190
192
  * `volume_cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe". [See driver->cache in libvirt documentation](http://libvirt.org/formatdomain.html#elementsDisks).
191
193
  * `kernel` - To launch the guest with a kernel residing on host filesystems. Equivalent to qemu `-kernel`.
@@ -196,14 +198,18 @@ end
196
198
  * `graphics_port` - Sets the port for the display protocol to bind to. Defaults to 5900.
197
199
  * `graphics_ip` - Sets the IP for the display protocol to bind to. Defaults to "127.0.0.0.1".
198
200
  * `graphics_passwd` - Sets the password for the display protocol. Working for vnc and spice. by default working without passsword.
199
- * `video_type` - Sets the graphics card type exposed to the guest. Defaults to "cirrus". [Possible values](http://libvirt.org/formatdomain.html#elementsVideo) are "vga", "cirrus", "vmvga", "xen", "vbox", or "qxl".
201
+ * `graphics_autoport` - Sets autoport for graphics, libvirt in this case ignores graphics_port value, Defaults to 'yes'. Possible value are "yes" and "no"
200
202
  * `keymap` - Set keymap for vm. default: en-us
203
+ * `video_type` - Sets the graphics card type exposed to the guest. Defaults to "cirrus". [Possible values](http://libvirt.org/formatdomain.html#elementsVideo) are "vga", "cirrus", "vmvga", "xen", "vbox", or "qxl".
201
204
  * `video_vram` - Used by some graphics card types to vary the amount of RAM dedicated to video. Defaults to 9216.
202
205
  * `machine` - Sets machine type. Equivalent to qemu `-machine`. Use `qemu-system-x86_64 -machine help` to get a list of supported machines.
203
206
  * `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`.
204
207
  * `machine_virtual_size` - Sets the disk size in GB for the machine overriding the default specified in the box. Allows boxes to defined with a minimal size disk by default and to be grown to a larger size at creation time. Will ignore sizes smaller than the size specified by the box metadata. Note that currently there is no support for automatically resizing the filesystem to take advantage of the larger disk.
205
208
  * `boot` - Change the boot order and enables the boot menu. Possible options are "hd", "network", "cdrom". Defaults to "hd" with boot menu disabled. When "network" is set without "hd", only all NICs will be tried; see below for more detail.
206
209
  * `nic_adapter_count` - Defaults to '8'. Only use case for increasing this count is for VMs that virtualize switches such as Cumulus Linux. Max value for Cumulus Linux VMs is 33.
210
+ * `uuid` - Force a domain UUID. Defaults to autogenerated value by libvirt if not set.
211
+ * `suspend_mode` - What is done on vagrant suspend. Possible values: 'pause', 'managedsave'. Pause mode executes a la `virsh suspend`, which just pauses execution of a VM, not freeing resources. Managed save mode does a la `virsh managedsave` which frees resources suspending a domain.
212
+
207
213
 
208
214
 
209
215
  Specific domain settings can be set for each domain separately in multi-VM
@@ -243,6 +249,25 @@ Vagrant.configure("2") do |config|
243
249
  # ...
244
250
  ```
245
251
 
252
+ #### Reload behavior
253
+ On vagrant reload the following domain specific attributes are updated in defined domain:
254
+
255
+ * `disk_bus` - Is updated only on disks. It skips cdroms.
256
+ * `nic_model_type` - Updated.
257
+ * `memory` - Updated.
258
+ * `cpus` - Updated.
259
+ * `nested` - Updated.
260
+ * `cpu_mode` - Updated. Pay attention that custom mode is not supported.
261
+ * `graphics_type` - Updated.
262
+ * `graphics_port` - Updated.
263
+ * `graphics_ip` - Updated.
264
+ * `graphics_passwd` - Updated.
265
+ * `graphics_autoport` - Updated.
266
+ * `keymap` - Updated.
267
+ * `video_type` - Updated.
268
+ * `video_vram` - Updated.
269
+
270
+
246
271
  ## Networks
247
272
 
248
273
  Networking features in the form of `config.vm.network` support private networks
@@ -431,6 +456,12 @@ Vagrant.configure("2") do |config|
431
456
  end
432
457
  ```
433
458
 
459
+ ### Reload behavior
460
+
461
+ On vagrant reload the following additional disk attributes are updated in defined domain:
462
+
463
+ * `bus` - Updated. Uses `device` as a search marker. It is not required to define `device`, but it's recommended. If `device` is defined then the order of addtitional disk definition becomes irrelevant.
464
+
434
465
  ## CDROMs
435
466
 
436
467
  You can attach up to four (4) CDROMs to a VM via `libvirt.storage :file, :device => :cdrom`. Available options are:
@@ -23,7 +23,7 @@ module VagrantPlugins
23
23
  # Create VM if not yet created.
24
24
  if !env[:result]
25
25
  b2.use SetNameOfDomain
26
- if !env[:machine].box
26
+ if !env[:machine].config.vm.box
27
27
  b2.use CreateDomain
28
28
  b2.use CreateNetworks
29
29
  b2.use CreateNetworkInterfaces
@@ -77,7 +77,7 @@ module VagrantPlugins
77
77
  next
78
78
  end
79
79
 
80
- if !env[:machine].box
80
+ if !env[:machine].config.vm.box
81
81
  # With no box, we just care about network creation and starting it
82
82
  b3.use CreateNetworks
83
83
  b3.use SetBootOrder
@@ -171,7 +171,7 @@ module VagrantPlugins
171
171
  if !env[:result]
172
172
  # Try to remove stale volumes anyway
173
173
  b2.use SetNameOfDomain
174
- if env[:machine].box
174
+ if env[:machine].config.vm.box
175
175
  b2.use RemoveStaleVolume
176
176
  end
177
177
  if !env[:result]
@@ -31,6 +31,7 @@ module VagrantPlugins
31
31
 
32
32
  # Gather some info about domain
33
33
  @name = env[:domain_name]
34
+ @uuid = config.uuid
34
35
  @cpus = config.cpus.to_i
35
36
  @cpu_mode = config.cpu_mode
36
37
  @loader = config.loader
@@ -74,7 +75,7 @@ module VagrantPlugins
74
75
  @os_type = 'hvm'
75
76
 
76
77
  # Get path to domain image from the storage pool selected if we have a box.
77
- if env[:machine].box
78
+ if env[:machine].config.vm.box
78
79
  actual_volumes =
79
80
  env[:machine].provider.driver.connection.volumes.all.select do |x|
80
81
  x.pool_name == @storage_pool_name
@@ -88,7 +89,7 @@ module VagrantPlugins
88
89
  # If we have a box, take the path from the domain volume and set our storage_prefix.
89
90
  # If not, we dump the storage pool xml to get its defined path.
90
91
  # the default storage prefix is typically: /var/lib/libvirt/images/
91
- if env[:machine].box
92
+ if env[:machine].config.vm.box
92
93
  storage_prefix = File.dirname(@domain_volume_path) + '/' # steal
93
94
  else
94
95
  storage_pool = env[:machine].provider.driver.connection.client.lookup_storage_pool_by_name(@storage_pool_name)
@@ -133,12 +134,15 @@ module VagrantPlugins
133
134
  # Output the settings we're going to use to the user
134
135
  env[:ui].info(I18n.t('vagrant_libvirt.creating_domain'))
135
136
  env[:ui].info(" -- Name: #{@name}")
137
+ if @uuid != ''
138
+ env[:ui].info(" -- Forced UUID: #{@uuid}")
139
+ end
136
140
  env[:ui].info(" -- Domain type: #{@domain_type}")
137
141
  env[:ui].info(" -- Cpus: #{@cpus}")
138
142
  env[:ui].info(" -- Memory: #{@memory_size / 1024}M")
139
143
  env[:ui].info(" -- Management MAC: #{@management_network_mac}")
140
144
  env[:ui].info(" -- Loader: #{@loader}")
141
- if env[:machine].box
145
+ if env[:machine].config.vm.box
142
146
  env[:ui].info(" -- Base box: #{env[:machine].box.name}")
143
147
  end
144
148
  env[:ui].info(" -- Storage pool: #{@storage_pool_name}")
@@ -177,7 +181,7 @@ module VagrantPlugins
177
181
  env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}")
178
182
  end
179
183
  @inputs.each do |input|
180
- env[:ui].info(" -- INPUT : type=#{input[:type]}, bus=#{input[:bus]}")
184
+ env[:ui].info(" -- INPUT: type=#{input[:type]}, bus=#{input[:bus]}")
181
185
  end
182
186
  env[:ui].info(" -- Command line : #{@cmd_line}")
183
187
 
@@ -138,7 +138,7 @@ module VagrantPlugins
138
138
  @app.call(env)
139
139
 
140
140
 
141
- if env[:machine].box
141
+ if env[:machine].config.vm.box
142
142
  # Configure interfaces that user requested. Machine should be up and
143
143
  # running now.
144
144
  networks_to_configure = []
@@ -28,6 +28,11 @@ module VagrantPlugins
28
28
  end
29
29
  end
30
30
 
31
+ # must remove managed saves
32
+ if libvirt_domain.has_managed_save?
33
+ libvirt_domain.managed_save_remove
34
+ end
35
+
31
36
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
32
37
 
33
38
  if env[:machine].provider_config.disks.empty?
@@ -11,8 +11,29 @@ module VagrantPlugins
11
11
  def call(env)
12
12
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
13
13
  raise Errors::NoDomainError if domain == nil
14
- env[:result] = domain.state.to_s == 'paused'
15
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
+
16
37
  @app.call(env)
17
38
  end
18
39
  end
@@ -16,7 +16,14 @@ module VagrantPlugins
16
16
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
17
17
  raise Errors::NoDomainError if domain == nil
18
18
 
19
- domain.resume
19
+ libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
20
+ config = env[:machine].provider_config
21
+ if config.suspend_mode == 'managedsave'
22
+ domain.start
23
+ else
24
+ domain.resume
25
+ end
26
+
20
27
  @logger.info("Machine #{env[:machine].id} is resumed.")
21
28
 
22
29
  @app.call(env)
@@ -1,9 +1,9 @@
1
1
  require 'log4r'
2
+ require 'rexml/document'
2
3
 
3
4
  module VagrantPlugins
4
5
  module ProviderLibvirt
5
6
  module Action
6
-
7
7
  # Just start the domain.
8
8
  class StartDomain
9
9
  def initialize(app, env)
@@ -16,8 +16,170 @@ module VagrantPlugins
16
16
 
17
17
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
18
18
  raise Errors::NoDomainError if domain == nil
19
+ config = env[:machine].provider_config
19
20
 
20
21
  begin
22
+ # update domain settings on change.
23
+
24
+ libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
25
+
26
+ if config.memory*1024 != libvirt_domain.max_memory
27
+ libvirt_domain.max_memory = config.memory*1024
28
+ libvirt_domain.memory = libvirt_domain.max_memory
29
+ end
30
+ begin
31
+ # XML definition manipulation
32
+ descr = libvirt_domain.xml_desc(1)
33
+ xml_descr = REXML::Document.new descr
34
+ descr_changed = false
35
+
36
+ # additional disk bus
37
+ config.disks.each {|disk|
38
+ device = disk[:device]
39
+ bus = disk[:bus]
40
+ REXML::XPath.each(xml_descr,'/domain/devices/disk[@device="disk"]/target[@dev="'+device+'"]') {|disk_target|
41
+ if disk_target.attributes['bus'] != bus
42
+ descr_changed = true
43
+ disk_target.attributes['bus'] = bus
44
+ disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
45
+ end
46
+ }
47
+ }
48
+
49
+ # disk_bus
50
+ REXML::XPath.each(xml_descr,'/domain/devices/disk[@device="disk"]/target[@dev="vda"]') {|disk_target|
51
+ if disk_target.attributes['bus'] != config.disk_bus
52
+ descr_changed = true
53
+ disk_target.attributes['bus'] = config.disk_bus
54
+ disk_target.parent.delete_element("#{disk_target.parent.xpath}/address")
55
+ end
56
+ }
57
+
58
+ # Iterface type
59
+ REXML::XPath.each(xml_descr,'/domain/devices/interface/model') {|iface_model|
60
+ if iface_model.attributes['type'] != config.nic_model_type
61
+ descr_changed = true
62
+ iface_model.attributes['type'] = config.nic_model_type
63
+ end
64
+ }
65
+
66
+ # vCpu count
67
+ if config.cpus.to_i != libvirt_domain.vcpus.length
68
+ descr_changed = true
69
+ REXML::XPath.first(xml_descr,'/domain/vcpu').text = config.cpus
70
+ end
71
+
72
+ # cpu_mode
73
+ cpu = REXML::XPath.first(xml_descr,'/domain/cpu')
74
+ if cpu.nil?
75
+ descr_changed = true
76
+ cpu = REXML::Element.new('cpu', REXML::XPath.first(xml_descr,'/domain'))
77
+ cpu.attributes['mode'] = config.cpu_mode
78
+ else
79
+ if cpu.attributes['mode'] != config.cpu_mode
80
+ descr_changed = true
81
+ cpu.attributes['mode'] = config.cpu_mode
82
+ end
83
+ end
84
+
85
+ if config.cpu_mode != 'host-passthrough'
86
+ cpu_model = REXML::XPath.first(xml_descr,'/domain/cpu/model')
87
+ if cpu_model.nil?
88
+ descr_changed = true
89
+ cpu_model = REXML::Element.new('model', REXML::XPath.first(xml_descr,'/domain/cpu'))
90
+ cpu_model.attributes['fallback'] = 'allow'
91
+ cpu_model.text = 'qemu64'
92
+ end
93
+ vmx_feature = REXML::XPath.first(xml_descr,'/domain/cpu/feature[@name="vmx"]')
94
+ svm_feature = REXML::XPath.first(xml_descr,'/domain/cpu/feature[@name="svm"]')
95
+ if config.nested
96
+ if vmx_feature.nil?
97
+ descr_changed = true
98
+ vmx_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr,'/domain/cpu'))
99
+ vmx_feature.attributes['policy'] = 'optional'
100
+ vmx_feature.attributes['name'] = 'vmx'
101
+ end
102
+ if svm_feature.nil?
103
+ descr_changed = true
104
+ svm_feature = REXML::Element.new('feature', REXML::XPath.first(xml_descr,'/domain/cpu'))
105
+ svm_feature.attributes['policy'] = 'optional'
106
+ svm_feature.attributes['name'] = 'svm'
107
+ end
108
+ else
109
+ if !vmx_feature.nil?
110
+ descr_changed = true
111
+ cpu.delete_element(vmx_feature)
112
+ end
113
+ if !svm_feature.nil?
114
+ descr_changed = true
115
+ cpu.delete_element(svm_feature)
116
+ end
117
+ end
118
+ else
119
+ if cpu.elements.to_a.length > 0
120
+ descr_changed = true
121
+ cpu.elements.each {|elem|
122
+ cpu.delete_element(elem)
123
+ }
124
+ end
125
+ end
126
+
127
+ # Graphics
128
+ graphics = REXML::XPath.first(xml_descr,'/domain/devices/graphics')
129
+ if graphics.attributes['type'] != config.graphics_type
130
+ descr_changed = true
131
+ graphics.attributes['type'] = config.graphics_type
132
+ end
133
+ if graphics.attributes['listen'] != config.graphics_ip
134
+ descr_changed = true
135
+ graphics.attributes['listen'] = config.graphics_ip
136
+ graphics.delete_element('//listen')
137
+ end
138
+ if graphics.attributes['autoport'] != config.graphics_autoport
139
+ descr_changed = true
140
+ graphics.attributes['autoport'] = config.graphics_autoport
141
+ if config.graphics_autoport == 'no'
142
+ graphics.attributes['port'] = config.graphics_port
143
+ end
144
+ end
145
+ if graphics.attributes['keymap'] != config.keymap
146
+ descr_changed = true
147
+ graphics.attributes['keymap'] = config.keymap
148
+ end
149
+ if graphics.attributes['passwd'] != config.graphics_passwd
150
+ descr_changed = true
151
+ if config.graphics_passwd.nil?
152
+ graphics.attributes.delete 'passwd'
153
+ else
154
+ graphics.attributes['passwd'] = config.graphics_passwd
155
+ end
156
+ end
157
+
158
+ # Video device
159
+ video = REXML::XPath.first(xml_descr,'/domain/devices/video/model')
160
+ if video.attributes['type'] != config.video_type || video.attributes['vram'] != config.video_vram
161
+ descr_changed = true
162
+ video.attributes.each_attribute {|attr| video.attributes.delete attr}
163
+ video.attributes['type'] = config.video_type
164
+ video.attributes['vram'] = config.video_vram
165
+ end
166
+
167
+ # Apply
168
+ if descr_changed
169
+ begin
170
+ libvirt_domain.undefine
171
+ new_descr = ""
172
+ xml_descr.write new_descr
173
+ server = env[:machine].provider.driver.connection.servers.create(xml: new_descr)
174
+ rescue Fog::Errors::Error => e
175
+ server = env[:machine].provider.driver.connection.servers.create(xml: descr)
176
+ raise Errors::FogCreateServerError, error_message: e.message
177
+ end
178
+ end
179
+ rescue => e
180
+ env[:ui].error("Error when updating domain settings: #{e.message}")
181
+ end
182
+ # Actually start the domain
21
183
  domain.start
22
184
  rescue => e
23
185
  raise Errors::FogError, :message => e.message
@@ -17,7 +17,19 @@ module VagrantPlugins
17
17
  domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
18
18
  raise Errors::NoDomainError if domain == nil
19
19
 
20
- domain.suspend
20
+ config = env[:machine].provider_config
21
+ if config.suspend_mode == 'managedsave'
22
+ libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
23
+ begin
24
+ libvirt_domain.managed_save
25
+ rescue => e
26
+ env[:ui].error("Error doing a managed save for domain. It may have entered a paused state.
27
+ Check the output of `virsh managedsave DOMAIN_NAME --verbose` on the VM host, error: #{e.message}")
28
+ end
29
+ else
30
+ domain.suspend
31
+ end
32
+
21
33
  @logger.info("Machine #{env[:machine].id} is suspended ")
22
34
 
23
35
  @app.call(env)
@@ -53,6 +53,7 @@ module VagrantPlugins
53
53
  attr_accessor :default_prefix
54
54
 
55
55
  # Domain specific settings used while creating new domain.
56
+ attr_accessor :uuid
56
57
  attr_accessor :memory
57
58
  attr_accessor :cpus
58
59
  attr_accessor :cpu_mode
@@ -89,6 +90,9 @@ module VagrantPlugins
89
90
  # Inputs
90
91
  attr_accessor :inputs
91
92
 
93
+ # Suspend mode
94
+ attr_accessor :suspend_mode
95
+
92
96
  def initialize
93
97
  @uri = UNSET_VALUE
94
98
  @driver = UNSET_VALUE
@@ -105,6 +109,7 @@ module VagrantPlugins
105
109
  @management_network_mac = UNSET_VALUE
106
110
 
107
111
  # Domain specific settings.
112
+ @uuid = UNSET_VALUE
108
113
  @memory = UNSET_VALUE
109
114
  @cpus = UNSET_VALUE
110
115
  @cpu_mode = UNSET_VALUE
@@ -138,6 +143,9 @@ module VagrantPlugins
138
143
 
139
144
  # Inputs
140
145
  @inputs = UNSET_VALUE
146
+
147
+ # Suspend mode
148
+ @suspend_mode = UNSET_VALUE
141
149
  end
142
150
 
143
151
  def boot(device)
@@ -317,6 +325,7 @@ module VagrantPlugins
317
325
  @uri = _generate_uri() if @uri == UNSET_VALUE
318
326
 
319
327
  # Domain specific settings.
328
+ @uuid = '' if @uuid == UNSET_VALUE
320
329
  @memory = 512 if @memory == UNSET_VALUE
321
330
  @cpus = 1 if @cpus == UNSET_VALUE
322
331
  @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
@@ -351,7 +360,13 @@ module VagrantPlugins
351
360
  # Storage
352
361
  @disks = [] if @disks == UNSET_VALUE
353
362
  @cdroms = [] if @cdroms == UNSET_VALUE
363
+
364
+ # Inputs
354
365
  @inputs = [{:type => "mouse", :bus => "ps2"}] if @inputs == UNSET_VALUE
366
+
367
+ # Suspend mode
368
+ @suspend_mode = "pause" if @suspend_mode == UNSET_VALUE
369
+
355
370
  end
356
371
 
357
372
  def validate(machine)
@@ -1,5 +1,6 @@
1
1
  <domain type='<%= @domain_type %>'>
2
2
  <name><%= @name %></name>
3
+ <uuid><%= @uuid %></uuid>
3
4
  <memory><%= @memory_size %></memory>
4
5
  <vcpu><%= @cpus %></vcpu>
5
6
 
@@ -87,9 +88,9 @@
87
88
 
88
89
  <%# Video device -%>
89
90
  <graphics type='<%= @graphics_type %>' port='<%= @graphics_port %>' autoport='<%= @graphics_autoport %>' listen='<%= @graphics_ip %>' keymap='<%= @keymap %>' <%= @graphics_passwd%> />
90
- <video>
91
- <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
92
- </video>
91
+ <video>
92
+ <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
93
+ </video>
93
94
  <%#End Video -%>
94
95
  </devices>
95
96
  </domain>
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProviderLibvirt
3
- VERSION = '0.0.31'
3
+ VERSION = '0.0.32'
4
4
  end
5
5
  end
@@ -81,7 +81,10 @@ fi
81
81
 
82
82
  cd "$TMP_DIR"
83
83
 
84
- IMG_SIZE=$(qemu-img info "$TMP_IMG" | grep 'virtual size' | awk '{print $3;}' | tr -d 'G')
84
+ #Using the awk int function here to truncate the virtual image size to an
85
+ #integer since the fog-libvirt library does not seem to properly handle
86
+ #floating point.
87
+ IMG_SIZE=$(qemu-img info "$TMP_IMG" | awk '/virtual size/{print int($3);}' | tr -d 'G')
85
88
 
86
89
  cat > metadata.json <<EOF
87
90
  {
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.31
4
+ version: 0.0.32
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: 2015-09-25 00:00:00.000000000 Z
13
+ date: 2015-10-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-core