vagrant-qemu 0.3.6 → 0.3.8
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +42 -1
- data/lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb +16 -2
- data/lib/vagrant-qemu/action/read_state.rb +5 -0
- data/lib/vagrant-qemu/action/start_instance.rb +8 -2
- data/lib/vagrant-qemu/action.rb +1 -1
- data/lib/vagrant-qemu/config.rb +3 -0
- data/lib/vagrant-qemu/driver.rb +23 -6
- data/lib/vagrant-qemu/version.rb +1 -1
- data/x +76 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad58eff4d1ca4ecc7899ccd8f5cf5e13497a0ba7f226dc425858f89a59cc2151
|
4
|
+
data.tar.gz: b91caf53e6f505b0ec6e7a6aefd4773f0205fcfff35f1015f915a4ce9056a0aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56885cedf852f75eaf87b6ab73904eb43a7775d36a7586a2f5558905726ccf0d5ebdafb69ea5fe9f6e34733b404d49245d7a87c0224d6c25e7aeb21b547eedd3
|
7
|
+
data.tar.gz: a7d03a0326ffe78dfad134a11cc402a091a872c97b3bbf5fea0c769a3712f604fc2efa544cff29d2a8ccb34cb82af086a6f5a7ff8dbfb4bdb7cee387354c63e9
|
data/CHANGELOG.md
CHANGED
@@ -71,3 +71,13 @@
|
|
71
71
|
|
72
72
|
* Config 'image_path' support array type
|
73
73
|
* Try to support libvirt box v2 format
|
74
|
+
|
75
|
+
# 0.3.7 (2025-02-02)
|
76
|
+
|
77
|
+
* Ignore exception after sending 'system_powerdown' cmd, fix windows halt error
|
78
|
+
* Move pid file to tmp dir
|
79
|
+
* Be able to auto correct ssh port collisions, new config: ssh_auto_correct
|
80
|
+
|
81
|
+
# 0.3.8 (2025-02-21)
|
82
|
+
|
83
|
+
* Fix regression that ssh_port is not working #68
|
data/README.md
CHANGED
@@ -86,6 +86,7 @@ This provider exposes a few provider-specific configuration options:
|
|
86
86
|
* `memory` - The memory setting of VM, default: `4G`
|
87
87
|
* debug/expert
|
88
88
|
* `ssh_host` - The SSH IP used to access VM, default: `127.0.0.1`
|
89
|
+
* `ssh_auto_correct` - Auto correct port collisions for ssh port, default: `false`
|
89
90
|
* `net_device` - The network device, default: `virtio-net-device`
|
90
91
|
* `drive_interface` - The interface type for the main drive, default `virtio`
|
91
92
|
* `image_path` - The path (or array of paths) to qcow2 image for box-less VM, default is nil value
|
@@ -226,7 +227,6 @@ end
|
|
226
227
|
8. Windows host
|
227
228
|
|
228
229
|
Windows version QEMU doesn't support `daemonize` mode and unix socket
|
229
|
-
(Notes: not tested)
|
230
230
|
|
231
231
|
```
|
232
232
|
Vagrant.configure("2") do |config|
|
@@ -240,6 +240,32 @@ Vagrant.configure("2") do |config|
|
|
240
240
|
end
|
241
241
|
```
|
242
242
|
|
243
|
+
9. Auto port collisions for ssh port (multiple machine)
|
244
|
+
|
245
|
+
```
|
246
|
+
Vagrant.configure("2") do |config|
|
247
|
+
|
248
|
+
config.vm.define "vm1" do |c|
|
249
|
+
c.vm.box = "ppggff/centos-7-aarch64-2009-4K"
|
250
|
+
c.vm.provider "qemu" do |qe|
|
251
|
+
qe.memory = "2G"
|
252
|
+
qe.ssh_auto_correct = true
|
253
|
+
end
|
254
|
+
c.vm.synced_folder ".", "/vagrant", disabled: true
|
255
|
+
end
|
256
|
+
|
257
|
+
config.vm.define "vm2" do |c|
|
258
|
+
c.vm.box = "ppggff/centos-7-aarch64-2009-4K"
|
259
|
+
c.vm.provider "qemu" do |qe|
|
260
|
+
qe.memory = "2G"
|
261
|
+
qe.ssh_auto_correct = true
|
262
|
+
end
|
263
|
+
c.vm.synced_folder ".", "/vagrant", disabled: true
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
```
|
268
|
+
|
243
269
|
## Debug
|
244
270
|
|
245
271
|
Serial port is exported to unix socket: `<user_home>/.vagrant.d/tmp/vagrant-qemu/<id>/qemu_socket_serial`, or `debug_port`.
|
@@ -299,6 +325,21 @@ Vagrant.configure("2") do |config|
|
|
299
325
|
end
|
300
326
|
```
|
301
327
|
|
328
|
+
As an alternative solution(helpful for macOS) it is possible to use 9p file system via virtio.
|
329
|
+
|
330
|
+
```
|
331
|
+
config.vm.synced_folder ".", "/vagrant", disabled: true
|
332
|
+
config.vm.provider "qemu" do |qe|
|
333
|
+
qe.extra_qemu_args = %w(-virtfs local,path=.,mount_tag=shared,security_model=mapped)
|
334
|
+
end
|
335
|
+
```
|
336
|
+
This will pass "current directory" to mount point tagged "shared"
|
337
|
+
Use the following /etc/fstab entry on the vagrant vm to mount the shared directory into /home/vagrant/shared
|
338
|
+
```
|
339
|
+
shared /home/vagrant/shared 9p _netdev,trans=virtio,msize=524288 0
|
340
|
+
```
|
341
|
+
Please keep in mind that the guest OS will need to install 9p dependencies to handle the 9p filestystem.
|
342
|
+
|
302
343
|
### 2. netcat does not support the -U parameter
|
303
344
|
|
304
345
|
I had netcat installed through home brew and it does not support the -U parameter.
|
@@ -16,16 +16,30 @@ module VagrantPlugins
|
|
16
16
|
# Build the remap for any existing collision detections
|
17
17
|
remap = {}
|
18
18
|
env[:port_collision_remap] = remap
|
19
|
+
|
20
|
+
has_ssh_forward = false
|
19
21
|
machine.config.vm.networks.each do |type, options|
|
20
22
|
next if type != :forwarded_port
|
21
23
|
|
22
|
-
#
|
24
|
+
# update ssh.host to ssh_port
|
23
25
|
if options[:id] == "ssh"
|
24
|
-
|
26
|
+
options[:host] = machine.provider_config.ssh_port
|
27
|
+
options[:auto_correct] = machine.provider_config.ssh_auto_correct
|
28
|
+
has_ssh_forward = true
|
25
29
|
break
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
33
|
+
if !has_ssh_forward
|
34
|
+
machine.config.vm.network :forwarded_port,
|
35
|
+
:guest => 22,
|
36
|
+
:host => machine.provider_config.ssh_port,
|
37
|
+
:host_ip => "127.0.0.1",
|
38
|
+
:id => "ssh",
|
39
|
+
:auto_correct => machine.provider_config.ssh_auto_correct,
|
40
|
+
:protocol => "tcp"
|
41
|
+
end
|
42
|
+
|
29
43
|
@app.call(env)
|
30
44
|
end
|
31
45
|
end
|
@@ -23,6 +23,11 @@ module VagrantPlugins
|
|
23
23
|
else
|
24
24
|
env[:machine_state_id] = :not_created
|
25
25
|
end
|
26
|
+
|
27
|
+
# Update ssh_port if needed
|
28
|
+
if env[:machine_state_id] == :running
|
29
|
+
env[:machine].provider_config.ssh_port = env[:machine].provider.driver.get_ssh_port(env[:machine].provider_config.ssh_port)
|
30
|
+
end
|
26
31
|
@app.call(env)
|
27
32
|
end
|
28
33
|
end
|
@@ -11,6 +11,7 @@ module VagrantPlugins
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
14
|
+
fwPorts = forwarded_ports(env)
|
14
15
|
options = {
|
15
16
|
:ssh_host => env[:machine].provider_config.ssh_host,
|
16
17
|
:ssh_port => env[:machine].provider_config.ssh_port,
|
@@ -23,7 +24,7 @@ module VagrantPlugins
|
|
23
24
|
:drive_interface => env[:machine].provider_config.drive_interface,
|
24
25
|
:extra_qemu_args => env[:machine].provider_config.extra_qemu_args,
|
25
26
|
:extra_netdev_args => env[:machine].provider_config.extra_netdev_args,
|
26
|
-
:ports =>
|
27
|
+
:ports => fwPorts,
|
27
28
|
:control_port => env[:machine].provider_config.control_port,
|
28
29
|
:debug_port => env[:machine].provider_config.debug_port,
|
29
30
|
:no_daemonize => env[:machine].provider_config.no_daemonize,
|
@@ -43,7 +44,12 @@ module VagrantPlugins
|
|
43
44
|
next if type != :forwarded_port
|
44
45
|
|
45
46
|
# Don't include SSH
|
46
|
-
|
47
|
+
if options[:id] == "ssh"
|
48
|
+
if options[:host] != env[:machine].provider_config.ssh_port
|
49
|
+
env[:machine].provider_config.ssh_port = options[:host]
|
50
|
+
end
|
51
|
+
next
|
52
|
+
end
|
47
53
|
|
48
54
|
# Skip port if it is disabled
|
49
55
|
next if options[:disabled]
|
data/lib/vagrant-qemu/action.rb
CHANGED
@@ -116,7 +116,7 @@ module VagrantPlugins
|
|
116
116
|
end
|
117
117
|
|
118
118
|
b1.use Provision
|
119
|
-
b1.use EnvSet, port_collision_repair:
|
119
|
+
b1.use EnvSet, port_collision_repair: true
|
120
120
|
b1.use PrepareForwardedPortCollisionParams
|
121
121
|
b1.use HandleForwardedPortCollisions
|
122
122
|
b1.use SyncedFolderCleanup
|
data/lib/vagrant-qemu/config.rb
CHANGED
@@ -5,6 +5,7 @@ module VagrantPlugins
|
|
5
5
|
class Config < Vagrant.plugin("2", :config)
|
6
6
|
attr_accessor :ssh_host
|
7
7
|
attr_accessor :ssh_port
|
8
|
+
attr_accessor :ssh_auto_correct
|
8
9
|
attr_accessor :arch
|
9
10
|
attr_accessor :machine
|
10
11
|
attr_accessor :cpu
|
@@ -25,6 +26,7 @@ module VagrantPlugins
|
|
25
26
|
def initialize
|
26
27
|
@ssh_host = UNSET_VALUE
|
27
28
|
@ssh_port = UNSET_VALUE
|
29
|
+
@ssh_auto_correct = UNSET_VALUE
|
28
30
|
@arch = UNSET_VALUE
|
29
31
|
@machine = UNSET_VALUE
|
30
32
|
@cpu = UNSET_VALUE
|
@@ -55,6 +57,7 @@ module VagrantPlugins
|
|
55
57
|
def finalize!
|
56
58
|
@ssh_host = "127.0.0.1" if @ssh_host == UNSET_VALUE
|
57
59
|
@ssh_port = 50022 if @ssh_port == UNSET_VALUE
|
60
|
+
@ssh_auto_correct = false if @ssh_auto_correct == UNSET_VALUE
|
58
61
|
@arch = "aarch64" if @arch == UNSET_VALUE
|
59
62
|
@machine = "virt,accel=hvf,highmem=on" if @machine == UNSET_VALUE
|
60
63
|
@cpu = "host" if @cpu == UNSET_VALUE
|
data/lib/vagrant-qemu/driver.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'childprocess'
|
2
2
|
require 'securerandom'
|
3
|
+
require 'yaml'
|
3
4
|
|
4
5
|
require "vagrant/util/busy"
|
5
6
|
require 'vagrant/util/io'
|
@@ -10,7 +11,7 @@ require_relative "plugin"
|
|
10
11
|
|
11
12
|
module VagrantPlugins
|
12
13
|
module QEMU
|
13
|
-
|
14
|
+
class Driver
|
14
15
|
# @return [String] VM ID
|
15
16
|
attr_reader :vm_id
|
16
17
|
attr_reader :data_dir
|
@@ -45,7 +46,6 @@ module VagrantPlugins
|
|
45
46
|
def start(options)
|
46
47
|
if !running?
|
47
48
|
id_dir = @data_dir.join(@vm_id)
|
48
|
-
pid_file = id_dir.join("qemu.pid").to_s
|
49
49
|
|
50
50
|
image_path = Array.new
|
51
51
|
image_count = id_dir.glob("linked-box*.img").count
|
@@ -57,6 +57,10 @@ module VagrantPlugins
|
|
57
57
|
id_tmp_dir = @tmp_dir.join(@vm_id)
|
58
58
|
FileUtils.mkdir_p(id_tmp_dir)
|
59
59
|
|
60
|
+
# dump options
|
61
|
+
options_file = id_tmp_dir.join("options.yml")
|
62
|
+
File.write(options_file, options.to_yaml)
|
63
|
+
|
60
64
|
control_socket = ""
|
61
65
|
if !options[:control_port].nil?
|
62
66
|
control_socket = "port=#{options[:control_port]},host=localhost,ipv4=on"
|
@@ -113,6 +117,7 @@ module VagrantPlugins
|
|
113
117
|
end
|
114
118
|
|
115
119
|
# control
|
120
|
+
pid_file = id_tmp_dir.join("qemu.pid").to_s
|
116
121
|
cmd += %W(-chardev socket,id=mon0,#{control_socket},server=on,wait=off)
|
117
122
|
cmd += %W(-mon chardev=mon0,mode=readline)
|
118
123
|
cmd += %W(-chardev socket,id=ser0,#{debug_socket},server=on,wait=off)
|
@@ -139,7 +144,7 @@ module VagrantPlugins
|
|
139
144
|
Socket.tcp("localhost", options[:control_port], connect_timeout: 5) do |sock|
|
140
145
|
sock.print "system_powerdown\n"
|
141
146
|
sock.close_write
|
142
|
-
sock.read
|
147
|
+
sock.read rescue nil
|
143
148
|
end
|
144
149
|
else
|
145
150
|
id_tmp_dir = @tmp_dir.join(@vm_id)
|
@@ -147,12 +152,24 @@ module VagrantPlugins
|
|
147
152
|
Socket.unix(unix_socket_path) do |sock|
|
148
153
|
sock.print "system_powerdown\n"
|
149
154
|
sock.close_write
|
150
|
-
sock.read
|
155
|
+
sock.read rescue nil
|
151
156
|
end
|
152
|
-
|
157
|
+
end
|
153
158
|
end
|
154
159
|
end
|
155
160
|
|
161
|
+
def get_ssh_port(ssh_port)
|
162
|
+
id_tmp_dir = @tmp_dir.join(@vm_id)
|
163
|
+
options_file = id_tmp_dir.join("options.yml")
|
164
|
+
|
165
|
+
if options_file.file?
|
166
|
+
options = YAML.load_file(options_file) rescue nil
|
167
|
+
ssh_port = options[:ssh_port] if !options.nil? && options.key?(:ssh_port)
|
168
|
+
end
|
169
|
+
|
170
|
+
ssh_port
|
171
|
+
end
|
172
|
+
|
156
173
|
def import(options)
|
157
174
|
new_id = "vq_" + SecureRandom.urlsafe_base64(8)
|
158
175
|
|
@@ -185,7 +202,7 @@ module VagrantPlugins
|
|
185
202
|
end
|
186
203
|
|
187
204
|
def running?
|
188
|
-
pid_file = @
|
205
|
+
pid_file = @tmp_dir.join(@vm_id).join("qemu.pid")
|
189
206
|
return false if !pid_file.file?
|
190
207
|
|
191
208
|
begin
|
data/lib/vagrant-qemu/version.rb
CHANGED
data/x
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
diff --git a/lib/vagrant-qemu/action.rb b/lib/vagrant-qemu/action.rb
|
2
|
+
index bb87e38..8818aa9 100644
|
3
|
+
--- a/lib/vagrant-qemu/action.rb
|
4
|
+
+++ b/lib/vagrant-qemu/action.rb
|
5
|
+
@@ -116,7 +116,7 @@ module VagrantPlugins
|
6
|
+
end
|
7
|
+
|
8
|
+
b1.use Provision
|
9
|
+
- b1.use EnvSet, port_collision_repair: false
|
10
|
+
+ b1.use EnvSet, port_collision_repair: true
|
11
|
+
b1.use PrepareForwardedPortCollisionParams
|
12
|
+
b1.use HandleForwardedPortCollisions
|
13
|
+
b1.use SyncedFolderCleanup
|
14
|
+
diff --git a/lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb b/lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb
|
15
|
+
index 159a785..b7c93a3 100644
|
16
|
+
--- a/lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb
|
17
|
+
+++ b/lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb
|
18
|
+
@@ -16,16 +16,23 @@ module VagrantPlugins
|
19
|
+
# Build the remap for any existing collision detections
|
20
|
+
remap = {}
|
21
|
+
env[:port_collision_remap] = remap
|
22
|
+
+
|
23
|
+
+ has_ssh_forward = false
|
24
|
+
machine.config.vm.networks.each do |type, options|
|
25
|
+
next if type != :forwarded_port
|
26
|
+
|
27
|
+
# remap ssh.host to ssh_port
|
28
|
+
if options[:id] == "ssh"
|
29
|
+
remap[options[:host]] = machine.provider_config.ssh_port
|
30
|
+
+ has_ssh_forward = true
|
31
|
+
break
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
+ if !has_ssh_forward
|
36
|
+
+ machine.config.vm.networks.forward_port(22, machine.provider_config.ssh_port, [id: "ssh", auto_correct: true])
|
37
|
+
+ end
|
38
|
+
+
|
39
|
+
@app.call(env)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
diff --git a/lib/vagrant-qemu/action/start_instance.rb b/lib/vagrant-qemu/action/start_instance.rb
|
43
|
+
index 13c1d9d..b434bb3 100644
|
44
|
+
--- a/lib/vagrant-qemu/action/start_instance.rb
|
45
|
+
+++ b/lib/vagrant-qemu/action/start_instance.rb
|
46
|
+
@@ -11,6 +11,7 @@ module VagrantPlugins
|
47
|
+
end
|
48
|
+
|
49
|
+
def call(env)
|
50
|
+
+ fwPorts = forwarded_ports(env)
|
51
|
+
options = {
|
52
|
+
:ssh_host => env[:machine].provider_config.ssh_host,
|
53
|
+
:ssh_port => env[:machine].provider_config.ssh_port,
|
54
|
+
@@ -23,7 +24,7 @@ module VagrantPlugins
|
55
|
+
:drive_interface => env[:machine].provider_config.drive_interface,
|
56
|
+
:extra_qemu_args => env[:machine].provider_config.extra_qemu_args,
|
57
|
+
:extra_netdev_args => env[:machine].provider_config.extra_netdev_args,
|
58
|
+
- :ports => forwarded_ports(env),
|
59
|
+
+ :ports => fwPorts,
|
60
|
+
:control_port => env[:machine].provider_config.control_port,
|
61
|
+
:debug_port => env[:machine].provider_config.debug_port,
|
62
|
+
:no_daemonize => env[:machine].provider_config.no_daemonize,
|
63
|
+
@@ -43,7 +44,12 @@ module VagrantPlugins
|
64
|
+
next if type != :forwarded_port
|
65
|
+
|
66
|
+
# Don't include SSH
|
67
|
+
- next if options[:id] == "ssh"
|
68
|
+
+ if options[:id] == "ssh"
|
69
|
+
+ if options[:host] != env[:machine].provider_config.ssh_port
|
70
|
+
+ env[:machine].provider_config.ssh_port = options[:host]
|
71
|
+
+ end
|
72
|
+
+ next
|
73
|
+
+ end
|
74
|
+
|
75
|
+
# Skip port if it is disabled
|
76
|
+
next if options[:disabled]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-qemu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ppggff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Enables Vagrant to manage machines with QEMU.
|
14
14
|
email: pgf00a@gmail.com
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/vagrant-qemu/version.rb
|
44
44
|
- locales/en.yml
|
45
45
|
- vagrant-qemu.gemspec
|
46
|
+
- x
|
46
47
|
homepage: https://github.com/ppggff/vagrant-qemu
|
47
48
|
licenses:
|
48
49
|
- MIT
|