Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode python3
authorGP Orcullo <kinsamanka@gmail.com>
Mon, 06 Feb 2023 20:07:51 +0800
branchpython3
changeset 3785 29bc2bebf1d4
parent 3784 a5f58ca4629b
child 3786 50935528d313
Generate warning instead of Exception if CTNMaxCount is exceeded for a confnode
ConfigTreeNode.py
--- a/ConfigTreeNode.py	Sat Feb 04 07:19:52 2023 +0800
+++ b/ConfigTreeNode.py	Mon Feb 06 20:07:51 2023 +0800
@@ -558,9 +558,12 @@
         ChildrenWithSameClass = self.Children.setdefault(CTNType, list())
         # Check count
         if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount:
-            raise Exception(
-                _("Max count ({a1}) reached for this confnode of type {a2} ").
-                format(a1=CTNClass.CTNMaxCount, a2=CTNType))
+
+            msg = _("Max count ({a1}) reached for this confnode of type {a2} ").format(
+                    a1=CTNClass.CTNMaxCount, a2=CTNType)
+            self.GetCTRoot().logger.write_warning(msg)
+
+            return None
 
         # create the final class, derived of provided confnode and template
         class FinalCTNClass(CTNClass, ConfigTreeNode):