2012-02-24 00:58:22 +00:00
|
|
|
require 'vagrant/util/template_renderer'
|
|
|
|
|
2012-04-19 04:03:03 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestFreeBSD
|
2011-01-14 14:12:43 +00:00
|
|
|
# A general Vagrant system implementation for "freebsd".
|
|
|
|
#
|
|
|
|
# Contributed by Kenneth Vestergaard <kvs@binarysolutions.dk>
|
2012-11-07 05:14:45 +00:00
|
|
|
class Guest < Vagrant.plugin("2", :guest)
|
2011-01-14 14:12:43 +00:00
|
|
|
# Here for whenever it may be used.
|
2012-04-19 04:03:03 +00:00
|
|
|
class FreeBSDError < Vagrant::Errors::VagrantError
|
2011-12-16 05:07:43 +00:00
|
|
|
error_namespace("vagrant.guest.freebsd")
|
2011-01-14 14:12:43 +00:00
|
|
|
end
|
|
|
|
|
2013-04-04 04:47:57 +00:00
|
|
|
def detect?(machine)
|
|
|
|
# TODO: FreeBSD detection
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2011-01-14 14:12:43 +00:00
|
|
|
def halt
|
2013-03-28 22:52:00 +00:00
|
|
|
begin
|
|
|
|
vm.communicate.sudo("shutdown -p now")
|
|
|
|
rescue IOError
|
|
|
|
# Do nothing because SSH connection closed and it probably
|
|
|
|
# means the VM just shut down really fast.
|
|
|
|
end
|
2011-01-14 14:12:43 +00:00
|
|
|
end
|
|
|
|
|
2012-01-27 21:12:21 +00:00
|
|
|
# TODO: vboxsf is currently unsupported in FreeBSD, if you are able to
|
|
|
|
# help out with this project, please contact vbox@FreeBSD.org
|
|
|
|
#
|
|
|
|
# See: http://wiki.freebsd.org/VirtualBox/ToDo
|
2011-01-14 14:12:43 +00:00
|
|
|
# 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}")
|
2011-12-10 21:44:45 +00:00
|
|
|
# ssh.exec!("sudo chown #{vm.config.ssh.username} #{guestpath}")
|
2011-01-14 14:12:43 +00:00
|
|
|
# end
|
|
|
|
|
|
|
|
def mount_nfs(ip, folders)
|
|
|
|
folders.each do |name, opts|
|
2013-01-30 18:54:53 +00:00
|
|
|
vm.communicate.sudo("mkdir -p #{opts[:guestpath]}")
|
2013-01-31 06:19:13 +00:00
|
|
|
vm.communicate.sudo("mount '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'")
|
2011-01-14 14:12:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-27 20:19:15 +00:00
|
|
|
def configure_networks(networks)
|
2012-02-24 00:58:22 +00:00
|
|
|
# Remove any previous network additions to the configuration file.
|
2013-01-30 18:54:53 +00:00
|
|
|
vm.communicate.sudo("sed -i '' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf")
|
2011-01-14 14:12:43 +00:00
|
|
|
|
2012-01-27 20:19:15 +00:00
|
|
|
networks.each do |network|
|
2012-02-24 00:58:22 +00:00
|
|
|
entry = TemplateRenderer.render("guests/freebsd/network_#{network[:type]}",
|
|
|
|
:options => network)
|
2012-06-23 03:56:41 +00:00
|
|
|
|
|
|
|
# Write the entry to a temporary location
|
|
|
|
temp = Tempfile.new("vagrant")
|
|
|
|
temp.binmode
|
|
|
|
temp.write(entry)
|
|
|
|
temp.close
|
|
|
|
|
2013-01-30 18:54:53 +00:00
|
|
|
vm.communicate.upload(temp.path, "/tmp/vagrant-network-entry")
|
|
|
|
vm.communicate.sudo("su -m root -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'")
|
|
|
|
vm.communicate.sudo("rm /tmp/vagrant-network-entry")
|
2012-04-02 07:33:54 +00:00
|
|
|
|
2012-02-24 00:58:22 +00:00
|
|
|
if network[:type].to_sym == :static
|
2013-01-30 18:54:53 +00:00
|
|
|
vm.communicate.sudo("ifconfig em#{network[:interface]} inet #{network[:ip]} netmask #{network[:netmask]}")
|
2012-02-24 00:58:22 +00:00
|
|
|
elsif network[:type].to_sym == :dhcp
|
2013-01-30 18:54:53 +00:00
|
|
|
vm.communicate.sudo("dhclient em#{network[:interface]}")
|
2012-02-24 00:58:22 +00:00
|
|
|
end
|
2011-01-14 14:12:43 +00:00
|
|
|
end
|
|
|
|
end
|
2012-02-22 23:08:18 +00:00
|
|
|
|
|
|
|
def change_host_name(name)
|
2013-01-30 18:54:53 +00:00
|
|
|
if !vm.communicate.test("hostname -f | grep '^#{name}$' || hostname -s | grep '^#{name}$'")
|
|
|
|
vm.communicate.sudo("sed -i '' 's/^hostname=.*$/hostname=#{name}/' /etc/rc.conf")
|
|
|
|
vm.communicate.sudo("hostname #{name}")
|
2012-02-22 23:08:18 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-14 14:12:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|