Class: Vagrant::Guest::FreeBSD

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant/guest/freebsd.rb

Overview

A general Vagrant system implementation for "freebsd".

Contributed by Kenneth Vestergaard [email protected]

Defined Under Namespace

Classes: FreeBSDConfig, FreeBSDError

Instance Attribute Summary

Attributes inherited from Base

#vm

Instance Method Summary collapse

Methods inherited from Base

#distro_dispatch, #initialize, #mount_shared_folder

Constructor Details

This class inherits a constructor from Vagrant::Guest::Base

Instance Method Details

#change_host_name(name) ⇒ Object



78
79
80
81
82
83
# File 'lib/vagrant/guest/freebsd.rb', line 78

def change_host_name(name)
  if !vm.channel.test("hostname -f | grep '^#{name}$' || hostname -s | grep '^#{name}$'")
    vm.channel.sudo("sed -i '' 's/^hostname=.*$/hostname=#{name}/' /etc/rc.conf")
    vm.channel.sudo("hostname #{name}")
  end
end

#configure_networks(networks) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vagrant/guest/freebsd.rb', line 61

def configure_networks(networks)
  # Remove any previous network additions to the configuration file.
  vm.channel.sudo("sed -i '' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf")

  networks.each do |network|
    entry = TemplateRenderer.render("guests/freebsd/network_#{network[:type]}",
                                    :options => network)
    vm.channel.upload(StringIO.new(entry), "/tmp/vagrant-network-entry")
    vm.channel.sudo("su -m root -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'")
    if network[:type].to_sym == :static
      vm.channel.sudo("ifconfig em#{network[:interface]} inet #{network[:ip]} netmask #{network[:netmask]}")
    elsif network[:type].to_sym == :dhcp
      vm.channel.sudo("dhclient em#{network[:interface]}")
    end
  end
end

#haltObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant/guest/freebsd.rb', line 28

def halt
  vm.channel.sudo("shutdown -p now")

  # 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.state != :poweroff
    count += 1

    return if count >= vm.config.freebsd.halt_timeout
    sleep vm.config.freebsd.halt_check_interval
  end
end

#mount_nfs(ip, folders) ⇒ Object

TODO: vboxsf is currently unsupported in FreeBSD, if you are able to help out with this project, please contact [email protected]

See: http://wiki.freebsd.org/VirtualBox/ToDo 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 #Vagrant::Guest::FreeBSD.vmvm.configvm.config.sshvm.config.ssh.username #guestpath") end



54
55
56
57
58
59
# File 'lib/vagrant/guest/freebsd.rb', line 54

def mount_nfs(ip, folders)
  folders.each do |name, opts|
    vm.channel.sudo("mkdir -p #{opts[:guestpath]}")
    vm.channel.sudo("mount #{ip}:#{opts[:hostpath]} #{opts[:guestpath]}")
  end
end