Class: Inspec::Resources::NetworkInterface
- Inherits:
-
Object
- Object
- Inspec::Resources::NetworkInterface
- Defined in:
- lib/inspec/resources/interface.rb
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(iface) ⇒ NetworkInterface
constructor
A new instance of NetworkInterface.
- #ipv4_address ⇒ Object
- #ipv4_address? ⇒ Boolean
- #ipv4_addresses ⇒ Object
- #ipv4_addresses_netmask ⇒ Object
- #ipv4_cidrs ⇒ Object
- #ipv6_address ⇒ Object
- #ipv6_address? ⇒ Boolean
- #ipv6_addresses ⇒ Object
- #ipv6_cidrs ⇒ Object
- #name ⇒ Object
- #resource_id ⇒ Object
-
#speed ⇒ Object
returns link speed in Mbits/sec.
- #to_s ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize(iface) ⇒ NetworkInterface
Returns a new instance of NetworkInterface.
21 22 23 |
# File 'lib/inspec/resources/interface.rb', line 21 def initialize(iface) @iface = iface end |
Instance Method Details
#exists? ⇒ Boolean
25 26 27 |
# File 'lib/inspec/resources/interface.rb', line 25 def exists? !!(interface_info && interface_info[:name]) end |
#ipv4_address ⇒ Object
50 51 52 |
# File 'lib/inspec/resources/interface.rb', line 50 def ipv4_address ipv4_addresses.first end |
#ipv4_address? ⇒ Boolean
42 43 44 |
# File 'lib/inspec/resources/interface.rb', line 42 def ipv4_address? ipv4_addresses && !ipv4_addresses.empty? end |
#ipv4_addresses ⇒ Object
54 55 56 |
# File 'lib/inspec/resources/interface.rb', line 54 def ipv4_addresses ipv4_cidrs.map { |i| i.split("/")[0] } end |
#ipv4_addresses_netmask ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/inspec/resources/interface.rb', line 66 def ipv4_addresses_netmask ipv4_cidrs.map { |i| i.split("/") }.map do |addr, netlen| binmask = "#{"1" * netlen.to_i}#{"0" * (32 - netlen.to_i)}".to_i(2) netmask = [] (1..4).each do |_byte| netmask.unshift(binmask & 255) binmask = binmask >> 8 end "#{addr}/#{netmask.join(".")}" end end |
#ipv4_cidrs ⇒ Object
78 79 80 |
# File 'lib/inspec/resources/interface.rb', line 78 def ipv4_cidrs interface_info && Array(interface_info[:ipv4_addresses]) end |
#ipv6_address ⇒ Object
58 59 60 |
# File 'lib/inspec/resources/interface.rb', line 58 def ipv6_address ipv6_addresses.first end |
#ipv6_address? ⇒ Boolean
46 47 48 |
# File 'lib/inspec/resources/interface.rb', line 46 def ipv6_address? ipv6_addresses && !ipv6_addresses.empty? end |
#ipv6_addresses ⇒ Object
62 63 64 |
# File 'lib/inspec/resources/interface.rb', line 62 def ipv6_addresses ipv6_cidrs.map { |i| i.split("/")[0] } end |
#ipv6_cidrs ⇒ Object
82 83 84 |
# File 'lib/inspec/resources/interface.rb', line 82 def ipv6_cidrs interface_info && Array(interface_info[:ipv6_addresses]) end |
#name ⇒ Object
33 34 35 |
# File 'lib/inspec/resources/interface.rb', line 33 def name interface_info[:name] end |
#resource_id ⇒ Object
86 87 88 |
# File 'lib/inspec/resources/interface.rb', line 86 def resource_id @iface || "Interface" end |
#speed ⇒ Object
returns link speed in Mbits/sec
38 39 40 |
# File 'lib/inspec/resources/interface.rb', line 38 def speed interface_info && interface_info[:speed] end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/inspec/resources/interface.rb', line 90 def to_s "Interface #{@iface}" end |
#up? ⇒ Boolean
29 30 31 |
# File 'lib/inspec/resources/interface.rb', line 29 def up? !!(interface_info && interface_info[:up]) end |