Class: Bosh::Agent::Platform::Ubuntu::Network
- Inherits:
-
Linux::Network
- Object
- Linux::Network
- Bosh::Agent::Platform::Ubuntu::Network
- Includes:
- Exec
- Defined in:
- lib/bosh_agent/platform/ubuntu/network.rb
Instance Method Summary collapse
-
#initialize(template_dir) ⇒ Network
constructor
A new instance of Network.
-
#restart_dhclient ⇒ Object
Executing /sbin/dhclient starts another dhclient process, so it’ll cause a conflict with the existing system dhclient process and dns changes will be flip floping each lease time.
- #restart_networking_service ⇒ Object
- #write_dhcp_conf ⇒ Object
- #write_network_interfaces ⇒ Object
Methods inherited from Linux::Network
#dns, #setup_dhcp_from_settings, #setup_networking, #setup_networking_from_settings
Constructor Details
#initialize(template_dir) ⇒ Network
Returns a new instance of Network.
7 8 9 |
# File 'lib/bosh_agent/platform/ubuntu/network.rb', line 7 def initialize(template_dir) super end |
Instance Method Details
#restart_dhclient ⇒ Object
Executing /sbin/dhclient starts another dhclient process, so it’ll cause a conflict with the existing system dhclient process and dns changes will be flip floping each lease time. So in order to refresh dhclient configuration we need to restart networking.
If dhclient3 cannot release a lease because it collides with a network restart (message “receive_packet failed on eth0: Network is down” appears at /var/log/syslog) then the old dhclient3 process won’t be killed (see bug LP #38140), and there will be two dhclient3 process running (and dns changes will be flip floping each lease time). So before restarting the network, we first kill all dhclient3 process.
53 54 55 56 |
# File 'lib/bosh_agent/platform/ubuntu/network.rb', line 53 def restart_dhclient sh("pkill dhclient3", :on_error => :return) sh("/etc/init.d/networking restart", :on_error => :return) end |
#restart_networking_service ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bosh_agent/platform/ubuntu/network.rb', line 21 def restart_networking_service # ubuntu 10.04 networking startup/upstart stuff is quite borked networks.each do |k, v| interface = v['interface'] @logger.info("Restarting #{interface}") output = sh("service network-interface stop INTERFACE=#{interface}").output output += sh("service network-interface start INTERFACE=#{interface}").output @logger.info("Restarted networking: #{output}") end end |
#write_dhcp_conf ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/bosh_agent/platform/ubuntu/network.rb', line 32 def write_dhcp_conf template = ERB.new(load_erb("dhclient_conf.erb"), 0, '%<>-') result = template.result(binding) updated = Bosh::Agent::Util::update_file(result, '/etc/dhcp3/dhclient.conf') if updated @logger.info("Updated dhclient.conf") restart_dhclient end end |
#write_network_interfaces ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/bosh_agent/platform/ubuntu/network.rb', line 11 def write_network_interfaces template = ERB.new(load_erb("interfaces.erb"), 0, '%<>-') result = template.result(binding) network_updated = Bosh::Agent::Util::update_file(result, '/etc/network/interfaces') if network_updated @logger.info("Updated networking") restart_networking_service end end |