diff --git a/Gemfile b/Gemfile index 8329b7b..4a61b8a 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/README.md b/README.md index eb7f2b7..08fa595 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/vagrant-qemu/action/start_instance.rb b/lib/vagrant-qemu/action/start_instance.rb index 13c1d9d..157db71 100644 --- a/lib/vagrant-qemu/action/start_instance.rb +++ b/lib/vagrant-qemu/action/start_instance.rb @@ -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, diff --git a/lib/vagrant-qemu/config.rb b/lib/vagrant-qemu/config.rb index 2e5dfd0..203e5bd 100644 --- a/lib/vagrant-qemu/config.rb +++ b/lib/vagrant-qemu/config.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/vagrant-qemu/driver.rb b/lib/vagrant-qemu/driver.rb index c2da222..e9d6547 100644 --- a/lib/vagrant-qemu/driver.rb +++ b/lib/vagrant-qemu/driver.rb @@ -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 diff --git a/lib/vagrant-qemu/version.rb b/lib/vagrant-qemu/version.rb index 72f4317..ea17580 100644 --- a/lib/vagrant-qemu/version.rb +++ b/lib/vagrant-qemu/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module QEMU - VERSION = '0.3.6' + VERSION = '24.06.00' end end diff --git a/vagrant-qemu.gemspec b/vagrant-qemu.gemspec index 99cec30..7ea05c3 100644 --- a/vagrant-qemu.gemspec +++ b/vagrant-qemu.gemspec @@ -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 = "pgf00a@gmail.com" - 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