Module: Havox::Merlin

Defined in:
lib/havox/exceptions.rb,
lib/havox/modules/merlin.rb

Defined Under Namespace

Classes: ParsingError

Class Method Summary collapse

Class Method Details

.compile(topology_file, policy_file, opts = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/havox/modules/merlin.rb', line 65

def self.compile(topology_file, policy_file, opts = {})
  rules = []
  result = run(cmd.compile(topology_file, policy_file))                     # Runs Merlin in the remote VM and retrieves its output.
  result = parse(result)                                                    # Parses the output into raw rules.
  result = Havox::RuleSanitizer.new(result).sanitized_rules                 # Removes unwanted rule snippets.
  result = Havox::RuleExpander.new(result).expanded_rules if opts[:expand]  # Expands each raw rule in the parsed result.
  result.each { |raw_rule| rules << Havox::Rule.new(raw_rule, opts) }       # Creates Rule instances for each raw rule.
  rules
end

.compile!(topology_file, policy_file, opts = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/havox/modules/merlin.rb', line 75

def self.compile!(topology_file, policy_file, opts = {})
  check_options(opts)
  policy_file = Havox::ModifiedPolicy.new(topology_file, policy_file).path if opts[:basic]
  if upload!(topology_file, opts[:dst]) && upload!(policy_file, opts[:dst])
    topology_file = "#{opts[:dst]}#{basename(topology_file)}"
    policy_file = "#{opts[:dst]}#{basename(policy_file)}"
    compile(topology_file, policy_file, opts)
  end
end

.run(command) ⇒ Object



53
54
55
56
57
# File 'lib/havox/modules/merlin.rb', line 53

def self.run(command)
  output = nil
  ssh_connection { |ssh| output = ssh.exec!(command) }
  output
end

.upload!(file, dst = nil) ⇒ Object



59
60
61
62
63
# File 'lib/havox/modules/merlin.rb', line 59

def self.upload!(file, dst = nil)
  dst ||= "#{config.merlin_path}/examples/"
  ssh_connection { |ssh| ssh.scp.upload!(file, dst) }
  true
end