<commit_before>module RightScale
  class UbuntuNetworkConfigurator < CentosNetworkConfigurator
    def self.supported?
      ::RightScale::Platform.ubuntu?
    end

    def separate_configs_enabled?
      !File.readlines("/etc/network/interfaces").grep(/source \/etc\/network\/interface.d/).empty?
    end

    def enable_separate_configs
      File.open("/etc/network/interfaces", "w") do |config|
        config.write <<-EOH
auto lo
iface lo inet loopback

source /etc/network/interfaces.d/*.cfg
        EOH
      end
    end

    def config_file(device)
      enable_separate_configs unless separate_configs_enabled?
      FileUtils.mkdir_p("/etc/network/interfaces.d/")
      "/etc/network/interfaces.d/#{device}.cfg"
    end

    def config_data(device, ip, netmask, gateway, nameservers)
      config_data = <<-EOH
      auto #{device}
iface #{device} inet static
address #{ip}
netmask #{netmask}
gateway #{gateway}
dns-nameservers #{nameservers.join(" ")}
      EOH
    end
  end
end<commit_msg>acu141082 NAT routing support for Ubuntu 12.04<commit_after>module RightScale
  class UbuntuNetworkConfigurator < CentosNetworkConfigurator
    def self.supported?
      ::RightScale::Platform.ubuntu?
    end

    def separate_configs_enabled?
      !File.readlines("/etc/network/interfaces").grep(/source \/etc\/network\/interface.d/).empty?
    end

    def enable_separate_configs
      File.open("/etc/network/interfaces", "w") do |config|
        config.write <<-EOH
# File managed by RightScale
# DO NOT EDIT
auto lo
iface lo inet loopback

source /etc/network/interfaces.d/*.cfg
        EOH
      end
    end

    def config_file(device)
      enable_separate_configs unless separate_configs_enabled?
      FileUtils.mkdir_p("/etc/network/interfaces.d/")
      "/etc/network/interfaces.d/#{device}.cfg"
    end

    def config_data(device, ip, netmask, gateway, nameservers)
      config_data = <<-EOH
# File managed by RightScale
# DO NOT EDIT
auto #{device}
iface #{device} inet static
address #{ip}
netmask #{netmask}
gateway #{gateway}
dns-nameservers #{nameservers.join(" ")}
      EOH
    end

    def ip_route_cmd(network, nat_server_ip)
      "up ip route add #{network} via #{nat_server_ip}"
    end

    def init_device_config_file(file_path, device)
      File.open(file_path, "w") do |config|
        config.write <<-EOH
# File managed by RightScale
# DO NOT EDIT
auto #{device}
iface #{device} inet dhcp
        EOH
      end
    end

    def routes_file(device)
      routes_file = config_file(device)
      init_device_config_file(routes_file, device) unless File.exists?(routes_file)
      routes_file
    end
  end
end
{'fraction_non_alphanumeric': 0.10854765506807867, 'fraction_numerical': 0.0037821482602118004, 'mean_word_length': 3.211783439490446, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5043687', 'n_tokens_mistral': 890, 'n_tokens_neox': 858, 'n_words': 199}