summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-04-19 12:44:28 -0400
committerMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-04-19 12:44:28 -0400
commitc9da67b5170b473895ce83feba2aa328cf5ec9f8 (patch)
treed932414a83ed58ca0ad3f153a3173dc5e5eb2c84
parentd7e488931d1c28f9f0693b7eaebe26bea19f72c5 (diff)
downloadthird_party-cobbler-c9da67b5170b473895ce83feba2aa328cf5ec9f8.zip
third_party-cobbler-c9da67b5170b473895ce83feba2aa328cf5ec9f8.tar.gz
third_party-cobbler-c9da67b5170b473895ce83feba2aa328cf5ec9f8.tar.xz
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.
-rw-r--r--cobbler/api.py15
-rw-r--r--cobbler/collection.py5
-rw-r--r--cobbler/config.py16
-rw-r--r--cobbler/serializer.py1
-rw-r--r--cobbler/utils.py7
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.