From 484b7290faea4f939953bb96233a64f0d3555bca Mon Sep 17 00:00:00 2001 From: Kenneth Vestergaard Date: Fri, 14 Jan 2011 15:12:43 +0100 Subject: [PATCH] add system provider for FreeBSD --- lib/vagrant/systems/freebsd.rb | 83 ++++++++++++++++++++++++++++++++++ templates/locales/en.yml | 3 ++ 2 files changed, 86 insertions(+) create mode 100644 lib/vagrant/systems/freebsd.rb diff --git a/lib/vagrant/systems/freebsd.rb b/lib/vagrant/systems/freebsd.rb new file mode 100644 index 000000000..4f7460157 --- /dev/null +++ b/lib/vagrant/systems/freebsd.rb @@ -0,0 +1,83 @@ +module Vagrant + module Systems + # A general Vagrant system implementation for "freebsd". + # + # Contributed by Kenneth Vestergaard + class FreeBSD < Base + # A custom config class which will be made accessible via `config.freebsd` + # This is not necessary for all system implementers, of course. However, + # generally, Vagrant tries to make almost every aspect of its execution + # configurable, and this assists that goal. + class FreeBSDConfig < Vagrant::Config::Base + configures :freebsd + + attr_accessor :halt_timeout + attr_accessor :halt_check_interval + + def initialize + @halt_timeout = 30 + @halt_check_interval = 1 + end + end + + # Here for whenever it may be used. + class FreeBSDError < Errors::VagrantError + error_namespace("vagrant.systems.freebsd") + end + + def halt + vm.env.ui.info I18n.t("vagrant.systems.freebsd.attempting_halt") + vm.ssh.execute do |ssh| + ssh.exec!("sudo shutdown -p now") + end + + # Wait until the VM's state is actually powered off. If this doesn't + # occur within a reasonable amount of time (15 seconds by default), + # then simply return and allow Vagrant to kill the machine. + count = 0 + while vm.vm.state != :powered_off + count += 1 + + return if count >= vm.env.config.freebsd.halt_timeout + sleep vm.env.config.freebsd.halt_check_interval + end + end + + # def mount_shared_folder(ssh, name, guestpath) + # ssh.exec!("sudo mkdir -p #{guestpath}") + # # Using a custom mount method here; could use improvement. + # ssh.exec!("sudo mount -t vboxfs v-root #{guestpath}") + # ssh.exec!("sudo chown #{vm.env.config.ssh.username} #{guestpath}") + # end + + def mount_nfs(ip, folders) + folders.each do |name, opts| + vm.ssh.execute do |ssh| + ssh.exec!("sudo mkdir -p #{opts[:guestpath]}") + ssh.exec!("sudo mount #{ip}:#{opts[:hostpath]} #{opts[:guestpath]}") + end + end + end + + def prepare_host_only_network(net_options=nil) + # Remove any previous host only network additions to the + # interface file. + vm.ssh.execute do |ssh| + # Clear out any previous entries + ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf > /tmp/rc.conf") + ssh.exec!("sudo mv /tmp/rc.conf /etc/rc.conf") + end + end + + def enable_host_only_network(net_options) + entry = "#VAGRANT-BEGIN\nifconfig_em#{net_options[:adapter]}=\"inet #{net_options[:ip]} netmask #{net_options[:netmask]}\"\n#VAGRANT-END\n" + vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + + vm.ssh.execute do |ssh| + ssh.exec!("sudo su -m root -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'") + ssh.exec!("sudo ifconfig em#{net_options[:adapter]} inet #{net_options[:ip]} netmask #{net_options[:netmask]}") + end + end + end + end +end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 059014ce9..dd2f2d0e1 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -512,3 +512,6 @@ en: solaris: attempting_halt: "Attempting graceful shutdown of solaris..." + + freebsd: + attempting_halt: "Attempting graceful shutdown of FreeBSD..."