Class: Inspec::Resources::Defaultgateway
- Inherits:
-
Routingtable
- Object
- Routingtable
- Inspec::Resources::Defaultgateway
- Defined in:
- lib/inspec/resources/default_gateway.rb
Instance Method Summary collapse
-
#initialize ⇒ Defaultgateway
constructor
A new instance of Defaultgateway.
-
#interface ⇒ Object
fetches the interface assigned to the default gateway.
-
#ipaddress ⇒ Object
fetches the ipaddress assigned to the default gateway default gateway’s destination is either ‘default` or `0.0.0.0`.
-
#to_s ⇒ Object
resource appearance in test reports.
Methods inherited from Routingtable
Constructor Details
#initialize ⇒ Defaultgateway
Returns a new instance of Defaultgateway.
25 26 27 28 29 |
# File 'lib/inspec/resources/default_gateway.rb', line 25 def initialize skip_resource "The `default_gateway` resource is not yet available on your OS." unless inspec.os.unix? || inspec.os.windows? # invoke the routing_table initialize; which populates the @routing_info super() end |
Instance Method Details
#interface ⇒ Object
fetches the interface assigned to the default gateway
53 54 55 56 57 58 59 |
# File 'lib/inspec/resources/default_gateway.rb', line 53 def interface %w{default 0.0.0.0}.each do |destination| return @routing_info[destination][0][1] if @routing_info.key?(destination) end # raise exception because no destination with value default or 0.0.0.0 is found in the routing table raise Inspec::Exceptions::ResourceFailed, "No routing found as part of default gateway" end |
#ipaddress ⇒ Object
fetches the ipaddress assigned to the default gateway default gateway’s destination is either ‘default` or `0.0.0.0`
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/inspec/resources/default_gateway.rb', line 38 def ipaddress # @routing_info is the hash populated in routing_table resource # @routing_info contain values as: # { # destination1: [ [gateway1x, interface1x], [gateway1y, interface1y] ], # destination2: [gateway2, interface2] # } %w{default 0.0.0.0}.each do |destination| return @routing_info[destination][0][0] if @routing_info.key?(destination) end # raise exception because no destination with value default or 0.0.0.0 is found in the routing table raise Inspec::Exceptions::ResourceFailed, "No routing found as part of default gateway" end |
#to_s ⇒ Object
resource appearance in test reports.
32 33 34 |
# File 'lib/inspec/resources/default_gateway.rb', line 32 def to_s "default_gateway" end |