Sandro Bonazzola has uploaded a new change for review. Change subject: network: firewalld: support firewall-cmd >= 0.3 ......................................................................
network: firewalld: support firewall-cmd >= 0.3 in firewall-cmd 0.3.3 shipped with Fedora 19 firewall-cmd --get-active-zone has changed the output from: <zone1>: <interface1> <interface2> to: <zone1>: interfaces: <interface1> <interface2> Change-Id: I5fe22c1f05dc98bc71a6ffd6fe28549721cda4f1 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M src/plugins/otopi/network/firewalld.py 1 file changed, 40 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/94/16094/1 diff --git a/src/plugins/otopi/network/firewalld.py b/src/plugins/otopi/network/firewalld.py index c6c58a5..e3cbea7 100644 --- a/src/plugins/otopi/network/firewalld.py +++ b/src/plugins/otopi/network/firewalld.py @@ -21,6 +21,7 @@ """firewalld plugin.""" import os +import re import gettext _ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup') @@ -42,6 +43,16 @@ """ FIREWALLD_SERVICES_DIR = '/etc/firewalld/services' + _ZONE_RE = re.compile(r'\w+') + _INTERFACE_RE = re.compile( + flags=re.VERBOSE, + pattern=r""" + \s+ + interfaces: + \s+ + (?P<interfaces>[\w,]+) + """ + ) def _isPermanentSupported(self): """ @@ -60,6 +71,15 @@ ret = ''.join(stdout).find('--permanent') != -1 return ret + def _get_firewalld_cmd_version(self): + rc, stdout, stderr = self.execute( + ( + self.command.get('firewall-cmd'), + '--version', + ), + ) + return stdout[0].split('.') + def _get_active_zones(self): rc, stdout, stderr = self.execute( ( @@ -68,9 +88,26 @@ ), ) zones = {} - for line in stdout: - zone_name, devices = line.split(':') - zones[zone_name] = devices.split() + version = self._get_firewalld_cmd_version() + if ( + int(version[0]) == 0 and + int(version[1]) <= 2 + ): + for line in stdout: + zone_name, devices = line.split(':') + zones[zone_name] = devices.split() + else: + #0.3 has changed output + zone_name = None + for line in stdout: + if self._ZONE_RE.match(line): + zone_name = line + elif self._INTERFACE_RE.match(line): + devices = self._INTERFACE_RE.match( + line + ).group('interfaces') + zones[zone_name] = devices.split() + return zones def __init__(self, context): -- To view, visit http://gerrit.ovirt.org/16094 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5fe22c1f05dc98bc71a6ffd6fe28549721cda4f1 Gerrit-PatchSet: 1 Gerrit-Project: otopi Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches