Class: Port
- Inherits:
-
Object
- Object
- Port
- Defined in:
- lib/resources/port.rb
Overview
Usage: describe port(80) do
it { should be_listening }
its('protocol') {should eq 'tcp'}
end
not supported serverspec syntax describe port(80) do
it { should be_listening.with('tcp') }
end
TODO: currently we return local ip only TODO: improve handling of same port on multiple interfaces
Instance Method Summary collapse
-
#initialize(port) ⇒ Port
constructor
A new instance of Port.
- #listening?(_protocol = nil, _local_address = nil) ⇒ Boolean
- #pid ⇒ Object
- #process ⇒ Object
- #protocol ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(port) ⇒ Port
Returns a new instance of Port.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resources/port.rb', line 21 def initialize(port) @port = port @port_manager = nil @cache = nil case inspec.os[:family] when 'ubuntu', 'debian', 'redhat', 'fedora', 'arch' @port_manager = LinuxPorts.new(inspec) when 'darwin' @port_manager = DarwinPorts.new(inspec) when 'windows' @port_manager = WindowsPorts.new(inspec) when 'freebsd' @port_manager = FreeBsdPorts.new(inspec) else return skip_resource 'The `port` resource is not supported on your OS yet.' end end |
Instance Method Details
#listening?(_protocol = nil, _local_address = nil) ⇒ Boolean
40 41 42 |
# File 'lib/resources/port.rb', line 40 def listening?(_protocol = nil, _local_address = nil) info.size > 0 end |
#pid ⇒ Object
54 55 56 57 |
# File 'lib/resources/port.rb', line 54 def pid res = info.map { |x| x[:pid] }.uniq.compact res.size > 0 ? res : nil end |
#process ⇒ Object
49 50 51 52 |
# File 'lib/resources/port.rb', line 49 def process res = info.map { |x| x[:process] }.uniq.compact res.size > 0 ? res : nil end |
#protocol ⇒ Object
44 45 46 47 |
# File 'lib/resources/port.rb', line 44 def protocol res = info.map { |x| x[:protocol] }.uniq.compact res.size > 0 ? res : nil end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/resources/port.rb', line 59 def to_s "Port #{@port}" end |