Class: Pec::Configure::UserData
- Inherits:
-
Object
- Object
- Pec::Configure::UserData
- Defined in:
- lib/pec/configure/user_data.rb
Class Method Summary collapse
- .get_template(config) ⇒ Object
- .make(config, ports) ⇒ Object
- .make_port_content(config, ports) ⇒ Object
Class Method Details
.get_template(config) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/pec/configure/user_data.rb', line 14 def get_template(config) config.templates.inject({}) do |merge_template, template| raise(Pec::Errors::UserData, "template:#{template} is not fond!") unless FileTest.exist?("user_datas/#{template}") merge_template.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.merge!(config.user_data) if config.user_data user_data.merge!(get_template(config)) if get_template(config) Base64.encode64("#cloud-config\n" + user_data.to_yaml) end |
.make_port_content(config, ports) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pec/configure/user_data.rb', line 21 def make_port_content(config, ports) config.networks.map do |ether| port_content = {} %w(name device).each do |k| port_content[k] = ether.name unless ether..key?(k) end port_content["bootproto"] = ether.bootproto port_content["type"] = ether.['type'] ||'Ethernet' port_content["onboot"] = ether.['onboot'] || 'yes' path = ether.['path'] || "/etc/sysconfig/network-scripts/ifcfg-#{ether.name}" port = ports.find {|p| p.name == ether.name} port_content["hwaddr"] = port.mac_address if ether.bootproto == "static" port_content["netmask"] = port.netmask port_content["ipaddr"] = port.ip_address end port_content.merge!(ether.) { 'content' => port_content.map {|k,v| "#{k.upcase}=#{v}"}.join("\n"), 'owner' => "root:root", 'path' => path, 'permissions' => "0644" } end end |