From c9da67b5170b473895ce83feba2aa328cf5ec9f8 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 19 Apr 2007 12:44:28 -0400 Subject: Various improvements to make the API more usable and cobbler a bit more efficient. Make both the Config and BootAPI objects Borgs, to prevent duplicate configuration records. Also do not implicitly serialize configuration objects unless the with_copy parameter is used. --- cobbler/api.py | 15 +++++++++++---- cobbler/collection.py | 5 +++-- cobbler/config.py | 16 +++++++++++++++- cobbler/serializer.py | 1 + cobbler/utils.py | 7 +++++++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/cobbler/api.py b/cobbler/api.py index cda4e86..212305a 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -26,14 +26,21 @@ import cexceptions class BootAPI: + __shared_state = {} + has_loaded = False + def __init__(self): """ Constructor """ - self._config = config.Config(self) - self.deserialize() - self.__settings = self._config.settings() - self.sync_flag = self.__settings.minimize_syncs + + self.__dict__ = self.__shared_state + if not BootAPI.has_loaded: + BootAPI.has_loaded = True + self._config = config.Config(self) + self.deserialize() + self.__settings = self._config.settings() + self.sync_flag = self.__settings.minimize_syncs def clear(self): """ diff --git a/cobbler/collection.py b/cobbler/collection.py index 196de7f..422ecc6 100644 --- a/cobbler/collection.py +++ b/cobbler/collection.py @@ -89,8 +89,6 @@ class Collection(serializable.Serializable): raise cexceptions.CobblerException("bad_param") self.listing[ref.name] = ref - # save the tree, so if neccessary, scripts can examine it. - self.config.api.serialize() # perform filesystem operations if with_copy: @@ -103,6 +101,9 @@ class Collection(serializable.Serializable): lite_sync.add_single_distro(ref.name) else: print "AIEEE ??? %s " % type(ref) + + # 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()) diff --git a/cobbler/config.py b/cobbler/config.py index 3444ded..3a9bd79 100644 --- a/cobbler/config.py +++ b/cobbler/config.py @@ -30,11 +30,25 @@ import serializer class Config: + has_loaded = False + __shared_state = {} + + def __init__(self,api): + """ Constructor. Manages a definitive copy of all data collections with weakrefs - poiting back into the class so they can understand each other's contents + pointing back into the class so they can understand each other's contents """ + self.__dict__ == Config.__shared_state + if not Config.has_loaded: + self.__load(api) + + + def __load(self,api): + + Config.has_loaded = True + self.api = api self._distros = distros.Distros(weakref.proxy(self)) self._profiles = profiles.Profiles(weakref.proxy(self)) diff --git a/cobbler/serializer.py b/cobbler/serializer.py index 4cf85f8..9a4925c 100644 --- a/cobbler/serializer.py +++ b/cobbler/serializer.py @@ -25,6 +25,7 @@ def serialize(obj): Will create intermediate paths if it can. Returns True on Success, False on permission errors. """ + # FIXME: DEBUG filename = obj.filename() try: fd = open(filename,"w+") diff --git a/cobbler/utils.py b/cobbler/utils.py index 40a558f..e7bd3fa 100644 --- a/cobbler/utils.py +++ b/cobbler/utils.py @@ -18,10 +18,17 @@ import socket import glob import sub_process import shutil +import string +import traceback _re_kernel = re.compile(r'vmlinuz(.*)') _re_initrd = re.compile(r'initrd(.*).img') +def trace_me(): + x = traceback.extract_stack() + bar = string.join(traceback.format_list(x)) + return bar + def get_host_ip(ip): """ Return the IP encoding needed for the TFTP boot tree. -- cgit