vagrant-qemu 0.1.6 → 0.1.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +28 -1
- data/lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb +26 -0
- data/lib/vagrant-qemu/action/start_instance.rb +23 -0
- data/lib/vagrant-qemu/action.rb +4 -0
- data/lib/vagrant-qemu/driver.rb +20 -5
- data/lib/vagrant-qemu/provider.rb +1 -1
- data/lib/vagrant-qemu/version.rb +1 -1
- 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: bd9a87ef8218106cb56d6d2482611ebd09b62fd10e5db9b67c40e0067c8d7872
|
|
4
|
+
data.tar.gz: 838154d84757fdc3d7a6dab09da20a4636f8ab6ab6ccec9254f7d39f3af580c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b711ec022033763ea5900e01b2498a20cda7117ac2b03a82f1ca3934aebe95fc8c8bc8388f584cc8906641a43a5c7ea1f359ea5593fe5820440eb239ed2212d
|
|
7
|
+
data.tar.gz: 245de895d3a118525a5fdb5545e271b43f98bc50b596bcb0da26d3814c97abd3f2c8ee925eede68015087dffaac156a2f51bab424231ad06416818ae8ab9df25
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -13,6 +13,7 @@ to control and provision machines using QEMU.
|
|
|
13
13
|
* Provision the instances with any built-in Vagrant provisioner
|
|
14
14
|
* Synced folder support via SMB
|
|
15
15
|
* Basic operation: up, ssh, halt, destroy
|
|
16
|
+
* Basic suport to forwarded ports, see [vagrant doc](https://www.vagrantup.com/docs/networking/forwarded_ports) for details
|
|
16
17
|
|
|
17
18
|
## Usage
|
|
18
19
|
|
|
@@ -58,6 +59,7 @@ This provider exposes a few provider-specific configuration options:
|
|
|
58
59
|
* `cpu` - The cpu model of VM, default: `cortex-a72`
|
|
59
60
|
* `smp` - The smp setting (Simulate an SMP system with n CPUs) of VM, default: `2`
|
|
60
61
|
* `memory` - The memory setting of VM, default: `4G`
|
|
62
|
+
* `net_device` - The network device, default: `virtio-net-device`
|
|
61
63
|
* `image_path` - The path to qcow2 image for box-less VM, default is nil value
|
|
62
64
|
* `qemu_dir` - The path to QEMU's install dir, default: `/opt/homebrew/share/qemu`
|
|
63
65
|
|
|
@@ -108,6 +110,32 @@ Vagrant.configure(2) do |config|
|
|
|
108
110
|
end
|
|
109
111
|
```
|
|
110
112
|
|
|
113
|
+
4. Work with a x86_64 box (basic config)
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Vagrant.configure(2) do |config|
|
|
117
|
+
config.vm.box = "centos/7"
|
|
118
|
+
|
|
119
|
+
config.vm.provider "qemu" do |qe|
|
|
120
|
+
qe.arch = "x86_64"
|
|
121
|
+
qe.machine = "q35"
|
|
122
|
+
qe.cpu = "max"
|
|
123
|
+
qe.net_device = "virtio-net-pci"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
5. Forwarded ports
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
# Basic Vagrant config (API version 2)
|
|
132
|
+
Vagrant.configure(2) do |config|
|
|
133
|
+
# ... other stuff
|
|
134
|
+
|
|
135
|
+
config.vm.network "forwarded", guest: 80, host: 8080
|
|
136
|
+
end
|
|
137
|
+
```
|
|
138
|
+
|
|
111
139
|
## Build
|
|
112
140
|
|
|
113
141
|
To build the `vagrant-qemu` plugin, clone this repository out, and use
|
|
@@ -127,7 +155,6 @@ bundle exec rake build
|
|
|
127
155
|
|
|
128
156
|
* Support NFS shared folder
|
|
129
157
|
* Support package VM to box
|
|
130
|
-
* Test on more architectures
|
|
131
158
|
* More configures
|
|
132
159
|
* Better error messages
|
|
133
160
|
* Network
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module QEMU
|
|
3
|
+
module Action
|
|
4
|
+
class PrepareForwardedPortCollisionParams
|
|
5
|
+
def initialize(app, env)
|
|
6
|
+
@app = app
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(env)
|
|
10
|
+
machine = env[:machine]
|
|
11
|
+
|
|
12
|
+
# TODO: not supported
|
|
13
|
+
other_used_ports = {}
|
|
14
|
+
env[:port_collision_extra_in_use] = other_used_ports
|
|
15
|
+
|
|
16
|
+
# Build the remap for any existing collision detections
|
|
17
|
+
remap = {}
|
|
18
|
+
env[:port_collision_remap] = remap
|
|
19
|
+
|
|
20
|
+
@app.call(env)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
@@ -19,12 +19,35 @@ module VagrantPlugins
|
|
|
19
19
|
:smp => env[:machine].provider_config.smp,
|
|
20
20
|
:memory => env[:machine].provider_config.memory,
|
|
21
21
|
:net_device => env[:machine].provider_config.net_device,
|
|
22
|
+
:ports => forwarded_ports(env)
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
env[:ui].output(I18n.t("vagrant_qemu.starting"))
|
|
25
26
|
env[:machine].provider.driver.start(options)
|
|
26
27
|
@app.call(env)
|
|
27
28
|
end
|
|
29
|
+
|
|
30
|
+
def forwarded_ports(env)
|
|
31
|
+
result = []
|
|
32
|
+
|
|
33
|
+
env[:machine].config.vm.networks.each do |type, options|
|
|
34
|
+
next if type != :forwarded_port
|
|
35
|
+
|
|
36
|
+
# Don't include SSH
|
|
37
|
+
next if options[:id] == "ssh"
|
|
38
|
+
|
|
39
|
+
# Skip port if it is disabled
|
|
40
|
+
next if options[:disabled]
|
|
41
|
+
|
|
42
|
+
host_ip = ""
|
|
43
|
+
host_ip = "#{options[:host_ip]}:" if options[:host_ip]
|
|
44
|
+
guest_ip = ""
|
|
45
|
+
guest_ip = "#{options[:guest_ip]}:" if options[:guest_ip]
|
|
46
|
+
result.push("#{options[:protocol]}:#{host_ip}:#{options[:host]}-#{guest_ip}:#{options[:guest]}")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
result
|
|
50
|
+
end
|
|
28
51
|
end
|
|
29
52
|
end
|
|
30
53
|
end
|
data/lib/vagrant-qemu/action.rb
CHANGED
|
@@ -116,6 +116,9 @@ module VagrantPlugins
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
b1.use Provision
|
|
119
|
+
b1.use EnvSet, port_collision_repair: false
|
|
120
|
+
b1.use PrepareForwardedPortCollisionParams
|
|
121
|
+
b1.use HandleForwardedPortCollisions
|
|
119
122
|
b1.use SyncedFolderCleanup
|
|
120
123
|
b1.use SyncedFolders
|
|
121
124
|
b1.use WarnNetworks
|
|
@@ -169,6 +172,7 @@ module VagrantPlugins
|
|
|
169
172
|
autoload :Destroy, action_root.join("destroy")
|
|
170
173
|
autoload :TimedProvision, action_root.join("timed_provision") # some plugins now expect this action to exist
|
|
171
174
|
autoload :WarnNetworks, action_root.join("warn_networks")
|
|
175
|
+
autoload :PrepareForwardedPortCollisionParams, action_root.join("prepare_forwarded_port_collision_params")
|
|
172
176
|
end
|
|
173
177
|
end
|
|
174
178
|
end
|
data/lib/vagrant-qemu/driver.rb
CHANGED
|
@@ -11,10 +11,12 @@ module VagrantPlugins
|
|
|
11
11
|
# @return [String] VM ID
|
|
12
12
|
attr_reader :vm_id
|
|
13
13
|
attr_reader :data_dir
|
|
14
|
+
attr_reader :tmp_dir
|
|
14
15
|
|
|
15
|
-
def initialize(id, dir)
|
|
16
|
+
def initialize(id, dir, tmp)
|
|
16
17
|
@vm_id = id
|
|
17
18
|
@data_dir = dir
|
|
19
|
+
@tmp_dir = tmp.join("vagrant-qemu")
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def get_current_state
|
|
@@ -32,6 +34,8 @@ module VagrantPlugins
|
|
|
32
34
|
if created?
|
|
33
35
|
id_dir = @data_dir.join(@vm_id)
|
|
34
36
|
FileUtils.rm_rf(id_dir)
|
|
37
|
+
id_tmp_dir = @tmp_dir.join(@vm_id)
|
|
38
|
+
FileUtils.rm_rf(id_tmp_dir)
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
|
|
@@ -39,9 +43,12 @@ module VagrantPlugins
|
|
|
39
43
|
if !running?
|
|
40
44
|
id_dir = @data_dir.join(@vm_id)
|
|
41
45
|
image_path = id_dir.join("linked-box.img").to_s
|
|
42
|
-
unix_socket_path = id_dir.join("qemu_socket").to_s
|
|
43
46
|
pid_file = id_dir.join("qemu.pid").to_s
|
|
44
47
|
|
|
48
|
+
id_tmp_dir = @tmp_dir.join(@vm_id)
|
|
49
|
+
FileUtils.mkdir_p(id_tmp_dir)
|
|
50
|
+
unix_socket_path = id_tmp_dir.join("qemu_socket").to_s
|
|
51
|
+
|
|
45
52
|
cmd = []
|
|
46
53
|
cmd += %W(qemu-system-#{options[:arch]})
|
|
47
54
|
|
|
@@ -51,7 +58,13 @@ module VagrantPlugins
|
|
|
51
58
|
cmd += %W(-smp #{options[:smp]})
|
|
52
59
|
cmd += %W(-m #{options[:memory]})
|
|
53
60
|
cmd += %W(-device #{options[:net_device]},netdev=net0)
|
|
54
|
-
|
|
61
|
+
|
|
62
|
+
# ports
|
|
63
|
+
hostfwd = "hostfwd=tcp::#{options[:ssh_port]}-:22"
|
|
64
|
+
options[:ports].each do |v|
|
|
65
|
+
hostfwd += ",hostfwd=#{v}"
|
|
66
|
+
end
|
|
67
|
+
cmd += %W(-netdev user,id=net0,#{hostfwd})
|
|
55
68
|
|
|
56
69
|
# drive
|
|
57
70
|
cmd += %W(-drive if=virtio,format=qcow2,file=#{image_path})
|
|
@@ -75,8 +88,8 @@ module VagrantPlugins
|
|
|
75
88
|
|
|
76
89
|
def stop
|
|
77
90
|
if running?
|
|
78
|
-
|
|
79
|
-
unix_socket_path =
|
|
91
|
+
id_tmp_dir = @tmp_dir.join(@vm_id)
|
|
92
|
+
unix_socket_path = id_tmp_dir.join("qemu_socket").to_s
|
|
80
93
|
sent = false
|
|
81
94
|
execute("nc", "-w", "5", "-U", unix_socket_path) do |type, data|
|
|
82
95
|
case type
|
|
@@ -96,6 +109,8 @@ module VagrantPlugins
|
|
|
96
109
|
# Make dir
|
|
97
110
|
id_dir = @data_dir.join(new_id)
|
|
98
111
|
FileUtils.mkdir_p(id_dir)
|
|
112
|
+
id_tmp_dir = @tmp_dir.join(new_id)
|
|
113
|
+
FileUtils.mkdir_p(id_tmp_dir)
|
|
99
114
|
|
|
100
115
|
# Prepare firmware
|
|
101
116
|
execute("cp", options[:qemu_dir].join("edk2-aarch64-code.fd").to_s, id_dir.join("edk2-aarch64-code.fd").to_s)
|
data/lib/vagrant-qemu/version.rb
CHANGED
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.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ppggff
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Enables Vagrant to manage machines with QEMU.
|
|
14
14
|
email: pgf00a@gmail.com
|
|
@@ -29,6 +29,7 @@ files:
|
|
|
29
29
|
- lib/vagrant-qemu/action/message_already_created.rb
|
|
30
30
|
- lib/vagrant-qemu/action/message_not_created.rb
|
|
31
31
|
- lib/vagrant-qemu/action/message_will_not_destroy.rb
|
|
32
|
+
- lib/vagrant-qemu/action/prepare_forwarded_port_collision_params.rb
|
|
32
33
|
- lib/vagrant-qemu/action/read_state.rb
|
|
33
34
|
- lib/vagrant-qemu/action/start_instance.rb
|
|
34
35
|
- lib/vagrant-qemu/action/stop_instance.rb
|