[et-mgmt-tools] [PATCH] Cobbler: recommendation for pre/post synchronization trigger implementation

Michael DeHaan mdehaan at redhat.com
Tue Jun 5 15:23:34 UTC 2007


Adam Rosenwald wrote:

I'll check this patch out shortly... It looks pretty good to me. Thanks!

> I spoke with Michael somewhat on IRC regarding my desire to implement 
> a DNS zone-related trigger mechanism. My main problem was that cobbler 
> "core" (as opposed to "triggers") enforced a policy on trigger 
> writers. When adding a new system (generically speaking, "cobbler 
> system add --name=<ip│mac│hostname | default> --profile=<string>", 
> where --name=hostname, and hostname != <resolveable hostname>, cobbler 
> prevents the system addition.
FYI -- This is already removed in upstream. (Cobbler system add 
--name=foo --mac=AA:BB:CC:DD:EE:FF) is now legal, and things work 
appropriately. If you leave off the --mac and the --ip, the system can't 
PXE, but it can still live in the config. Implict adds such as "cobbler 
system add --name=AA:BB:CC:DD:EE:FF" will automatically set the mac 
address, as before.

>
> This presented much difficulty in adding zone entries to systems that 
> didn't yet exist in DNS (chicken and egg). If that were not enough 
> trouble, if I would then remove the checking mechanism (as seen in 
> action_sync.py:get_pxe_filename() method), the sync occurs regardless 
> whether my own 'valid hostname' checks could be utilized.
>
> I asked Michael if there were a way to push such policy mechanisms 
> (there really is only one -- the system.name <http://system.name> 
> check) to the trigger writers, so I might have a way to enforce my 
> checks. Rather than to rewrite the control of the add method (whose 
> utility outweighs its rarely-seen limitations), Michael recommended 
> some options including the solution I'm offering.
>
> With the following minor patch and the addition of 
> ../trigger/system/{add,remove}/{pre,post} directories, triggers that 
> either make use of custom checks (which conflict with those in 
> get_pxe_filename()) and/or need to be executed prior to syncs, can 
> then be placed in the .../pre/... directories. Those triggers which 
> may be executed without these requirements can be placed in the 
> .../post/... directories.
>
> I am able to refer to "sys.argv[1]" within my trigger, and this will 
> refer to the --name. Then, I can make use of --name within my 
> pre_trigger and perform custom checks, dns zone instantiation, etc. 
> before returning control to cobbler core, where the core name checks 
> are then performed. Normal triggers would be called after sync as they 
> currently are, but they are to be found in the .../post/... directory.
Yup...
>
> There are other ways of implementing the mechanism. Perhaps only one 
> trigger directory is needed with checked filename prefixes or suffixes 
> for pre/post. I am only following the existing mechanism in adding the 
> directories. If there are more elegant or efficient mechanisms, it 
> will likely be part of a complete trigger system rehaul, as Michael 
> has alluded to...
The main thing I want to see is pre-triggers filtering checking return 
codes, so as to reject additions to the config if any of the 
pre-triggers fail. This is pretty simple.

Post-return codes also need to be paid attention to, which is something 
the current cobbler system doesn't do either :) ...


>
> If you would like to use this patch, you will have to rebuild with the 
> following changes to the specfile and setup.py:
>
> --- cobbler.spec.orig 2007-04-26 22:03:04.000000000 +0000
> +++ cobbler.spec 2007-06-04 23:35:23.000000000 +0000
> @@ -105,14 +105,22 @@
> %dir /var/log/cobbler/syslog
> %defattr(2550,root,root)
> %dir /var/lib/cobbler
> -%dir /var/lib/cobbler/triggers/add/distro
> -%dir /var/lib/cobbler/triggers/add/profile
> -%dir /var/lib/cobbler/triggers/add/system
> -%dir /var/lib/cobbler/triggers/add/repo
> -%dir /var/lib/cobbler/triggers/delete/distro
> -%dir /var/lib/cobbler/triggers/delete/profile
> -%dir /var/lib/cobbler/triggers/delete/system
> -%dir /var/lib/cobbler/triggers/delete/repo
> +%dir /var/lib/cobbler/triggers/add/distro/pre
> +%dir /var/lib/cobbler/triggers/add/distro/post
> +%dir /var/lib/cobbler/triggers/add/profile/pre
> +%dir /var/lib/cobbler/triggers/add/profile/post
> +%dir /var/lib/cobbler/triggers/add/system/pre
> +%dir /var/lib/cobbler/triggers/add/system/post
> +%dir /var/lib/cobbler/triggers/add/repo/pre
> +%dir /var/lib/cobbler/triggers/add/repo/post
> +%dir /var/lib/cobbler/triggers/delete/distro/pre
> +%dir /var/lib/cobbler/triggers/delete/distro/post
> +%dir /var/lib/cobbler/triggers/delete/profile/pre
> +%dir /var/lib/cobbler/triggers/delete/profile/post
> +%dir /var/lib/cobbler/triggers/delete/system/pre
> +%dir /var/lib/cobbler/triggers/delete/system/post
> +%dir /var/lib/cobbler/triggers/delete/repo/pre
> +%dir /var/lib/cobbler/triggers/delete/repo/post
> /var/lib/cobbler/elilo-3.6-ia64.efi
> /var/lib/cobbler/menu.c32
> %defattr(-,root,root)
>
> --- setup.py.orig 2007-04-26 18:03:12.000000000 -0400
> +++ setup.py 2007-06-04 22:05:22.000000000 -0400
> @@ -78,14 +78,22 @@
> (vw_links, []),
> (tftp_cfg, []),
> (tftp_images, []),
> - ("/var/lib/cobbler/triggers/add/distro", []),
> - ("/var/lib/cobbler/triggers/add/profile", []),
> - ("/var/lib/cobbler/triggers/add/system", []),
> - ("/var/lib/cobbler/triggers/add/repo", []),
> - ("/var/lib/cobbler/triggers/delete/distro", []),
> - ("/var/lib/cobbler/triggers/delete/profile", []),
> - ("/var/lib/cobbler/triggers/delete/system", []),
> - ("/var/lib/cobbler/triggers/delete/repo", [])
> + ("/var/lib/cobbler/triggers/add/distro/pre", []),
> + ("/var/lib/cobbler/triggers/add/distro/post", []),
> + ("/var/lib/cobbler/triggers/add/profile/pre", []),
> + ("/var/lib/cobbler/triggers/add/profile/post", []),
> + ("/var/lib/cobbler/triggers/add/system/pre", []),
> + ("/var/lib/cobbler/triggers/add/system/post", []),
> + ("/var/lib/cobbler/triggers/add/repo/pre", []),
> + ("/var/lib/cobbler/triggers/add/repo/post", []),
> + ("/var/lib/cobbler/triggers/delete/distro/pre", []),
> + ("/var/lib/cobbler/triggers/delete/distro/post", []),
> + ("/var/lib/cobbler/triggers/delete/profile/pre", []),
> + ("/var/lib/cobbler/triggers/delete/profile/post", []),
> + ("/var/lib/cobbler/triggers/delete/system/pre", []),
> + ("/var/lib/cobbler/triggers/delete/system/post", []),
> + ("/var/lib/cobbler/triggers/delete/repo/pre", [])
> + ("/var/lib/cobbler/triggers/delete/repo/post", [])
> ],
> description = SHORT_DESC,
> long_description = LONG_DESC
>
>
> The actual core patches are listed below
>
> --- cobbler/collection_distros.py.orig 2007-04-16 15:57:29.000000000 -0400
> +++ cobbler/collection_distros.py 2007-06-04 21:38:33.000000000 -0400
> @@ -51,9 +51,10 @@
> raise cexceptions.CobblerException("orphan_profile",v.name 
> <http://v.name>)
> if self.find(name):
> if with_delete:
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/distro/pre/*")
> lite_sync = action_litesync.BootLiteSync(self.config)
> lite_sync.remove_single_profile(name)
> - self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/distro/*")
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/distro/post/*")
> del self.listing[name]
> return True
> raise cexceptions.CobblerException("delete_nothing")
> --- cobbler/collection_profiles.py.orig 2007-04-16 15:07:37.000000000 
> -0400
> +++ cobbler/collection_profiles.py 2007-06-04 21:39:01.000000000 -0400
> @@ -48,9 +48,10 @@
> raise cexceptions.CobblerException("orphan_system",v.name <http://v.name>)
> if self.find(name):
> if with_delete:
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/profile/pre/*")
> lite_sync = action_litesync.BootLiteSync(self.config)
> lite_sync.remove_single_profile(name)
> - self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/profile/*")
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/profile/post/*")
> del self.listing[name]
> return True
> raise cexceptions.CobblerException("delete_nothing")
> --- cobbler/collection_systems.py.orig 2007-04-16 15:07:47.000000000 -0400
> +++ cobbler/collection_systems.py 2007-06-04 21:41:11.000000000 -0400
> @@ -49,9 +49,10 @@
> """
> if self.find(name):
> if with_delete:
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/system/pre/*")
> lite_sync = action_litesync.BootLiteSync(self.config)
> lite_sync.remove_single_system(name)
> - self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/system/*")
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/system/post/*")
> del self.listing[name]
> return True
> raise cexceptions.CobblerException("delete_nothing")
> --- cobbler/collection_repos.py.orig 2007-04-20 18:54:24.000000000 -0400
> +++ cobbler/collection_repos.py 2007-06-04 21:40:25.000000000 -0400
> @@ -52,8 +52,9 @@
> # but is left in for consistancy in the API.
>
> if self.find(name):
> - self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/repo/*")
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/repo/pre/*")
> del self.listing[name]
> + self._run_triggers(self.listing[name], 
> "/var/lib/cobbler/triggers/delete/repo/post/*")
> return True
> raise cexceptions.CobblerException("delete_nothing")
>
> --- cobbler/collection.py.orig 2007-04-20 16:14:52.000000000 -0400
> +++ cobbler/collection.py 2007-06-04 21:35:46.000000000 -0400
> @@ -91,6 +91,7 @@
>
> # perform filesystem operations
> if with_copy:
> + self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/pre/*" % 
> self.collection_type())
> lite_sync = action_litesync.BootLiteSync(self.config)
> if isinstance(ref, item_system.System):
> lite_sync.add_single_system(ref.name <http://ref.name>)
> @@ -103,8 +104,8 @@
>
> # save the tree, so if neccessary, scripts can examine it.
> self.config.api.serialize()
> -
> - self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/*" % 
> self.collection_type())
> +
> + self._run_triggers(ref,"/var/lib/cobbler/triggers/add/%s/post/*" % 
> self.collection_type())
>
> return True
>
>
> --Adam.
> ------------------------------------------------------------------------
>
> _______________________________________________
> et-mgmt-tools mailing list
> et-mgmt-tools at redhat.com
> https://www.redhat.com/mailman/listinfo/et-mgmt-tools




More information about the et-mgmt-tools mailing list