Skip to content

Commit

Permalink
actors: add FirewalldCollectDirectConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
erig0 committed Oct 30, 2024
1 parent 745f698 commit ce41185
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from leapp.actors import Actor
from leapp.libraries.actor.private_firewalldcollectdirectconfig import read_config
from leapp.models import FirewalldDirectConfig
from leapp.tags import FactsPhaseTag, IPUWorkflowTag


class FirewalldCollectDirectConfig(Actor):
"""
This actor reads firewalld's configuration and produces Model
FirewalldDirectConfig.
"""

name = 'firewalld_collect_direct_config'
consumes = ()
produces = (FirewalldDirectConfig,)
tags = (FactsPhaseTag, IPUWorkflowTag)

def process(self):
self.produce(read_config())
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from leapp.models import FirewalldDirectConfig

try:
from firewall.core.fw import Firewall
except ImportError:
pass


def read_config():
try:
fw = Firewall(offline=True)
except NameError:
# import failure missing means firewalld is not installed. Just return
# the defaults.
return FirewalldDirectConfig()

# This does not actually start firewalld. It just loads the configuration a
# la firewall-offline-cmd.
fw.start()

conf = fw.config.get_direct().export_config()

conf_dict = {}
conf_dict['has_permanent_configuration'] = any(conf)

return FirewalldDirectConfig(**conf_dict)

0 comments on commit ce41185

Please sign in to comment.