Class: Vagrant::Guest::Linux

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant/guest/linux.rb,
lib/vagrant/guest/linux/error.rb,
lib/vagrant/guest/linux/config.rb

Direct Known Subclasses

Arch, Debian, Fedora, Gentoo, Redhat

Defined Under Namespace

Classes: LinuxConfig, LinuxError

Instance Attribute Summary

Attributes inherited from Base

#vm

Instance Method Summary collapse

Methods inherited from Base

#change_host_name, #configure_networks

Constructor Details

#initialize(*args) ⇒ Linux

Returns a new instance of Linux.



9
10
11
12
13
# File 'lib/vagrant/guest/linux.rb', line 9

def initialize(*args)
  super

  @logger = Log4r::Logger.new("vagrant::guest::linux")
end

Instance Method Details

#distro_dispatchObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant/guest/linux.rb', line 15

def distro_dispatch
  if @vm.channel.test("cat /etc/debian_version")
    return :debian if @vm.channel.test("cat /proc/version | grep 'Debian'")
    return :ubuntu if @vm.channel.test("cat /proc/version | grep 'Ubuntu'")
  end

  return :gentoo if @vm.channel.test("cat /etc/gentoo-release")
  return :fedora if @vm.channel.test("grep 'Fedora release 16' /etc/redhat-release")
  return :redhat if @vm.channel.test("cat /etc/redhat-release")
  return :suse if @vm.channel.test("cat /etc/SuSE-release")
  return :arch if @vm.channel.test("cat /etc/arch-release")

  # Can't detect the distro, assume vanilla linux
  nil
end

#haltObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant/guest/linux.rb', line 31

def halt
  @vm.channel.sudo("shutdown -h 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.linux.halt_timeout
    sleep @vm.config.linux.halt_check_interval
  end
end

#mount_nfs(ip, folders) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant/guest/linux.rb', line 55

def mount_nfs(ip, folders)
  # TODO: Maybe check for nfs support on the guest, since its often
  # not installed by default
  folders.each do |name, opts|
    # Expand the guestpath, so we can handle things like "~/vagrant"
    real_guestpath = expanded_guest_path(opts[:guestpath])

    # Do the actual creating and mounting
    @vm.channel.sudo("mkdir -p #{real_guestpath}")
    @vm.channel.sudo("mount -o vers=#{opts[:nfs_version]} #{ip}:'#{opts[:hostpath]}' #{real_guestpath}",
                    :error_class => LinuxError,
                    :error_key => :mount_nfs_fail)
  end
end

#mount_shared_folder(name, guestpath, options) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/vagrant/guest/linux.rb', line 46

def mount_shared_folder(name, guestpath, options)
  real_guestpath = expanded_guest_path(guestpath)
  @logger.debug("Shell expanded guest path: #{real_guestpath}")

  @vm.channel.sudo("mkdir -p #{real_guestpath}")
  mount_folder(name, real_guestpath, options)
  @vm.channel.sudo("chown `id -u #{options[:owner]}`:`id -g #{options[:group]}` #{real_guestpath}")
end