class Pec::Handler::UserData::Nic::Ubuntu

Public Class Methods

default_path(port) click to toggle source
# File lib/pec/handler/user_data/nic/ubuntu.rb, line 40
def default_path(port)
  "/etc/network/interfaces"
end
gen_user_data(networks, ports) click to toggle source
# File lib/pec/handler/user_data/nic/ubuntu.rb, line 6
def gen_user_data(networks, ports)
  port_content = [
    "auto lo\niface lo inet loopback"
  ]

  networks.map do |network|
    port = ports.find {|p|p.name == network[NAME]}
    port_content << ifcfg_config(network, port)
  end
  [
    {
      'content' => port_content.join("\n"),
      'owner' => "root:root",
      'path' => networks.first[CONFIG]['path'] || default_path(nil),
      'permissions' => "0644"
    }
  ]
end
ifcfg_config(network, port) click to toggle source
# File lib/pec/handler/user_data/nic/ubuntu.rb, line 25
def ifcfg_config(network, port)
  base = {
    "auto"                    => port.name,
    "iface #{port.name} inet" => network[CONFIG]['bootproto'],
  }
  base.merge!(
    {
      "address"  => port.fixed_ips.first['ip_address'],
      "netmask" => IP.new(network[CONFIG]['ip_address']).netmask.to_s,
      "hwaddress ether"  => port.mac_address
    }
  ) if network[CONFIG]['bootproto'] == "static"
  safe_merge(base, network).reject {|k,v| k == "bootproto"}.map {|k,v| "#{k} #{v}"}.join("\n")
end