Skip to content

Commit

Permalink
Socket networking with MAC addresses (#1)
Browse files Browse the repository at this point in the history
* Add support for socket networking with fd

* Add MAC address option

* Update gemspec for fork
  • Loading branch information
skara9 authored Jun 17, 2024
1 parent 486b64e commit f91d827
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
gem "vagrant", :git => "https://github.com/hashicorp/vagrant.git"

gem "rake"
gem "rspec", "~> 3.4"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ This provider exposes a few provider-specific configuration options:
* debug/expert
* `ssh_host` - The SSH IP used to access VM, default: `127.0.0.1`
* `net_device` - The network device, default: `virtio-net-device`
* `mac_address` - The MAC address, default is nil value. (nil means automatically set)
* `socket_fd` - The file descriptor for socket networking, default is nil value. (nil means no socket)
* `drive_interface` - The interface type for the main drive, default `virtio`
* `image_path` - The path (or array of paths) to qcow2 image for box-less VM, default is nil value
* `qemu_dir` - The path to QEMU's install dir, default: `/opt/homebrew/share/qemu`
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-qemu/action/start_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def call(env)
:smp => env[:machine].provider_config.smp,
:memory => env[:machine].provider_config.memory,
:net_device => env[:machine].provider_config.net_device,
:mac_address => env[:machine].provider_config.mac_address,
:socket_fd => env[:machine].provider_config.socket_fd,
:drive_interface => env[:machine].provider_config.drive_interface,
:extra_qemu_args => env[:machine].provider_config.extra_qemu_args,
:extra_netdev_args => env[:machine].provider_config.extra_netdev_args,
Expand Down
6 changes: 6 additions & 0 deletions lib/vagrant-qemu/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Config < Vagrant.plugin("2", :config)
attr_accessor :smp
attr_accessor :memory
attr_accessor :net_device
attr_accessor :mac_address
attr_accessor :socket_fd
attr_accessor :drive_interface
attr_accessor :image_path
attr_accessor :qemu_dir
Expand All @@ -31,6 +33,8 @@ def initialize
@smp = UNSET_VALUE
@memory = UNSET_VALUE
@net_device = UNSET_VALUE
@mac_address = UNSET_VALUE
@socket_fd = UNSET_VALUE
@drive_interface = UNSET_VALUE
@image_path = UNSET_VALUE
@qemu_dir = UNSET_VALUE
Expand Down Expand Up @@ -61,6 +65,8 @@ def finalize!
@smp = "2" if @smp == UNSET_VALUE
@memory = "4G" if @memory == UNSET_VALUE
@net_device = "virtio-net-device" if @net_device == UNSET_VALUE
@mac_address = nil if @mac_address == UNSET_VALUE
@socket_fd = nil if @socket_fd == UNSET_VALUE
@drive_interface = "virtio" if @drive_interface == UNSET_VALUE
@image_path = nil if @image_path == UNSET_VALUE
@qemu_dir = "/opt/homebrew/share/qemu" if @qemu_dir == UNSET_VALUE
Expand Down
20 changes: 15 additions & 5 deletions lib/vagrant-qemu/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,28 @@ def start(options)
# network
if !options[:net_device].nil?
# net device
cmd += %W(-device #{options[:net_device]},netdev=net0)
macaddr = options[:mac_address].nil? ? "" : ",mac=" + options[:mac_address]
cmd += %W(-device #{options[:net_device]},netdev=net0#{macaddr})

# net type
net_type = "user"
if !options[:socket_fd].nil?
net_type = "socket,fd=#{options[:socket_fd]}"
end

# ports
hostfwd = "hostfwd=tcp::#{options[:ssh_port]}-:22"
options[:ports].each do |v|
hostfwd += ",hostfwd=#{v}"
hostfwd = ""
if options[:socket_fd].nil?
hostfwd = ",hostfwd=tcp::#{options[:ssh_port]}-:22"
options[:ports].each do |v|
hostfwd += ",hostfwd=#{v}"
end
end
extra_netdev = ""
if !options[:extra_netdev_args].nil?
extra_netdev = ",#{options[:extra_netdev_args]}"
end
cmd += %W(-netdev user,id=net0,#{hostfwd}#{extra_netdev})
cmd += %W(-netdev #{net_type},id=net0#{hostfwd}#{extra_netdev})
end

# drive
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-qemu/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module QEMU
VERSION = '0.3.6'
VERSION = '24.06.00'
end
end
6 changes: 2 additions & 4 deletions vagrant-qemu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ Gem::Specification.new do |s|
s.version = VagrantPlugins::QEMU::VERSION
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.authors = "ppggff"
s.email = "[email protected]"
s.homepage = "https://github.com/ppggff/vagrant-qemu"
s.authors = "Submitty"
s.homepage = "https://github.com/Submitty/vagrant-qemu"
s.summary = "Enables Vagrant to manage machines with QEMU."
s.description = "Enables Vagrant to manage machines with QEMU."

s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "vagrant-qemu"

# The following block of code determines the files that should be included
# in the gem. It does this by reading all the files in the directory where
Expand Down

0 comments on commit f91d827

Please sign in to comment.