Class: DHCP::Lease

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Lease

Returns a new instance of Lease.



50
51
52
53
54
55
56
57
# File 'lib/dhcp.rb', line 50

def initialize(definition)
    @name = definition[:name]
    @ip = definition[:ip]
    @mask = definition[:mask]
    @mac = definition[:mac]
    @pxe_path = definition[:pxe_path] if definition.include? :pxe_path
    @hostname = definition[:hostname] if definition.include? :hostname
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



48
49
50
# File 'lib/dhcp.rb', line 48

def hostname
  @hostname
end

#ipObject (readonly)

Returns the value of attribute ip.



48
49
50
# File 'lib/dhcp.rb', line 48

def ip
  @ip
end

#macObject (readonly)

Returns the value of attribute mac.



48
49
50
# File 'lib/dhcp.rb', line 48

def mac
  @mac
end

#maskObject (readonly)

Returns the value of attribute mask.



48
49
50
# File 'lib/dhcp.rb', line 48

def mask
  @mask
end

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'lib/dhcp.rb', line 48

def name
  @name
end

#pxe_pathObject (readonly)

Returns the value of attribute pxe_path.



48
49
50
# File 'lib/dhcp.rb', line 48

def pxe_path
  @pxe_path
end

Instance Method Details

#ip2hex(ip) ⇒ Object



70
71
72
# File 'lib/dhcp.rb', line 70

def ip2hex ip
  ip.split(".").map{|i| "%02x" % i }.join(":")
end

#statements_stringObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/dhcp.rb', line 59

def statements_string
    out = "option subnet-mask = #{ip2hex(@mask)};"
    if @pxe_path
        out += " filename = \\\"#{@pxe_path}\\\";"
    end
    if @hostname
        out += " host-name = \\\"#{@hostname}\\\";"
    end
    return out
end