Class: Pec::Configure::UserData

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

Class Method Summary collapse

Class Method Details

.get_template(config) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/pec/configure/user_data.rb', line 14

def get_template(config)
  config.templates.inject({}) do |merge_template, template|
    template.to_s.concat('.yaml') unless template.to_s.match(/.*\.yaml/)
    raise(Pec::Errors::UserData, "template:#{template} is not fond!") unless FileTest.exist?("user_datas/#{template}")
    merge_template.deep_merge!(YAML.load_file("user_datas/#{template}").to_hash)
  end if config.templates
end

.make(config, ports) ⇒ Object



6
7
8
9
10
11
12
# 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
  user_data.deep_merge!(config.user_data) if config.user_data
  user_data.deep_merge!(get_template(config)) if get_template(config)
  Base64.encode64("#cloud-config\n" + user_data.to_yaml)
end

.make_port_content(config, ports) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pec/configure/user_data.rb', line 22

def make_port_content(config, ports)
  config.networks.map do |ether|
    path = ether.options['path'] || "/etc/sysconfig/network-scripts/ifcfg-#{ether.name}"
    {
      'content' => ether.get_port_content(ports),
      'owner' => "root:root",
      'path' => path,
      'permissions' => "0644"
    }
  end
end