Class: Pec::Configure::UserData

Inherits:
Object
  • Object
show all
Defined in:
lib/pec/configure/user_data.rb

Class Method Summary collapse

Class Method Details

.make(config, ports) ⇒ Object



6
7
8
9
10
# File 'lib/pec/configure/user_data.rb', line 6

def make(config, ports)
  user_data = {}
  user_data["write_files"] = make_port_content(config, ports) if ports
  Base64.encode64("#cloud-config\n" + user_data.merge(config.user_data).to_yaml)
end

.make_port_content(config, ports) ⇒ 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
# File 'lib/pec/configure/user_data.rb', line 12

def make_port_content(config, ports)
  config.networks.map do |ether|
    port_content = {}
    port_content["name"] = ether.name unless ether.options.key?('name')
    port_content["device"] = ether.name unless ether.options.key?('device')
    port_content["type"] = 'Ethernet' unless ether.options.key?('type')
    port_content["onboot"] = "yes" unless ether.options.key?('onboot')

    _path = "/etc/sysconfig/network-scripts/ifcfg-#{ether.name}" unless ether.options.key?('path')

    port = ports.find {|p| p.name == ether.name}

    if port
      port_content["netmask"] = port.netmask
      port_content["hwaddr"] = port.mac_address
      port_content["ipaddr"] = port.ip_address
    end
    port_content.merge!(ether.options)
    {
      'content' => port_content.map {|k,v| "#{k.upcase}=#{v}"}.join("\n"),
      'owner' => "root:root",
      'path' => _path,
      'permissions' => "0644"
    }
  end
end