Blame SOURCES/firewalld-0.7-0026-command-sort-rich-rule-output-by-priority.patch

21c891
From bec614ce987935a8fccb99c32fb2ba342b17048a Mon Sep 17 00:00:00 2001
21c891
From: Eric Garver <e@erig.me>
21c891
Date: Thu, 29 Nov 2018 12:26:08 -0500
21c891
Subject: [PATCH 26/34] command: sort rich rule output by priority
21c891
21c891
(cherry picked from commit 606e853e58028b6a8cfd91c1544e58346e7966be)
21c891
---
21c891
 src/firewall/command.py | 16 +++++++++++++++-
21c891
 1 file changed, 15 insertions(+), 1 deletion(-)
21c891
21c891
diff --git a/src/firewall/command.py b/src/firewall/command.py
21c891
index 6c93be840760..1449b6dfc3ea 100644
21c891
--- a/src/firewall/command.py
21c891
+++ b/src/firewall/command.py
21c891
@@ -393,6 +393,19 @@ class FirewallCommand(object):
21c891
         description = settings.getDescription()
21c891
         short_description = settings.getShort()
21c891
 
21c891
+        def rich_rule_sorted_key(rule):
21c891
+            priority = 0
21c891
+            search_str = "priority="
21c891
+            try:
21c891
+                i = rule.index(search_str)
21c891
+            except ValueError:
21c891
+                pass
21c891
+            else:
21c891
+                i += len(search_str)
21c891
+                priority = int(rule[i:i+(rule[i:].index(" "))].replace("\"", ""))
21c891
+
21c891
+            return priority
21c891
+
21c891
         attributes = []
21c891
         if default_zone is not None:
21c891
             if zone == default_zone:
21c891
@@ -424,7 +437,8 @@ class FirewallCommand(object):
21c891
                        " ".join(["%s/%s" % (port[0], port[1])
21c891
                                  for port in source_ports]))
21c891
         self.print_msg("  icmp-blocks: " + " ".join(icmp_blocks))
21c891
-        self.print_msg("  rich rules: \n\t" + "\n\t".join(rules))
21c891
+        self.print_msg("  rich rules: \n\t" + "\n\t".join(
21c891
+                            sorted(rules, key=rich_rule_sorted_key)))
21c891
 
21c891
     def print_service_info(self, service, settings):
21c891
         ports = settings.getPorts()
21c891
-- 
21c891
2.18.0
21c891