vagrant/plugins/guests/freebsd/guest.rb

71 lines
2.6 KiB
Ruby
Raw Normal View History

require 'vagrant/util/template_renderer'
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.
class FreeBSDError < Vagrant::Errors::VagrantError
error_namespace("vagrant.guest.freebsd")
2011-01-14 14:12:43 +00:00
end
def halt
vm.communicate.sudo("shutdown -p now")
2011-01-14 14:12:43 +00:00
end
# 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|
vm.communicate.sudo("mkdir -p #{opts[:guestpath]}")
vm.communicate.sudo("mount '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'")
2011-01-14 14:12:43 +00:00
end
end
def configure_networks(networks)
# Remove any previous network additions to the configuration file.
vm.communicate.sudo("sed -i '' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf")
2011-01-14 14:12:43 +00:00
networks.each do |network|
entry = TemplateRenderer.render("guests/freebsd/network_#{network[:type]}",
:options => network)
# Write the entry to a temporary location
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(entry)
temp.close
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")
if network[:type].to_sym == :static
vm.communicate.sudo("ifconfig em#{network[:interface]} inet #{network[:ip]} netmask #{network[:netmask]}")
elsif network[:type].to_sym == :dhcp
vm.communicate.sudo("dhclient em#{network[:interface]}")
end
2011-01-14 14:12:43 +00:00
end
end
def change_host_name(name)
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}")
end
end
2011-01-14 14:12:43 +00:00
end
end
end