Class: Host
- Inherits:
-
Object
- Object
- Host
- Defined in:
- lib/resources/host.rb
Overview
Usage: describe host(‘example.com’) do
it { should be_resolvable }
it { should be_reachable }
its(:ipaddress) { should include '93.184.216.34' }
end
To verify a hostname with protocol and port describe host(‘example.com’, port: 53, proto: ‘udp’) do
it { should be_reachable }
end
We do not support the following serverspec syntax: describe host(‘example.com’) do
it { should be_reachable.with( :port => 22 ) }
it { should be_reachable.with( :port => 22, :proto => 'tcp' ) }
it { should be_reachable.with( :port => 53, :proto => 'udp' ) }
it { should be_resolvable.by('hosts') }
it { should be_resolvable.by('dns') }
end
Instance Method Summary collapse
-
#initialize(hostname, params = {}) ⇒ Host
constructor
A new instance of Host.
-
#ipaddress ⇒ Object
returns all A records of the IP adress, will return an array.
- #reachable?(port = nil, proto = nil, timeout = nil) ⇒ Boolean
-
#resolvable?(type = nil) ⇒ Boolean
if we get the IP adress, the host is resolvable.
- #to_s ⇒ Object
Constructor Details
#initialize(hostname, params = {}) ⇒ Host
Returns a new instance of Host.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/resources/host.rb', line 36 def initialize(hostname, params = {}) @hostname = hostname @port = params[:port] || nil @proto = params[:proto] || nil @host_provider = nil if inspec.os.linux? @host_provider = LinuxHostProvider.new(inspec) elsif inspec.os.windows? @host_provider = WindowsHostProvider.new(inspec) else return skip_resource 'The `host` resource is not supported on your OS yet.' end end |
Instance Method Details
#ipaddress ⇒ Object
returns all A records of the IP adress, will return an array
63 64 65 |
# File 'lib/resources/host.rb', line 63 def ipaddress resolve.nil? || resolve.empty? ? nil : resolve end |
#reachable?(port = nil, proto = nil, timeout = nil) ⇒ Boolean
57 58 59 60 |
# File 'lib/resources/host.rb', line 57 def reachable?(port = nil, proto = nil, timeout = nil) fail "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil? ping.nil? ? false : ping end |
#resolvable?(type = nil) ⇒ Boolean
if we get the IP adress, the host is resolvable
52 53 54 55 |
# File 'lib/resources/host.rb', line 52 def resolvable?(type = nil) warn "The `host` resource ignores #{type} parameters. Continue to resolve host." if !type.nil? resolve.nil? || resolve.empty? ? false : true end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/resources/host.rb', line 67 def to_s "Host #{@hostname}" end |