Class: Vagrant::Guest::Debian

Inherits:
Linux show all
Includes:
Util
Defined in:
lib/vagrant/guest/debian.rb

Direct Known Subclasses

Ubuntu

Instance Attribute Summary

Attributes inherited from Base

#vm

Instance Method Summary collapse

Methods inherited from Linux

#distro_dispatch, #halt, #initialize, #mount_nfs, #mount_shared_folder

Methods inherited from Base

#distro_dispatch, #halt, #initialize, #mount_nfs, #mount_shared_folder

Constructor Details

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

Instance Method Details

#change_host_name(name) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/vagrant/guest/debian.rb', line 55

def change_host_name(name)
  if !vm.channel.test("hostname --fqdn | grep '^#{name}$' || hostname --short | grep '^#{name}$'")
    vm.channel.sudo("sed -r -i 's/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1#{name} #{name.split('.')[0]}/' /etc/hosts")
    vm.channel.sudo("sed -i 's/.*$/#{name.split('.')[0]}/' /etc/hostname")
    vm.channel.sudo("hostname -F /etc/hostname")
  end
end

#configure_networks(networks) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vagrant/guest/debian.rb', line 12

def configure_networks(networks)
  # First, remove any previous network modifications
  # from the interface file.
  vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
  vm.channel.sudo("su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")

  # Accumulate the configurations to add to the interfaces file as
  # well as what interfaces we're actually configuring since we use that
  # later.
  interfaces = Set.new
  entries = []
  networks.each do |network|
    interfaces.add(network[:interface])
    entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
                                    :options => network)

    entries << entry
  end

  # Perform the careful dance necessary to reconfigure
  # the network interfaces
  temp = Tempfile.new("vagrant")
  temp.binmode
  temp.write(entries.join("\n"))
  temp.close

  vm.channel.upload(temp.path, "/tmp/vagrant-network-entry")

  # Bring down all the interfaces we're reconfiguring. By bringing down
  # each specifically, we avoid reconfiguring eth0 (the NAT interface) so
  # SSH never dies.
  interfaces.each do |interface|
    vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null")
  end

  vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/network/interfaces")

  # Bring back up each network interface, reconfigured
  interfaces.each do |interface|
    vm.channel.sudo("/sbin/ifup eth#{interface}")
  end
end