Merge pull request #2819 from stoned/guest-netbsd
Add NetBSD guest support
This commit is contained in:
commit
53347abbca
|
@ -0,0 +1,18 @@
|
|||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
if !machine.communicate.test("hostname -s | grep '^#{name}$'")
|
||||
machine.communicate.sudo(<<CMDS, {:shell => "sh"})
|
||||
set -e
|
||||
sed -e 's/^hostname=.*$/hostname=#{name}/' /etc/rc.conf > /tmp/rc.conf.vagrant_changehostname_#{name}
|
||||
mv /tmp/rc.conf.vagrant_changehostname_#{name} /etc/rc.conf
|
||||
hostname #{name}
|
||||
CMDS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,53 @@
|
|||
require "tempfile"
|
||||
|
||||
require "vagrant/util/template_renderer"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
module Cap
|
||||
class ConfigureNetworks
|
||||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
|
||||
# setup a new rc.conf file
|
||||
newrcconf = "/tmp/rc.conf.vagrant_configurenetworks"
|
||||
machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf > #{newrcconf}")
|
||||
|
||||
networks.each do |network|
|
||||
|
||||
# create an interface configuration file fragment
|
||||
entry = TemplateRenderer.render("guests/netbsd/network_#{network[:type]}",
|
||||
:options => network)
|
||||
|
||||
temp = Tempfile.new("vagrant")
|
||||
temp.binmode
|
||||
temp.write(entry)
|
||||
temp.close
|
||||
|
||||
# upload it and append it to the new rc.conf file
|
||||
machine.communicate.upload(temp.path, "/tmp/vagrant-network-entry")
|
||||
machine.communicate.sudo("cat /tmp/vagrant-network-entry >> #{newrcconf}")
|
||||
machine.communicate.sudo("rm /tmp/vagrant-network-entry")
|
||||
|
||||
ifname = "wm#{network[:interface]}"
|
||||
# remove old configuration
|
||||
machine.communicate.sudo("/sbin/dhcpcd -x #{ifname}", { :error_check => false })
|
||||
machine.communicate.sudo("/sbin/ifconfig #{ifname} inet delete", { :error_check => false })
|
||||
|
||||
# live new configuration
|
||||
if network[:type].to_sym == :static
|
||||
machine.communicate.sudo("/sbin/ifconfig #{ifname} media autoselect up;/sbin/ifconfig #{ifname} inet #{network[:ip]} netmask #{network[:netmask]}")
|
||||
elsif network[:type].to_sym == :dhcp
|
||||
machine.communicate.sudo("/sbin/dhcpcd -n -q #{ifname}")
|
||||
end
|
||||
end
|
||||
|
||||
# install new rc.conf
|
||||
machine.communicate.sudo("install -c -o 0 -g 0 -m 644 #{newrcconf} /etc/rc.conf")
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
module Cap
|
||||
class Halt
|
||||
def self.halt(machine)
|
||||
begin
|
||||
machine.communicate.sudo("/sbin/shutdown -p -h now")
|
||||
rescue IOError
|
||||
# Do nothing, because it probably means the machine shut down
|
||||
# and SSH connection was lost.
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
module Cap
|
||||
class MountNFSFolder
|
||||
def self.mount_nfs_folder(machine, ip, folders)
|
||||
folders.each do |name, opts|
|
||||
machine.communicate.sudo(<<CMDS, {:shell => "sh"})
|
||||
set -e
|
||||
mkdir -p #{opts[:guestpath]}
|
||||
/sbin/mount -t nfs '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'
|
||||
CMDS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
def detect?(machine)
|
||||
machine.communicate.test("uname -s | grep NetBSD")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
class Plugin < Vagrant.plugin("2")
|
||||
name "NetBSD guest"
|
||||
description "NetBSD guest support."
|
||||
|
||||
guest("netbsd") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
Guest
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "change_host_name") do
|
||||
require_relative "cap/change_host_name"
|
||||
Cap::ChangeHostName
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "configure_networks") do
|
||||
require_relative "cap/configure_networks"
|
||||
Cap::ConfigureNetworks
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "halt") do
|
||||
require_relative "cap/halt"
|
||||
Cap::Halt
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "mount_nfs_folder") do
|
||||
require_relative "cap/mount_nfs_folder"
|
||||
Cap::MountNFSFolder
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
#VAGRANT-BEGIN
|
||||
ifconfig_wm<%= options[:interface] %>=dhcp
|
||||
#VAGRANT-END
|
|
@ -0,0 +1,3 @@
|
|||
#VAGRANT-BEGIN
|
||||
ifconfig_wm<%= options[:interface] %>="media autoselect up;inet <%= options[:ip] %> netmask <%= options[:netmask] %>"
|
||||
#VAGRANT-END
|
Loading…
Reference in New Issue