vagrant-qemu 0.3.6 → 0.3.7

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: 47636dd2f589218fd058d32661aa2844a842ea0c1fce7c4fbf1bceb5efc58bea
4
- data.tar.gz: d4e04639beb03206cdcb5a09c2b63d608efe18b623ede070d6b2a4a1bafb452e
3
+ metadata.gz: aa6a7877a0f30cbe820b09bfb481863f115758c542c92f02570641c3057983de
4
+ data.tar.gz: 74151d323890fcf318b74af5c251ae9413f8089429a700ac51e1e3f57d0e693f
5
5
  SHA512:
6
- metadata.gz: 80ef6dbcb15d76fc97296b178416aaede61bcf4133fc38cac83fd92854cc1e92c8159b49ff961939e498a344b33a328fe87a6995675b65d91a6286d2ae0334ed
7
- data.tar.gz: bad9fba78583cb6cb236e81728eba6d9fd53747b25abfe94b1227e0258364e536c093a126a3daea13a72e7bb1403df86710739032b931012ceee7f2a529dadd1
6
+ metadata.gz: e0bc88d099f46ce974eb217025108e86d6ab14ca7efe199450e7ddf1e9364ebe24d466175067f3cf30f470864981251cecb46b3bffdfa070f6e7caf67906249b
7
+ data.tar.gz: 3d7e6b3486b69cf0a7ff5ebdcd536bda37ea5f733e6eb89677746d27b3e6169f12e369ce31d6b02dfacb7e6145719c656afed238796bba8338b8f11fc69deacb
data/CHANGELOG.md CHANGED
@@ -71,3 +71,9 @@
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
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,23 @@ 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
  # remap ssh.host to ssh_port
23
25
  if options[:id] == "ssh"
24
26
  remap[options[:host]] = machine.provider_config.ssh_port
27
+ has_ssh_forward = true
25
28
  break
26
29
  end
27
30
  end
28
31
 
32
+ if !has_ssh_forward
33
+ machine.config.vm.networks.forward_port(22, machine.provider_config.ssh_port, [id: "ssh", auto_correct: machine.provider_config.ssh_auto_correct])
34
+ end
35
+
29
36
  @app.call(env)
30
37
  end
31
38
  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] != :not_created
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 => forwarded_ports(env),
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
- next if options[:id] == "ssh"
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]
@@ -116,7 +116,7 @@ module VagrantPlugins
116
116
  end
117
117
 
118
118
  b1.use Provision
119
- b1.use EnvSet, port_collision_repair: false
119
+ b1.use EnvSet, port_collision_repair: true
120
120
  b1.use PrepareForwardedPortCollisionParams
121
121
  b1.use HandleForwardedPortCollisions
122
122
  b1.use SyncedFolderCleanup
@@ -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
@@ -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
- class Driver
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
- end
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 = @data_dir.join(@vm_id).join("qemu.pid")
205
+ pid_file = @tmp_dir.join(@vm_id).join("qemu.pid")
189
206
  return false if !pid_file.file?
190
207
 
191
208
  begin
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module QEMU
3
- VERSION = '0.3.6'
3
+ VERSION = '0.3.7'
4
4
  end
5
5
  end
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.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ppggff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-27 00:00:00.000000000 Z
11
+ date: 2025-02-02 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