Class: Y2Firewall::Firewalld::Interface
- Inherits:
-
Object
- Object
- Y2Firewall::Firewalld::Interface
- Includes:
- Yast::I18n
- Defined in:
- library/network/src/lib/y2firewall/firewalld/interface.rb
Overview
Class to work with firewalld interfaces
Instance Attribute Summary collapse
Class Method Summary collapse
-
.fw ⇒ Y2Firewall::Firewalld
Return an instance of Y2Firewall::Firewalld.
-
.known ⇒ Array<Y2Firewall::Firewalld::Interface>
Return an array with all the known or configured interfaces.
-
.unknown ⇒ Array<Y2Firewall::Firewalld::Interface>
Return an array with all the interfaces that belongs to some firewalld zone but are not known (sysconfig configured).
Instance Method Summary collapse
-
#device_name ⇒ String
Return the network interface device name in case it is configured or 'Unknown' in other case.
-
#initialize(name) ⇒ Interface
constructor
Constructor.
-
#known? ⇒ Boolean
Return whether the zone is a known one.
-
#name ⇒ String
Interface name.
-
#zone ⇒ Y2Firewall::Firewalld::Zone?
Return the zone name for a given interface from the firewalld instance instead of from the API.
-
#zone=(zone_name) ⇒ Object
Assign the interface to the given zone.
Constructor Details
#initialize(name) ⇒ Interface
Constructor
35 36 37 38 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 35 def initialize(name) textdomain "firewall" @id = name.to_sym end |
Instance Attribute Details
#id ⇒ Symbol
30 31 32 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 30 def id @id end |
Class Method Details
.fw ⇒ Y2Firewall::Firewalld
Return an instance of Y2Firewall::Firewalld
44 45 46 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 44 def fw Y2Firewall::Firewalld.instance end |
.known ⇒ Array<Y2Firewall::Firewalld::Interface>
Return an array with all the known or configured interfaces
51 52 53 54 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 51 def known interfaces = Yast::NetworkInterfaces.List("").reject { |i| i == "lo" } interfaces.map { |i| new(i) } end |
.unknown ⇒ Array<Y2Firewall::Firewalld::Interface>
Return an array with all the interfaces that belongs to some firewalld zone but are not known (sysconfig configured)
60 61 62 63 64 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 60 def unknown known_interfaces = Yast::NetworkInterfaces.List("").reject { |i| i == "lo" } configured_interfaces = fw.zones.map(&:interfaces).flatten.compact (configured_interfaces - known_interfaces).map { |i| new(i) } end |
Instance Method Details
#device_name ⇒ String
Return the network interface device name in case it is configured or 'Unknown' in other case
84 85 86 87 88 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 84 def device_name return _("Unknown") unless known? Yast::NetworkInterfaces.GetValue(name, "NAME") end |
#known? ⇒ Boolean
Return whether the zone is a known one
71 72 73 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 71 def known? Yast::NetworkInterfaces.List("").reject { |i| i == "lo" }.include?(name) end |
#name ⇒ String
Returns interface name.
76 77 78 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 76 def name id.to_s end |
#zone ⇒ Y2Firewall::Firewalld::Zone?
Return the zone name for a given interface from the firewalld instance instead of from the API.
94 95 96 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 94 def zone fw.zones.find { |z| z.interfaces.include?(name) } end |
#zone=(zone_name) ⇒ Object
Assign the interface to the given zone
101 102 103 104 105 |
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 101 def zone=(zone_name) fw.zones.each { |z| z.remove_interface(name) if z.interfaces.include?(name) } z = fw.find_zone(zone_name) z&.add_interface(name) end |