Skip to content

Commit

Permalink
Added methods for improving the interface to zone assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Feb 5, 2019
1 parent 423ba57 commit 55f55c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions library/network/src/lib/y2firewall/firewalld/interface.rb
Expand Up @@ -96,6 +96,15 @@ def zone
fw.zones.find { |z| z.interfaces.include?(name) }
end

# Assign the interface to the given zone
#
# @param zone_name [String] the name of the zone to be assigned to
def zone=(zone_name)
fw.zones.map { |z| z.remove_interface(name) if z.interfaces.include?(name) }
z = fw.find_zone(zone_name)
z && z.add_interface(name)
end

private

# Return an instance of Y2Firewall::Firewalld
Expand Down
7 changes: 7 additions & 0 deletions library/network/src/lib/y2firewall/firewalld/zone.rb
Expand Up @@ -136,6 +136,13 @@ def add_interface!(interface)
api.change_interface(name, interface)
end

# Assign the interface to the zone removing it previously from any other
# zone that was including it.
def change_interface(interface)
firewalld.zones.each { |z| z.remove_interface(interface) }
add_interface(interface)
end

private

# Convenience method which return an instance of Y2Firewall::Firewalld
Expand Down

0 comments on commit 55f55c2

Please sign in to comment.