Class: DHCPD
- Inherits:
-
Object
- Object
- DHCPD
- Defined in:
- lib/dhcpd.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(conf_path) ⇒ DHCPD
constructor
A new instance of DHCPD.
- #save ⇒ Object
- #serialize ⇒ Object
- #subnet ⇒ Object
Constructor Details
#initialize(conf_path) ⇒ DHCPD
Returns a new instance of DHCPD.
4 5 6 7 8 9 10 11 |
# File 'lib/dhcpd.rb', line 4 def initialize(conf_path) @conf_path = conf_path @preamble = '' @postamble = '' @config = {} parse end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
2 3 4 |
# File 'lib/dhcpd.rb', line 2 def config @config end |
Instance Method Details
#save ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/dhcpd.rb', line 35 def save tmp_path = '.tmp.dhcpd.conf' File.open(tmp_path, 'w') do |f| f.write serialize end system 'sudo', 'mv', tmp_path, @conf_path end |
#serialize ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dhcpd.rb', line 17 def serialize out = @preamble out += BEGIN_PAUPER + "\n" @config.each do |host, host_config| out += "host #{host} {\n" host_config.each do |key, value| out += "\t#{key} #{value};\n" end out += "}\n" end out += END_PAUPER + "\n" out += @postamble out end |
#subnet ⇒ Object
13 14 15 |
# File 'lib/dhcpd.rb', line 13 def subnet @preamble.match(/subnet (\d+\.\d+\.\d+)\.0 netmask/)[1] end |