Class: DHCP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/dhcp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, port) ⇒ Server

Returns a new instance of Server.



6
7
8
9
# File 'lib/dhcp.rb', line 6

def initialize(address, port)
    @address = address
    @port = port
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



4
5
6
# File 'lib/dhcp.rb', line 4

def address
  @address
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/dhcp.rb', line 4

def port
  @port
end

Instance Method Details

#add_lease(lease) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dhcp.rb', line 11

def add_lease(lease)
    File.open('/tmp/add_pxe_lease','w') do |file|
        file.puts "server #{@address}"
        file.puts "server #{@port}"
        file.puts "connect"
        file.puts "new host"
        file.puts "set name = \"#{lease.name}\""
        file.puts "set hardware-address = #{lease.mac}"
        file.puts "set hardware-type = 1"
        file.puts "set ip-address = #{lease.ip}"
        file.puts "set statements = \"#{lease.statements_string}\""
        file.puts "create"
    end

    #execute!
    `cat /tmp/add_pxe_lease | omshell`
    `rm /tmp/add_pxe_lease`
end

#del_lease(lease) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dhcp.rb', line 30

def del_lease(lease)
    File.open('/tmp/del_pxe_lease','w') do |file|
        file.puts "server #{address}"
        file.puts "server #{port}"
        file.puts "connect"
        file.puts "new host"
        file.puts "set name = \"#{lease.name}\""
        file.puts "open"
        file.puts "remove"
    end

    #execute!
    `cat /tmp/del_pxe_lease | omshell`
    `rm /tmp/del_pxe_lease`
end