class Havox::DSL::Directive
Constants
- MERLIN_DIC
Attributes
attributes[R]
switch[R]
Public Class Methods
new(type, switch, attributes = {})
click to toggle source
# File lib/havox/dsl/directive.rb, line 20 def initialize(type, switch, attributes = {}) @type = type @switch = switch @attributes = attributes end
Public Instance Methods
method_missing(name, *args, &block)
click to toggle source
# File lib/havox/dsl/directive.rb, line 26 def method_missing(name, *args, &block) @attributes[name] = args.first end
to_block(src_hosts, dst_hosts, qos = nil)
click to toggle source
# File lib/havox/dsl/directive.rb, line 30 def to_block(src_hosts, dst_hosts, qos = nil) "#{foreach_code(src_hosts, dst_hosts)}\n #{to_statement(qos)}\n" end
Private Instance Methods
foreach_code(src_hosts, dst_hosts)
click to toggle source
# File lib/havox/dsl/directive.rb, line 47 def foreach_code(src_hosts, dst_hosts) src_hosts_str = format_hosts(src_hosts) dst_hosts_str = format_hosts(dst_hosts) "foreach (s, d): cross(#{src_hosts_str}, #{dst_hosts_str})" end
format_hosts(host_names)
click to toggle source
# File lib/havox/dsl/directive.rb, line 43 def format_hosts(host_names) "{ #{host_names.join('; ')} }" end
netmask_removed(ip)
click to toggle source
# File lib/havox/dsl/directive.rb, line 61 def netmask_removed(ip) IPAddr.new(ip).to_s end
regex_path()
click to toggle source
# File lib/havox/dsl/directive.rb, line 65 def regex_path ".* #{@switch.to_s}".strip end
to_statement(qos)
click to toggle source
# File lib/havox/dsl/directive.rb, line 36 def to_statement(qos) fields = @attributes.map { |k, v| "#{MERLIN_DIC[k]} = #{treated(v, k)}" } predicate = fields.join(' and ') qos_str = qos.nil? ? '' : " at #{qos}" "#{predicate} -> #{regex_path}#{qos_str};" end
treated(value, field)
click to toggle source
# File lib/havox/dsl/directive.rb, line 53 def treated(value, field) case field when :source_ip then netmask_removed(value) when :destination_ip then netmask_removed(value) else value end end