[et-mgmt-tools] [PATCH] Added with_triggers=True variable to functions that call triggers.

Riggs, Ben rigg0022 at umn.edu
Thu Nov 15 19:46:18 UTC 2007


Michael DeHaan wrote:
 > Ben,
 >
 > This attachment seems to be zero-length ...
 >
 > --Michael

I'm confused, myself. I received this response from 
et-mgmt-tools-bounces at redhat.com:



You are not allowed to post to this mailing list, and your message has
been automatically rejected.  If you think that your messages are
being rejected in error, contact the mailing list owner at
et-mgmt-tools-owner at redhat.com.

---------------------------------------------------------------------

Subject:
[PATCH] Added with_triggers=True variable to functions that call 
triggers. This allows one to pass with_triggers=False from the API to 
bypass triggers. It can be used to prevent infinite recursions caused by 
adding a system during a pre/post add trigger.
From:
Ben Riggs <rigg0022 at math.umn.edu>
Date:
Wed, 14 Nov 2007 14:27:21 -0600

---
  cobbler/collection.py          |    6 +++---
  cobbler/collection_distros.py  |    6 +++---
  cobbler/collection_profiles.py |    6 +++---
  cobbler/collection_repos.py    |    6 +++---
  cobbler/collection_systems.py  |    6 +++---
  5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/cobbler/collection.py b/cobbler/collection.py
index 8e6be39..a9364d4 100644
--- a/cobbler/collection.py
+++ b/cobbler/collection.py
@@ -96,7 +96,7 @@ class Collection(serializable.Serializable):
              item = self.factory_produce(self.config,seed_data)
              self.add(item)

-    def add(self,ref,with_copy=False):
+    def add(self,ref,with_copy=False,with_triggers=True):
          """
          Add an object to the collection, if it's valid.  Returns True
          if the object was added to the collection.  Returns False if the
@@ -126,7 +126,7 @@ class Collection(serializable.Serializable):
          # perform filesystem operations
          if with_copy:
              # failure of a pre trigger will prevent the object from 
being added
- 
self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/pre/*" % 
self.collection_type())
+            if with_triggers: 
self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/pre/*" % 
self.collection_type())
              self.listing[ref.name.lower()] = ref

              # save just this item if possible, if not, save
@@ -146,7 +146,7 @@ class Collection(serializable.Serializable):
                  print _("Internal error. Object type not recognized: 
%s") % type(ref)

              # save the tree, so if neccessary, scripts can examine it.
- 
self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/post/*" % 
self.collection_type())
+            if with_triggers: 
self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/post/*" % 
self.collection_type())

          # update children cache in parent object
          parent = ref.get_parent()
diff --git a/cobbler/collection_distros.py b/cobbler/collection_distros.py
index b696738..b415766 100644
--- a/cobbler/collection_distros.py
+++ b/cobbler/collection_distros.py
@@ -31,7 +31,7 @@ class Distros(collection.Collection):
          """
          return distro.Distro(config).from_datastruct(seed_data)

-    def remove(self,name,with_delete=True):
+    def remove(self,name,with_delete=True,with_triggers=True):
          """
          Remove element named 'name' from the collection
          """
@@ -43,13 +43,13 @@ class Distros(collection.Collection):
          obj = self.find(name=name)
          if obj is not None:
              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/distro/pre/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/distro/pre/*")
                  lite_sync = action_litesync.BootLiteSync(self.config)
                  lite_sync.remove_single_profile(name)
              del self.listing[name]
              self.config.serialize_delete(self, obj)
              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/distro/post/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/distro/post/*")
              return True
          raise CX(_("cannot delete object that does not exist"))

diff --git a/cobbler/collection_profiles.py b/cobbler/collection_profiles.py
index b878ff9..6892e4e 100644
--- a/cobbler/collection_profiles.py
+++ b/cobbler/collection_profiles.py
@@ -32,7 +32,7 @@ class Profiles(collection.Collection):
      def factory_produce(self,config,seed_data):
          return profile.Profile(config).from_datastruct(seed_data)

-    def remove(self,name,with_delete=True):
+    def remove(self,name,with_delete=True,with_triggers=True):
          """
          Remove element named 'name' from the collection
          """
@@ -43,13 +43,13 @@ class Profiles(collection.Collection):
          obj = self.find(name=name)
          if obj is not None:
              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/profile/pre/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/profile/pre/*")
                  lite_sync = action_litesync.BootLiteSync(self.config)
                  lite_sync.remove_single_profile(name)
              del self.listing[name]
              self.config.serialize_delete(self, obj)
              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/profile/post/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/profile/post/*")
              return True
          raise CX(_("cannot delete an object that does not exist"))

diff --git a/cobbler/collection_repos.py b/cobbler/collection_repos.py
index da1a3bd..62d7ff0 100644
--- a/cobbler/collection_repos.py
+++ b/cobbler/collection_repos.py
@@ -36,7 +36,7 @@ class Repos(collection.Collection):
          """
          return repo.Repo(config).from_datastruct(seed_data)

-    def remove(self,name,with_delete=True):
+    def remove(self,name,with_delete=True,with_triggers=True):
          """
          Remove element named 'name' from the collection
          """
@@ -47,13 +47,13 @@ class Repos(collection.Collection):
          obj = self.find(name=name)
          if obj is not None:
              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/repo/pre/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/repo/pre/*")

              del self.listing[name]
              self.config.serialize_delete(self, obj)

              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/repo/post/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/repo/post/*")
              return True
          raise CX(_("cannot delete an object that does not exist"))

diff --git a/cobbler/collection_systems.py b/cobbler/collection_systems.py
index a871f9a..d31ee2e 100644
--- a/cobbler/collection_systems.py
+++ b/cobbler/collection_systems.py
@@ -33,7 +33,7 @@ class Systems(collection.Collection):
          """
          return system.System(config).from_datastruct(seed_data)

-    def remove(self,name,with_delete=True):
+    def remove(self,name,with_delete=True,with_triggers=True):
          """
          Remove element named 'name' from the collection
          """
@@ -43,13 +43,13 @@ class Systems(collection.Collection):
          if obj is not None:

              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/system/pre/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/system/pre/*")
                  lite_sync = action_litesync.BootLiteSync(self.config)
                  lite_sync.remove_single_system(name)
              del self.listing[name]
              self.config.serialize_delete(self, obj)
              if with_delete:
-                self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/system/post/*")
+                if with_triggers: self._run_triggers(obj, 
"/var/lib/cobbler/triggers/delete/system/post/*")

              return True
          raise CX(_("cannot delete an object that does not exist"))
-- 1.5.2.4 --------------040405030105090803090001--




More information about the et-mgmt-tools mailing list