vagrant-libvirt 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +134 -23
- data/lib/vagrant-libvirt/action/clean_machine_folder.rb +4 -0
- data/lib/vagrant-libvirt/action/create_domain.rb +11 -3
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +7 -2
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +8 -2
- data/lib/vagrant-libvirt/action/create_networks.rb +12 -8
- data/lib/vagrant-libvirt/action/destroy_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/destroy_networks.rb +2 -0
- data/lib/vagrant-libvirt/action/forward_ports.rb +7 -5
- data/lib/vagrant-libvirt/action/halt_domain.rb +4 -34
- data/lib/vagrant-libvirt/action/handle_box_image.rb +18 -13
- data/lib/vagrant-libvirt/action/handle_storage_pool.rb +7 -1
- data/lib/vagrant-libvirt/action/is_created.rb +2 -0
- data/lib/vagrant-libvirt/action/is_running.rb +2 -0
- data/lib/vagrant-libvirt/action/is_suspended.rb +2 -0
- data/lib/vagrant-libvirt/action/message_already_created.rb +2 -0
- data/lib/vagrant-libvirt/action/message_not_created.rb +2 -0
- data/lib/vagrant-libvirt/action/message_not_running.rb +2 -0
- data/lib/vagrant-libvirt/action/message_not_suspended.rb +2 -0
- data/lib/vagrant-libvirt/action/message_will_not_destroy.rb +2 -0
- data/lib/vagrant-libvirt/action/package_domain.rb +133 -68
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +2 -0
- data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +2 -0
- data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +2 -0
- data/lib/vagrant-libvirt/action/read_mac_addresses.rb +2 -0
- data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +2 -0
- data/lib/vagrant-libvirt/action/remove_stale_volume.rb +2 -0
- data/lib/vagrant-libvirt/action/resume_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/set_boot_order.rb +8 -2
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +3 -1
- data/lib/vagrant-libvirt/action/share_folders.rb +2 -0
- data/lib/vagrant-libvirt/action/shutdown_domain.rb +49 -0
- data/lib/vagrant-libvirt/action/start_domain.rb +26 -17
- data/lib/vagrant-libvirt/action/suspend_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/wait_till_up.rb +2 -0
- data/lib/vagrant-libvirt/action.rb +34 -4
- data/lib/vagrant-libvirt/cap/mount_9p.rb +2 -0
- data/lib/vagrant-libvirt/cap/mount_virtiofs.rb +2 -0
- data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +2 -0
- data/lib/vagrant-libvirt/cap/public_address.rb +2 -0
- data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +5 -2
- data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +5 -2
- data/lib/vagrant-libvirt/config.rb +58 -24
- data/lib/vagrant-libvirt/driver.rb +67 -12
- data/lib/vagrant-libvirt/errors.rb +2 -0
- data/lib/vagrant-libvirt/plugin.rb +2 -0
- data/lib/vagrant-libvirt/provider.rb +2 -0
- data/lib/vagrant-libvirt/templates/domain.xml.erb +4 -2
- data/lib/vagrant-libvirt/templates/public_interface.xml.erb +1 -0
- data/lib/vagrant-libvirt/util/byte_number.rb +71 -0
- data/lib/vagrant-libvirt/util/collection.rb +2 -0
- data/lib/vagrant-libvirt/util/erb_template.rb +2 -0
- data/lib/vagrant-libvirt/util/error_codes.rb +2 -0
- data/lib/vagrant-libvirt/util/network_util.rb +3 -0
- data/lib/vagrant-libvirt/util/nfs.rb +2 -0
- data/lib/vagrant-libvirt/util/storage_util.rb +1 -0
- data/lib/vagrant-libvirt/util/timer.rb +2 -0
- data/lib/vagrant-libvirt/util/ui.rb +1 -0
- data/lib/vagrant-libvirt/util.rb +2 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/lib/vagrant-libvirt/version.rb +2 -0
- data/lib/vagrant-libvirt.rb +2 -0
- data/locales/en.yml +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/binding_proc.rb +2 -0
- data/spec/support/environment_helper.rb +2 -0
- data/spec/support/libvirt_context.rb +2 -0
- data/spec/support/matchers/have_file_content.rb +2 -0
- data/spec/support/sharedcontext.rb +3 -0
- data/spec/support/temporary_dir.rb +12 -0
- data/spec/unit/action/clean_machine_folder_spec.rb +16 -4
- data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +61 -0
- data/spec/unit/action/create_domain_spec/default_domain.xml +55 -0
- data/spec/unit/action/create_domain_spec.rb +68 -32
- data/spec/unit/action/create_domain_volume_spec/one_disk_in_storage.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec.rb +10 -4
- data/spec/unit/action/destroy_domain_spec.rb +8 -2
- data/spec/unit/action/forward_ports_spec.rb +2 -0
- data/spec/unit/action/halt_domain_spec.rb +30 -57
- data/spec/unit/action/handle_box_image_spec.rb +104 -24
- data/spec/unit/action/package_domain_spec.rb +304 -0
- data/spec/unit/action/set_name_of_domain_spec.rb +2 -0
- data/spec/unit/action/shutdown_domain_spec.rb +131 -0
- data/spec/unit/action/start_domain_spec/existing.xml +62 -0
- data/spec/unit/action/start_domain_spec.rb +18 -28
- data/spec/unit/action/wait_till_up_spec.rb +2 -0
- data/spec/unit/action_spec.rb +96 -0
- data/spec/unit/config_spec.rb +56 -3
- data/spec/unit/driver_spec.rb +155 -0
- data/spec/unit/templates/domain_all_settings.xml +4 -0
- data/spec/unit/templates/domain_spec.rb +2 -0
- data/spec/unit/util/byte_number_spec.rb +28 -0
- metadata +59 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e37a27120aef75fdd73d704321b96c7c881b07fa3cbdd655855300bf11163a3
|
4
|
+
data.tar.gz: 4639827cc360b3f06304310f02dffea445f19d2f4b8675a6e0e05a9be3cea307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb13d39445a95f3514cc1be73bcf6e81ec7924959ec86e6cc712c50050ac8211f6b5beb26bbd42c137020e98143794d7b67aa7241e2461cdf2d1ca5ed2a15c30
|
7
|
+
data.tar.gz: b341135cabad7d59963df62e9dd921470a43e4794fb203ff78b893bd058a38af877717f48b25a72135211e72d82082ec444227b97157e365903103240dfb1311
|
data/README.md
CHANGED
@@ -18,7 +18,10 @@ can help a lot :-)
|
|
18
18
|
|
19
19
|
* [Features](#features)
|
20
20
|
* [Future work](#future-work)
|
21
|
-
* [Using
|
21
|
+
* [Using the container image](#using-the-container-image)
|
22
|
+
* [Using Docker](#using-docker)
|
23
|
+
* [Using Podman](#using-podman)
|
24
|
+
* [Extending the Docker image with additional vagrant plugins](#extending-the-docker-image-with-additional-vagrant-plugins)
|
22
25
|
* [Installation](#installation)
|
23
26
|
* [Possible problems with plugin installation on Linux](#possible-problems-with-plugin-installation-on-linux)
|
24
27
|
* [Additional Notes for Fedora and Similar Linux Distributions](#additional-notes-for-fedora-and-similar-linux-distributions)
|
@@ -99,7 +102,7 @@ can help a lot :-)
|
|
99
102
|
* Take a look at [open
|
100
103
|
issues](https://github.com/vagrant-libvirt/vagrant-libvirt/issues?state=open).
|
101
104
|
|
102
|
-
## Using
|
105
|
+
## Using the container image
|
103
106
|
|
104
107
|
Due to the number of issues encountered around compatibility between the ruby runtime environment
|
105
108
|
that is part of the upstream vagrant installation and the library dependencies of libvirt that
|
@@ -109,11 +112,31 @@ This should allow users to execute vagrant with vagrant-libvirt without needing
|
|
109
112
|
the compatibility issues, though you may need to extend the image for your own needs should
|
110
113
|
you make use of additional plugins.
|
111
114
|
|
112
|
-
|
115
|
+
Note the default image contains the full toolchain required to build and install vagrant-libvirt
|
116
|
+
and it's dependencies. There is also a smaller image published with the `-slim` suffix if you
|
117
|
+
just need vagrant-libvirt and don't need to install any additional plugins for your environment.
|
118
|
+
|
119
|
+
If you are connecting to a remote system libvirt, you may omit the
|
120
|
+
`-v /var/run/libvirt/:/var/run/libvirt/` mount bind. Some distributions patch the local
|
121
|
+
vagrant environment to ensure vagrant-libvirt uses `qemu:///session`, which means you
|
122
|
+
may need to set the environment variable `LIBVIRT_DEFAULT_URI` to the same value if
|
123
|
+
looking to use this in place of your distribution provided installation.
|
124
|
+
|
125
|
+
### Using Docker
|
126
|
+
|
127
|
+
To get the image with the most recent release:
|
113
128
|
```bash
|
114
129
|
docker pull vagrantlibvirt/vagrant-libvirt:latest
|
115
130
|
```
|
116
131
|
|
132
|
+
---
|
133
|
+
**Note** If you want the very latest code you can use the `edge` tag instead.
|
134
|
+
|
135
|
+
```bash
|
136
|
+
docker pull vagrantlibvirt/vagrant-libvirt:edge
|
137
|
+
```
|
138
|
+
---
|
139
|
+
|
117
140
|
Preparing the docker run, only once:
|
118
141
|
|
119
142
|
```bash
|
@@ -126,33 +149,73 @@ docker run -it --rm \
|
|
126
149
|
-e LIBVIRT_DEFAULT_URI \
|
127
150
|
-v /var/run/libvirt/:/var/run/libvirt/ \
|
128
151
|
-v ~/.vagrant.d:/.vagrant.d \
|
129
|
-
-v $(
|
130
|
-
-w $(
|
152
|
+
-v $(realpath "${PWD}"):${PWD} \
|
153
|
+
-w $(realpath "${PWD}") \
|
131
154
|
--network host \
|
132
155
|
vagrantlibvirt/vagrant-libvirt:latest \
|
133
156
|
vagrant status
|
134
157
|
```
|
135
158
|
|
136
|
-
It's possible to define
|
159
|
+
It's possible to define a function in `~/.bashrc`, for example:
|
137
160
|
```bash
|
138
|
-
|
139
|
-
mkdir -p ~/.vagrant.d/{boxes,data,tmp}; \
|
161
|
+
vagrant(){
|
140
162
|
docker run -it --rm \
|
141
163
|
-e LIBVIRT_DEFAULT_URI \
|
142
164
|
-v /var/run/libvirt/:/var/run/libvirt/ \
|
143
165
|
-v ~/.vagrant.d:/.vagrant.d \
|
144
|
-
-v $(
|
145
|
-
-w $(
|
166
|
+
-v $(realpath "${PWD}"):${PWD} \
|
167
|
+
-w $(realpath "${PWD}") \
|
146
168
|
--network host \
|
147
169
|
vagrantlibvirt/vagrant-libvirt:latest \
|
148
|
-
|
170
|
+
vagrant $@
|
171
|
+
}
|
172
|
+
|
149
173
|
```
|
150
174
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
175
|
+
### Using Podman
|
176
|
+
To run with Podman you need to include
|
177
|
+
|
178
|
+
```bash
|
179
|
+
--entrypoint /bin/bash \
|
180
|
+
--security-opt label=disable \
|
181
|
+
-v ~/.vagrant.d/boxes:/vagrant/boxes \
|
182
|
+
-v ~/.vagrant.d/data:/vagrant/data \
|
183
|
+
```
|
184
|
+
|
185
|
+
for example:
|
186
|
+
|
187
|
+
```bash
|
188
|
+
vagrant(){
|
189
|
+
podman run -it --rm \
|
190
|
+
-e LIBVIRT_DEFAULT_URI \
|
191
|
+
-v /var/run/libvirt/:/var/run/libvirt/ \
|
192
|
+
-v ~/.vagrant.d/boxes:/vagrant/boxes \
|
193
|
+
-v ~/.vagrant.d/data:/vagrant/data \
|
194
|
+
-v $(realpath "${PWD}"):${PWD} \
|
195
|
+
-w $(realpath "${PWD}") \
|
196
|
+
--network host \
|
197
|
+
--entrypoint /bin/bash \
|
198
|
+
--security-opt label=disable \
|
199
|
+
docker.io/vagrantlibvirt/vagrant-libvirt:latest \
|
200
|
+
vagrant $@
|
201
|
+
}
|
202
|
+
```
|
203
|
+
|
204
|
+
Running Podman in rootless mode maps the root user inside the container to your host user so we need to bypass [entrypoint.sh](https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/entrypoint.sh) and mount persistent storage directly to `/vagrant`.
|
205
|
+
|
206
|
+
### Extending the Docker image with additional vagrant plugins
|
207
|
+
|
208
|
+
By default the image published and used contains the entire tool chain required
|
209
|
+
to reinstall the vagrant-libvirt plugin and it's dependencies, as this is the
|
210
|
+
default behaviour of vagrant anytime a new plugin is installed. This means it
|
211
|
+
should be possible to use a simple `FROM` statement and ask vagrant to install
|
212
|
+
additional plugins.
|
213
|
+
|
214
|
+
```
|
215
|
+
FROM vagrantlibvirt/vagrant-libvirt:latest
|
216
|
+
|
217
|
+
RUN vagrant plugin install <plugin>
|
218
|
+
```
|
156
219
|
|
157
220
|
## Installation
|
158
221
|
|
@@ -183,6 +246,7 @@ vagrant-libvirt. This depends on your distro. An overview:
|
|
183
246
|
apt-get build-dep vagrant ruby-libvirt
|
184
247
|
apt-get install qemu libvirt-daemon-system libvirt-clients ebtables dnsmasq-base
|
185
248
|
apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
|
249
|
+
apt-get install libguestfs-tools
|
186
250
|
```
|
187
251
|
|
188
252
|
* Ubuntu 18.04, Debian 8 and older:
|
@@ -190,23 +254,24 @@ apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
|
|
190
254
|
apt-get build-dep vagrant ruby-libvirt
|
191
255
|
apt-get install qemu libvirt-bin ebtables dnsmasq-base
|
192
256
|
apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
|
257
|
+
apt-get install libguestfs-tools
|
193
258
|
```
|
194
259
|
|
195
260
|
(It is possible some users will already have libraries from the third line installed, but this is the way to make it work OOTB.)
|
196
261
|
|
197
262
|
* CentOS 6, 7, Fedora 21:
|
198
263
|
```shell
|
199
|
-
yum install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm
|
264
|
+
yum install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm libguestfs-tools
|
200
265
|
```
|
201
266
|
|
202
267
|
* Fedora 22 and up:
|
203
268
|
```shell
|
204
|
-
dnf install -y gcc libvirt libvirt-devel libxml2-devel make ruby-devel
|
269
|
+
dnf install -y gcc libvirt libvirt-devel libxml2-devel make ruby-devel libguestfs-tools
|
205
270
|
```
|
206
271
|
|
207
272
|
* OpenSUSE leap 15.1:
|
208
273
|
```shell
|
209
|
-
zypper install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm
|
274
|
+
zypper install qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm libguestfs
|
210
275
|
```
|
211
276
|
|
212
277
|
* Arch Linux: please read the related [ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt) page.
|
@@ -241,8 +306,7 @@ On Ubuntu, Debian, make sure you are running all three of the `apt` commands abo
|
|
241
306
|
On RedHat, Centos, Fedora, ...
|
242
307
|
|
243
308
|
```shell
|
244
|
-
$ sudo dnf install libxslt-devel libxml2-devel libvirt-devel
|
245
|
-
libguestfs-tools-c ruby-devel gcc
|
309
|
+
$ sudo dnf install libxslt-devel libxml2-devel libvirt-devel ruby-devel gcc
|
246
310
|
```
|
247
311
|
|
248
312
|
On Arch Linux it is recommended to follow [steps from ArchWiki](https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt).
|
@@ -906,6 +970,23 @@ DHCP server. dnsmasq writes lease information in the `/var/lib/libvirt/dnsmasq`
|
|
906
970
|
directory. Vagrant-libvirt looks for the MAC address in this file and extracts
|
907
971
|
the corresponding IP address.
|
908
972
|
|
973
|
+
It is also possible to use the Qemu Agent to extract the management interface
|
974
|
+
configuration from the booted virtual machine. This is helpful in libvirt
|
975
|
+
environments where no local dnsmasq is used for automatic address assigment,
|
976
|
+
but external dhcp services via bridged libvirt networks.
|
977
|
+
|
978
|
+
Prerequisite is to enable the qemu agent channel via ([Libvirt communication
|
979
|
+
channels](#libvirt-communication-channels)) and the virtual machine image must
|
980
|
+
have the agent pre-installed before deploy. The agent will start automatically
|
981
|
+
if it detects an attached channel during boot.
|
982
|
+
|
983
|
+
* `qemu_use_agent` - false by default, if set to true, attempt to extract configured
|
984
|
+
ip address via qemu agent.
|
985
|
+
|
986
|
+
To use the management network interface with an external dhcp service you need
|
987
|
+
to setup a bridged host network manually and define it via
|
988
|
+
`management_network_name` in your Vagrantfile.
|
989
|
+
|
909
990
|
## Additional Disks
|
910
991
|
|
911
992
|
You can create and attach additional disks to a VM via `libvirt.storage :file`.
|
@@ -1067,13 +1148,14 @@ The USB controller can be configured using `libvirt.usb_controller`, with the fo
|
|
1067
1148
|
Vagrant.configure("2") do |config|
|
1068
1149
|
config.vm.provider :libvirt do |libvirt|
|
1069
1150
|
# Set up a USB3 controller
|
1070
|
-
libvirt.usb_controller :model => "
|
1151
|
+
libvirt.usb_controller :model => "qemu-xhci"
|
1071
1152
|
end
|
1072
1153
|
end
|
1073
1154
|
```
|
1074
1155
|
|
1075
1156
|
See the [libvirt documentation](https://libvirt.org/formatdomain.html#elementsControllers) for a list of valid models.
|
1076
1157
|
|
1158
|
+
If any USB devices are passed through by setting `libvirt.usb` or `libvirt.redirdev`, a default controller will be added using the model `qemu-xhci` in the absence of a user specified one. This should help ensure more devices work out of the box as the default configured by libvirt is pii3-uhci, which appears to only work for USB 1 devices and does not work as expected when connected via a USB 2 controller, while the xhci stack should work for all versions of USB.
|
1077
1159
|
|
1078
1160
|
### USB Device Passthrough
|
1079
1161
|
|
@@ -1094,6 +1176,17 @@ The example values above match the device from the following output of `lsusb`:
|
|
1094
1176
|
Bus 001 Device 002: ID 1234:abcd Example device
|
1095
1177
|
```
|
1096
1178
|
|
1179
|
+
```ruby
|
1180
|
+
Vagrant.configure("2") do |config|
|
1181
|
+
config.vm.provider :libvirt do |libvirt|
|
1182
|
+
# pass through specific device based on identifying it
|
1183
|
+
libvirt.usbdev :vendor => '0x1234', :product => '0xabcd'
|
1184
|
+
# pass through a host device where multiple of the same vendor/product exist
|
1185
|
+
libvirt.usbdev :bus => '1', :device => '1'
|
1186
|
+
end
|
1187
|
+
end
|
1188
|
+
```
|
1189
|
+
|
1097
1190
|
Additionally, the following options can be used:
|
1098
1191
|
|
1099
1192
|
* `startupPolicy` - Is passed through to Libvirt and controls if the device has
|
@@ -1150,7 +1243,7 @@ In this case, the USB device with `class 0x0b`, `vendor 0x08e6`, `product 0x3437
|
|
1150
1243
|
Vagrant.configure("2") do |config|
|
1151
1244
|
config.vm.provider :libvirt do |libvirt|
|
1152
1245
|
libvirt.redirdev :type => "spicevmc"
|
1153
|
-
libvirt.redirfilter :class => "0x0b" :vendor => "0x08e6" :product => "0x3437" :version => "2.00" :allow => "yes"
|
1246
|
+
libvirt.redirfilter :class => "0x0b", :vendor => "0x08e6", :product => "0x3437", :version => "2.00", :allow => "yes"
|
1154
1247
|
libvirt.redirfilter :allow => "no"
|
1155
1248
|
end
|
1156
1249
|
end
|
@@ -1389,6 +1482,24 @@ Name of network "foreman_managed" is key for define boot order
|
|
1389
1482
|
end
|
1390
1483
|
```
|
1391
1484
|
|
1485
|
+
An example VM that is PXE booted from the `br1` device (which must already be configured in the host machine), and if that fails, is booted from the disk:
|
1486
|
+
|
1487
|
+
```ruby
|
1488
|
+
Vagrant.configure("2") do |config|
|
1489
|
+
config.vm.define :pxeclient do |pxeclient|
|
1490
|
+
pxeclient.vm.network :public_network,
|
1491
|
+
dev: 'br1',
|
1492
|
+
auto_config: false
|
1493
|
+
pxeclient.vm.provider :libvirt do |domain|
|
1494
|
+
boot_network = {'dev' => 'br1'}
|
1495
|
+
domain.storage :file, :size => '100G'
|
1496
|
+
domain.boot boot_network
|
1497
|
+
domain.boot 'hd'
|
1498
|
+
end
|
1499
|
+
end
|
1500
|
+
end
|
1501
|
+
```
|
1502
|
+
|
1392
1503
|
## SSH Access To VM
|
1393
1504
|
|
1394
1505
|
vagrant-libvirt supports vagrant's [standard ssh
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
2
4
|
|
3
5
|
module VagrantPlugins
|
@@ -19,6 +21,8 @@ module VagrantPlugins
|
|
19
21
|
|
20
22
|
@logger.debug("Recursively removing: #{machine_folder}")
|
21
23
|
FileUtils.rm_rf(machine_folder, :secure => true)
|
24
|
+
# need to recreate to prevent exception during a cancelled up
|
25
|
+
FileUtils.mkdir_p(machine_folder)
|
22
26
|
|
23
27
|
@app.call(env)
|
24
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
2
4
|
|
3
5
|
module VagrantPlugins
|
@@ -33,7 +35,8 @@ module VagrantPlugins
|
|
33
35
|
# Gather some info about domain
|
34
36
|
@name = env[:domain_name]
|
35
37
|
@title = config.title
|
36
|
-
|
38
|
+
vagrantfile = File.join(env[:root_path], (env[:vagrantfile_name] || "Vagrantfile"))
|
39
|
+
@description = !config.description.empty? ? config.description : "Source: #{vagrantfile}"
|
37
40
|
@uuid = config.uuid
|
38
41
|
@cpus = config.cpus.to_i
|
39
42
|
@cpuset = config.cpuset
|
@@ -265,7 +268,7 @@ module VagrantPlugins
|
|
265
268
|
end
|
266
269
|
env[:ui].info(" -- Storage pool: #{@storage_pool_name}")
|
267
270
|
@domain_volumes.each do |volume|
|
268
|
-
env[:ui].info(" -- Image(#{volume[:device]}): #{volume[:path]}, #{volume[:virtual_size]}G")
|
271
|
+
env[:ui].info(" -- Image(#{volume[:device]}): #{volume[:path]}, #{volume[:virtual_size].to_GB}G")
|
269
272
|
end
|
270
273
|
|
271
274
|
if not @disk_driver_opts.empty?
|
@@ -397,9 +400,14 @@ module VagrantPlugins
|
|
397
400
|
# Create Libvirt domain.
|
398
401
|
# Is there a way to tell fog to create new domain with already
|
399
402
|
# existing volume? Use domain creation from template..
|
403
|
+
xml = to_xml('domain')
|
404
|
+
@logger.debug {
|
405
|
+
"Creating Domain with XML:\n#{xml}"
|
406
|
+
}
|
407
|
+
|
400
408
|
begin
|
401
409
|
server = env[:machine].provider.driver.connection.servers.create(
|
402
|
-
xml:
|
410
|
+
xml: xml
|
403
411
|
)
|
404
412
|
rescue Fog::Errors::Error => e
|
405
413
|
raise Errors::FogCreateServerError, error_message: e.message
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
2
4
|
|
3
5
|
module VagrantPlugins
|
@@ -39,7 +41,7 @@ module VagrantPlugins
|
|
39
41
|
@backing_file = box_volume.path
|
40
42
|
|
41
43
|
# Virtual size of image. Take value worked out by HandleBoxImage
|
42
|
-
@capacity = env[:box_volumes][index][:virtual_size] #
|
44
|
+
@capacity = env[:box_volumes][index][:virtual_size].to_B # Byte
|
43
45
|
|
44
46
|
# Create new volume from xml template. Fog currently doesn't support
|
45
47
|
# volume snapshots directly.
|
@@ -47,7 +49,7 @@ module VagrantPlugins
|
|
47
49
|
xml = Nokogiri::XML::Builder.new do |xml|
|
48
50
|
xml.volume do
|
49
51
|
xml.name(@name)
|
50
|
-
xml.capacity(@capacity, unit: '
|
52
|
+
xml.capacity(@capacity, unit: 'B')
|
51
53
|
xml.target do
|
52
54
|
xml.format(type: 'qcow2')
|
53
55
|
xml.permissions do
|
@@ -76,6 +78,9 @@ module VagrantPlugins
|
|
76
78
|
else
|
77
79
|
pool_name = config.storage_pool_name
|
78
80
|
end
|
81
|
+
@logger.debug {
|
82
|
+
"Creating Volume with XML:\n#{xml}"
|
83
|
+
}
|
79
84
|
@logger.debug "Using pool #{pool_name} for base box snapshot"
|
80
85
|
domain_volume = env[:machine].provider.driver.connection.volumes.create(
|
81
86
|
xml: xml,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
2
4
|
require 'vagrant/util/network_ip'
|
3
5
|
require 'vagrant/util/scoped_hash_override'
|
@@ -128,10 +130,10 @@ module VagrantPlugins
|
|
128
130
|
end
|
129
131
|
|
130
132
|
message = "Creating network interface eth#{@iface_number}"
|
131
|
-
message
|
133
|
+
message += " connected to network #{@network_name}."
|
132
134
|
if @mac
|
133
135
|
@mac = @mac.scan(/(\h{2})/).join(':')
|
134
|
-
message
|
136
|
+
message += " Using MAC address: #{@mac}"
|
135
137
|
end
|
136
138
|
@logger.info(message)
|
137
139
|
|
@@ -157,6 +159,9 @@ module VagrantPlugins
|
|
157
159
|
else
|
158
160
|
to_xml(template_name)
|
159
161
|
end
|
162
|
+
@logger.debug {
|
163
|
+
"Attaching Network Device with XML:\n#{xml}"
|
164
|
+
}
|
160
165
|
domain.attach_device(xml)
|
161
166
|
rescue => e
|
162
167
|
raise Errors::AttachDeviceError,
|
@@ -246,6 +251,7 @@ module VagrantPlugins
|
|
246
251
|
udp_tunnel={}, pci_bus, pci_slot)
|
247
252
|
Nokogiri::XML::Builder.new do |xml|
|
248
253
|
xml.interface(type: type || 'network') do
|
254
|
+
xml.alias(name: "ua-net-#{iface_number}")
|
249
255
|
xml.source(source_options) do
|
250
256
|
xml.local(udp_tunnel) if type == 'udp'
|
251
257
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
2
4
|
require 'vagrant/util/network_ip'
|
3
5
|
require 'vagrant/util/scoped_hash_override'
|
@@ -160,7 +162,7 @@ module VagrantPlugins
|
|
160
162
|
if @interface_network[:created]
|
161
163
|
# Just check for mismatch error here - if name and ip from
|
162
164
|
# config match together.
|
163
|
-
if @options[:network_name] != @interface_network[:name]
|
165
|
+
if @options[:network_name] != @interface_network[:name] and @qemu_use_agent == false
|
164
166
|
raise Errors::NetworkNameAndAddressMismatch,
|
165
167
|
ip_address: @options[:ip],
|
166
168
|
network_name: @options[:network_name]
|
@@ -312,8 +314,7 @@ module VagrantPlugins
|
|
312
314
|
|
313
315
|
if @options[:dhcp_enabled]
|
314
316
|
# Find out DHCP addresses pool range.
|
315
|
-
network_address = "#{@interface_network[:network_address]}
|
316
|
-
network_address << (@interface_network[:netmask]).to_s
|
317
|
+
network_address = "#{@interface_network[:network_address]}/#{(@interface_network[:netmask]).to_s}"
|
317
318
|
net = @interface_network[:network_address] ? IPAddr.new(network_address) : nil
|
318
319
|
|
319
320
|
# First is address of network, second is gateway (by default).
|
@@ -336,8 +337,12 @@ module VagrantPlugins
|
|
336
337
|
@network_domain_name = @options[:domain_name]
|
337
338
|
|
338
339
|
begin
|
340
|
+
xml = to_xml('private_network')
|
341
|
+
@logger.debug {
|
342
|
+
"Creating private network with XML:\n#{xml}"
|
343
|
+
}
|
339
344
|
@interface_network[:libvirt_network] = \
|
340
|
-
@libvirt_client.define_network_xml(
|
345
|
+
@libvirt_client.define_network_xml(xml)
|
341
346
|
@logger.debug 'created network'
|
342
347
|
rescue => e
|
343
348
|
raise Errors::CreateNetworkError, error_message: e.message
|
@@ -345,10 +350,9 @@ module VagrantPlugins
|
|
345
350
|
|
346
351
|
created_networks_file = env[:machine].data_dir + 'created_networks'
|
347
352
|
|
348
|
-
message = 'Saving information about created network '
|
349
|
-
|
350
|
-
|
351
|
-
message << "to file #{created_networks_file}."
|
353
|
+
message = 'Saving information about created network ' \
|
354
|
+
"#{@interface_network[:name]}, UUID=#{@interface_network[:libvirt_network].uuid} " \
|
355
|
+
"to file #{created_networks_file}."
|
352
356
|
@logger.info(message)
|
353
357
|
|
354
358
|
File.open(created_networks_file, 'a') do |file|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module ProviderLibvirt
|
3
5
|
module Action
|
@@ -104,7 +106,7 @@ module VagrantPlugins
|
|
104
106
|
IdentitiesOnly=#{ssh_info[:keys_only] ? 'yes' : 'no'}
|
105
107
|
) + ssh_info[:private_key_path].map do |pk|
|
106
108
|
"IdentityFile='\"#{pk}\"'"
|
107
|
-
end).map { |s|
|
109
|
+
end).map { |s| "-o #{s}" }.join(' ')
|
108
110
|
|
109
111
|
options += " -o ProxyCommand=\"#{ssh_info[:proxy_command]}\"" if machine.provider_config.proxy_command
|
110
112
|
|
@@ -116,12 +118,12 @@ module VagrantPlugins
|
|
116
118
|
env[:ui].info 'Requesting sudo for host port(s) <= 1024'
|
117
119
|
r = system('sudo -v')
|
118
120
|
if r
|
119
|
-
ssh_cmd
|
121
|
+
ssh_cmd += 'sudo ' # add sudo prefix
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
124
|
-
ssh_cmd
|
126
|
+
ssh_cmd += "ssh -n #{options} #{params}"
|
125
127
|
|
126
128
|
@logger.debug "Forwarding port with `#{ssh_cmd}`"
|
127
129
|
log_file = ssh_forward_log_file(
|
@@ -180,10 +182,10 @@ module VagrantPlugins
|
|
180
182
|
kill_cmd = ''
|
181
183
|
|
182
184
|
if tag[:port] <= 1024
|
183
|
-
kill_cmd
|
185
|
+
kill_cmd += 'sudo ' # add sudo prefix
|
184
186
|
end
|
185
187
|
|
186
|
-
kill_cmd
|
188
|
+
kill_cmd += "kill #{tag[:pid]}"
|
187
189
|
@@lock.synchronize do
|
188
190
|
system(kill_cmd)
|
189
191
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
2
4
|
|
3
5
|
module VagrantPlugins
|
@@ -11,41 +13,9 @@ module VagrantPlugins
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def call(env)
|
14
|
-
env[:ui].info(I18n.t('vagrant_libvirt.halt_domain'))
|
15
|
-
|
16
|
-
timeout = env[:machine].config.vm.graceful_halt_timeout
|
17
16
|
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
18
|
-
|
19
|
-
|
20
|
-
if env[:force_halt]
|
21
|
-
domain.poweroff
|
22
|
-
return @app.call(env)
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
Timeout.timeout(timeout) do
|
27
|
-
begin
|
28
|
-
env[:machine].guest.capability(:halt)
|
29
|
-
rescue Timeout::Error
|
30
|
-
raise
|
31
|
-
rescue
|
32
|
-
@logger.info('Trying Libvirt graceful shutdown.')
|
33
|
-
# Read domain object again
|
34
|
-
dom = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
35
|
-
if dom.state.to_s == 'running'
|
36
|
-
dom.shutdown
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
domain.wait_for(timeout) do
|
41
|
-
!ready?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
rescue Timeout::Error
|
45
|
-
@logger.info('VM is still running. Calling force poweroff.')
|
46
|
-
domain.poweroff
|
47
|
-
rescue
|
48
|
-
@logger.error('Failed to shutdown cleanly. Calling force poweroff.')
|
17
|
+
if env[:machine].state.id == :running
|
18
|
+
env[:ui].info(I18n.t('vagrant_libvirt.halt_domain'))
|
49
19
|
domain.poweroff
|
50
20
|
end
|
51
21
|
|
@@ -1,4 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'log4r'
|
4
|
+
require 'open3'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require 'vagrant-libvirt/util/byte_number'
|
2
8
|
|
3
9
|
module VagrantPlugins
|
4
10
|
module ProviderLibvirt
|
@@ -64,7 +70,7 @@ module VagrantPlugins
|
|
64
70
|
{
|
65
71
|
:path => image_path,
|
66
72
|
:name => volume_name,
|
67
|
-
:virtual_size => virtual_size
|
73
|
+
:virtual_size => virtual_size,
|
68
74
|
:format => HandleBoxImage.verify_box_format(format)
|
69
75
|
}
|
70
76
|
}
|
@@ -80,16 +86,17 @@ module VagrantPlugins
|
|
80
86
|
# Override box_virtual_size
|
81
87
|
box_virtual_size = env[:box_volumes][0][:virtual_size]
|
82
88
|
if config.machine_virtual_size
|
83
|
-
|
89
|
+
config_machine_virtual_size = ByteNumber.from_GB(config.machine_virtual_size)
|
90
|
+
if config_machine_virtual_size < box_virtual_size
|
84
91
|
# Warn that a virtual size less than the box metadata size
|
85
92
|
# is not supported and will be ignored
|
86
93
|
env[:ui].warn I18n.t(
|
87
94
|
'vagrant_libvirt.warnings.ignoring_virtual_size_too_small',
|
88
|
-
requested:
|
95
|
+
requested: config_machine_virtual_size.to_GB, minimum: box_virtual_size.to_GB
|
89
96
|
)
|
90
97
|
else
|
91
98
|
env[:ui].info I18n.t('vagrant_libvirt.manual_resize_required')
|
92
|
-
box_virtual_size =
|
99
|
+
box_virtual_size = config_machine_virtual_size
|
93
100
|
end
|
94
101
|
end
|
95
102
|
# save for use by later actions
|
@@ -130,7 +137,7 @@ module VagrantPlugins
|
|
130
137
|
# Virtual size has to be set for allocating space in storage pool.
|
131
138
|
box_virtual_size = env[:machine].box.metadata['virtual_size']
|
132
139
|
raise Errors::NoBoxVirtualSizeSet if box_virtual_size.nil?
|
133
|
-
return box_virtual_size
|
140
|
+
return ByteNumber.from_GB(box_virtual_size)
|
134
141
|
end
|
135
142
|
|
136
143
|
def self.get_box_image_path(box, box_name)
|
@@ -152,14 +159,14 @@ module VagrantPlugins
|
|
152
159
|
end
|
153
160
|
|
154
161
|
def self.get_box_disk_settings(image_path)
|
155
|
-
stdout, stderr, status = Open3.capture3('qemu-img', 'info', image_path)
|
162
|
+
stdout, stderr, status = Open3.capture3('qemu-img', 'info', '--output=json', image_path)
|
156
163
|
if !status.success?
|
157
164
|
raise Errors::BadBoxImage, image: image_path, out: stdout, err: stderr
|
158
165
|
end
|
159
166
|
|
160
|
-
|
161
|
-
format =
|
162
|
-
virtual_size =
|
167
|
+
image_info = JSON.parse(stdout)
|
168
|
+
format = image_info['format']
|
169
|
+
virtual_size = ByteNumber.new(image_info['virtual-size'])
|
163
170
|
|
164
171
|
return format, virtual_size
|
165
172
|
end
|
@@ -174,15 +181,13 @@ module VagrantPlugins
|
|
174
181
|
raise Vagrant::Errors::BoxNotFound, name: env[:machine].box.name
|
175
182
|
end
|
176
183
|
box_image_size = File.size(box_image_file) # B
|
177
|
-
message = "Creating volume #{box_volume[:name]}"
|
178
|
-
message << " in storage pool #{config.storage_pool_name}."
|
184
|
+
message = "Creating volume #{box_volume[:name]} in storage pool #{config.storage_pool_name}."
|
179
185
|
@logger.info(message)
|
180
|
-
|
181
186
|
begin
|
182
187
|
fog_volume = env[:machine].provider.driver.connection.volumes.create(
|
183
188
|
name: box_volume[:name],
|
184
189
|
allocation: "#{box_image_size / 1024 / 1024}M",
|
185
|
-
capacity: "#{box_volume[:virtual_size]}
|
190
|
+
capacity: "#{box_volume[:virtual_size].to_B}B",
|
186
191
|
format_type: box_volume[:format],
|
187
192
|
owner: storage_uid(env),
|
188
193
|
group: storage_gid(env),
|