class Tablomat::IPSet::Set
Interface to manage ipsets
Attributes
active[R]
name[R]
system[R]
Public Class Methods
new(system, name)
click to toggle source
# File lib/tablomat/ipset/set.rb, line 11 def initialize(system, name) @system = system @name = name @entrys = {} @active = false end
Public Instance Methods
add(entry_data:, add_options: '', exist: false)
click to toggle source
# File lib/tablomat/ipset/set.rb, line 49 def add(entry_data:, add_options: '', exist: false) entry(entry_data).add(add_options, exist) end
create(type:, create_options: '', rangefrom: '', rangeto: '')
click to toggle source
# File lib/tablomat/ipset/set.rb, line 57 def create(type:, create_options: '', rangefrom: '', rangeto: '') create_options = "range #{rangefrom}-#{rangeto} #{create_options}" if type.include?('bitmap') command = "#{@system.ipset_bin} create #{@name} #{type} #{create_options}" @system.exec command @active = true end
del(entry_data:, exist: false)
click to toggle source
# File lib/tablomat/ipset/set.rb, line 53 def del(entry_data:, exist: false) entry(entry_data).del(exist) end
destroy()
click to toggle source
# File lib/tablomat/ipset/set.rb, line 64 def destroy command = "#{@system.ipset_bin} destroy #{@name}" @system.exec command @active = false end
entry(data, &block)
click to toggle source
# File lib/tablomat/ipset/set.rb, line 41 def entry(data, &block) data = data.to_s.downcase (@entrys[data] || Entry.new(self, data)).tap do |entry| @entrys[data] = entry block&.call(entry) end end
exists?()
click to toggle source
# File lib/tablomat/ipset/set.rb, line 18 def exists? command = "#{@system.ipset_bin} list #{@name}" @system.exec command true rescue IPSetError => e raise unless e.message.include?('The set with the given name does not exist') false end
type()
click to toggle source
# File lib/tablomat/ipset/set.rb, line 28 def type command = "#{system.ipset_bin} list #{@name}" stdout = `#{command} 2>&1`.strip << "\n" if $CHILD_STATUS != 0 # throw error puts "Invalid return value when calling #{command}" end stdout = stdout.split("\n").select { |s| s.include?('Type:') }[0] stdout.split(/Type: /)[1] rescue StandardError => e puts "[error] #{e}" end