Class: Y2Firewall::Firewalld::Interface

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Interface

Constructor

Parameters:

  • name (String)

    interface name


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

#idSymbol

Returns:

  • (Symbol)

30
31
32
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 30

def id
  @id
end

Class Method Details

.fwY2Firewall::Firewalld

Return an instance of Y2Firewall::Firewalld

Returns:


44
45
46
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 44

def fw
  Y2Firewall::Firewalld.instance
end

.knownArray<Y2Firewall::Firewalld::Interface>

Return an array with all the known or configured interfaces

Returns:


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

.unknownArray<Y2Firewall::Firewalld::Interface>

Return an array with all the interfaces that belongs to some firewalld zone but are not known (sysconfig configured)

Returns:


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_nameString

Return the network interface device name in case it is configured or 'Unknown' in other case

Returns:

  • (String)

    its device name or 'Unknown' if not configured


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

Returns:

  • (Boolean)

    true if the interface is known

See Also:


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

#nameString

Returns interface name.

Returns:

  • (String)

    interface name


76
77
78
# File 'library/network/src/lib/y2firewall/firewalld/interface.rb', line 76

def name
  id.to_s
end

#zoneY2Firewall::Firewalld::Zone?

Return the zone name for a given interface from the firewalld instance instead of from the API.

Returns:


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

Parameters:

  • zone_name (String)

    the name of the zone to be assigned to


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