Class: Iface::RangeFile
Overview
Represents a range config file (a range of IP addresses)
These are files named like “ifcfg-eth0-range0”.
Instance Attribute Summary collapse
Attributes inherited from ConfigFile
#device, #filename, #vars
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ConfigFile
create, file_type_name, parse_filename
Constructor Details
#initialize(filename, device, range_num, clone_num, vars) ⇒ RangeFile
128
129
130
131
132
133
|
# File 'lib/iface/config_file.rb', line 128
def initialize(filename, device, range_num, clone_num, vars)
super
@start_ip_num = string_to_ip_num(vars['ipaddr_start'])
@end_ip_num = string_to_ip_num(vars['ipaddr_end'])
@start_clone_num = vars['clonenum_start']&.to_i
end
|
Instance Attribute Details
#start_clone_num ⇒ Object
Returns the value of attribute start_clone_num.
122
123
124
|
# File 'lib/iface/config_file.rb', line 122
def start_clone_num
@start_clone_num
end
|
Class Method Details
.recognize?(_device, range_num, _clone_num, _vars) ⇒ Boolean
124
125
126
|
# File 'lib/iface/config_file.rb', line 124
def self.recognize?(_device, range_num, _clone_num, _vars)
!range_num.nil?
end
|
Instance Method Details
#end_ip_num ⇒ Object
148
149
150
|
# File 'lib/iface/config_file.rb', line 148
def end_ip_num
@end_ip_num.to_ip
end
|
#include?(ip) ⇒ Boolean
139
140
141
142
|
# File 'lib/iface/config_file.rb', line 139
def include?(ip)
ip_num = string_to_ip_num(ip)
@start_ip_num <= ip_num && ip_num <= @end_ip_num
end
|
#start_ip_num ⇒ Object
144
145
146
|
# File 'lib/iface/config_file.rb', line 144
def start_ip_num
@start_ip_num.to_ip
end
|
#static? ⇒ Boolean
135
136
137
|
# File 'lib/iface/config_file.rb', line 135
def static?
true
end
|
#string_to_ip_num(str) ⇒ Object
152
153
154
|
# File 'lib/iface/config_file.rb', line 152
def string_to_ip_num(str)
str.split('.').collect { |x| x.to_i.to_s(16).rjust(2, '0') }.join.hex
end
|