Class: Vagrant::Guest::Fedora

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

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



56
57
58
59
60
61
62
63
# File 'lib/vagrant/guest/fedora.rb', line 56

def change_host_name(name)
  # Only do this if the hostname is not already set
  if !vm.channel.test("sudo hostname | grep '#{name}'")
    vm.channel.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
    vm.channel.sudo("hostname #{name}")
    vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
  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
# File 'lib/vagrant/guest/fedora.rb', line 12

def configure_networks(networks)
  # 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
  networks.each do |network|
    interfaces.add(network[:interface])

    # Remove any previous vagrant configuration in this network
    # interface's configuration files.
    vm.channel.sudo("touch #{network_scripts_dir}/ifcfg-p7p#{network[:interface]}")
    vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-p7p#{network[:interface]} > /tmp/vagrant-ifcfg-p7p#{network[:interface]}")
    vm.channel.sudo("cat /tmp/vagrant-ifcfg-p7p#{network[:interface]} > #{network_scripts_dir}/ifcfg-p7p#{network[:interface]}")

    # Render and upload the network entry file to a deterministic
    # temporary location.
    entry = TemplateRenderer.render("guests/fedora/network_#{network[:type]}",
                                    :options => network)

    temp = Tempfile.new("vagrant")
    temp.binmode
    temp.write(entry)
    temp.close

    vm.channel.upload(temp.path, "/tmp/vagrant-network-entry_#{network[:interface]}")
  end

  # Bring down all the interfaces we're reconfiguring. By bringing down
  # each specifically, we avoid reconfiguring p7p (the NAT interface) so
  # SSH never dies.
  interfaces.each do |interface|
    vm.channel.sudo("/sbin/ifdown p7p#{interface} 2> /dev/null", :error_check => false)
    vm.channel.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-p7p#{interface}")
    vm.channel.sudo("/sbin/ifup p7p#{interface} 2> /dev/null")
  end
end

#network_scripts_dirObject

The path to the directory with the network configuration scripts. This is pulled out into its own directory since there are other operating systems (SuSE) which behave similarly but with a different path to the network scripts.



52
53
54
# File 'lib/vagrant/guest/fedora.rb', line 52

def network_scripts_dir
  '/etc/sysconfig/network-scripts'
end