Class: Infrataster::Plugin::Firewall::Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/infrataster/plugin/firewall/capture.rb

Overview

Reqresent capture

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, bpf = nil, term_sec = 3) ⇒ Capture

Returns a new instance of Capture.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/infrataster/plugin/firewall/capture.rb', line 9

def initialize(node, bpf = nil, term_sec = 3)
  @node = node.respond_to?(:server) ? node.server :
    Net::SSH.start(node, config: true)
  @bpf = bpf
  @connected = false
  @term_sec = term_sec
  @thread = nil
  @ssh = nil
  @result = false
  @output = ''
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/infrataster/plugin/firewall/capture.rb', line 7

def output
  @output
end

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/infrataster/plugin/firewall/capture.rb', line 7

def result
  @result
end

Class Method Details

.bpf(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/infrataster/plugin/firewall/capture.rb', line 36

def self.bpf(options = {})
  is_first = true
  filter = ''

  options.each do |k, v|
    filter << ' and ' unless is_first
    filter << "#{k} #{v}"
    is_first = false
  end
  filter
end

Instance Method Details

#closeObject



30
31
32
33
34
# File 'lib/infrataster/plugin/firewall/capture.rb', line 30

def close
  sleep 0.5 until capture_done?
  @thread.kill
  @ssh.close unless @ssh.closed?
end

#open(&block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/infrataster/plugin/firewall/capture.rb', line 21

def open(&block)
  open_node
  wait_connected
  return unless block

  block.call
  close
end