Class: Vagrant::Systems::FreeBSD

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant/systems/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

#change_host_name, #distro_dispatch, #initialize, #mount_shared_folder

Constructor Details

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

Instance Method Details

#enable_host_only_network(net_options) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/vagrant/systems/freebsd.rb', line 73

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

#haltObject



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

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

#mount_nfs(ip, folders) ⇒ Object

TODO: Error/warning about this. 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::Systems::FreeBSD.vmvm.envvm.env.configvm.env.config.sshvm.env.config.ssh.username #guestpath") end



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

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

#prepare_host_only_network(net_options = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/vagrant/systems/freebsd.rb', line 63

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