diff options
Diffstat (limited to 'cobbler')
-rw-r--r-- | cobbler/api.py | 7 | ||||
-rw-r--r-- | cobbler/collection.py | 2 | ||||
-rw-r--r-- | cobbler/config.py | 36 | ||||
-rw-r--r-- | cobbler/module_loader.py | 11 | ||||
-rw-r--r-- | cobbler/modules/serializer_yaml.py | 6 | ||||
-rw-r--r-- | cobbler/serializer.py | 17 | ||||
-rw-r--r-- | cobbler/settings.py | 9 |
7 files changed, 36 insertions, 52 deletions
diff --git a/cobbler/api.py b/cobbler/api.py index f5d3322..1c9a445 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -23,6 +23,7 @@ import action_reposync import action_status import action_validate import sub_process +import module_loader class BootAPI: @@ -36,10 +37,10 @@ class BootAPI: self.__dict__ = self.__shared_state if not BootAPI.has_loaded: - BootAPI.has_loaded = True - self._config = config.Config(self) + BootAPI.has_loaded = True + self.modules = module_loader.load_modules() + self._config = config.Config(self) self.deserialize() - self.__settings = self._config.settings() def version(self): """ diff --git a/cobbler/collection.py b/cobbler/collection.py index 576bf6f..aa73412 100644 --- a/cobbler/collection.py +++ b/cobbler/collection.py @@ -169,7 +169,9 @@ class Collection(serializable.Serializable): # 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()) self.listing[ref.name.lower()] = ref + self.config.api.serialize() + lite_sync = action_litesync.BootLiteSync(self.config) if isinstance(ref, item_system.System): lite_sync.add_single_system(ref.name) diff --git a/cobbler/config.py b/cobbler/config.py index 91bf1fd..cb22b7b 100644 --- a/cobbler/config.py +++ b/cobbler/config.py @@ -26,8 +26,6 @@ import collection_systems as systems import collection_repos as repos import modules.serializer_yaml as serializer_yaml -import module_loader as loader - import settings import serializer @@ -55,10 +53,6 @@ class Config: Config.has_loaded = True - self.modules = loader.load_modules() - - print "DEBUG: You've got modules!: %s" % self.modules - self.api = api self._distros = distros.Distros(weakref.proxy(self)) self._repos = repos.Repos(weakref.proxy(self)) @@ -66,12 +60,15 @@ class Config: self._systems = systems.Systems(weakref.proxy(self)) self._settings = settings.Settings() # not a true collection self._graph_classes = [ + self._settings, self._distros, self._repos, self._profiles, self._systems ] - # self.file_check() + + + self.file_check() def __cmp(self,a,b): return cmp(a.name,b.name) @@ -138,24 +135,23 @@ class Config: x.clear() return True - #def file_check(self): - # """ - # Serialize any files that do not yet exist. This is useful for bringing the - # app up to a working state on first run or if files are deleted. See api.py - # """ - # for x in self._classes: - # if not os.path.exists(x.filename()): - # if not serializer.serialize(x): - # return False - # return True + def file_check(self): + """ + Serialize any files that do not yet exist. This is useful for bringing the + app up to a working state on first run or if files are deleted. See api.py + FIXME: will require some tweaks when serializer modes aren't all file based + """ + for x in self._graph_classes: + if not os.path.exists(x.filename()): + if not serializer.serialize(x): + return False + return True def serialize(self): """ Save the object hierarchy to disk, using the filenames referenced in each object. """ - if not serializer_yaml.serialize(self._settings): - return False for x in self._graph_classes: if not serializer.serialize(x): return False @@ -165,8 +161,6 @@ class Config: """ Load the object hierachy from disk, using the filenames referenced in each object. """ - if not serializer_yaml.deserialize(self._settings,topological=False): - return False for x in self._graph_classes: if not serializer.deserialize(x,topological=True): return False diff --git a/cobbler/module_loader.py b/cobbler/module_loader.py index 98ca487..5b27a01 100644 --- a/cobbler/module_loader.py +++ b/cobbler/module_loader.py @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ - import distutils.sysconfig import os import sys @@ -24,7 +23,6 @@ from rhpl.translate import _, N_, textdomain, utf8 plib = distutils.sysconfig.get_python_lib() mod_path="%s/cobbler/modules" % plib -print "DEBUG: adding to python path: %s" % mod_path sys.path.insert(0, mod_path) sys.path.insert(1, "%s/cobbler" % plib) @@ -35,7 +33,6 @@ def load_modules(module_path=mod_path, blacklist=None): mods = {} - print sys.path for fn in filenames: basename = os.path.basename(fn) @@ -50,10 +47,12 @@ def load_modules(module_path=mod_path, blacklist=None): try: blip = __import__("modules.%s" % ( modname), globals(), locals(), [modname]) if not hasattr(blip, "register"): - errmsg = _("%(module_path)s/%(modname)s is not a proper module") - print errmsg % {'module_path': module_path, 'modname':modname} + if not modname.startswith("__init__"): + errmsg = _("%(module_path)s/%(modname)s is not a proper module") + print errmsg % {'module_path': module_path, 'modname':modname} continue - mods[modname] = blip + if blip.register(): + mods[modname] = blip except ImportError, e: print e raise diff --git a/cobbler/modules/serializer_yaml.py b/cobbler/modules/serializer_yaml.py index 6aa308b..52570cf 100644 --- a/cobbler/modules/serializer_yaml.py +++ b/cobbler/modules/serializer_yaml.py @@ -27,11 +27,11 @@ import yaml # Howell-Clark version from cexceptions import * import os -def register(obj): +def register(): """ The mandatory cobbler module registration hook. """ - pass + return True def serialize(obj): """ @@ -82,7 +82,7 @@ def deserialize(obj,topological=False): datastruct = yaml.load(data).next() # first record fd.close() - if topological: + if topological and type(datastruct) == list: # in order to build the graph links from the flat list, sort by the # depth of items in the graph. If an object doesn't have a depth, sort it as # if the depth were 0. It will be assigned a proper depth at serialization diff --git a/cobbler/serializer.py b/cobbler/serializer.py index 15dcd10..bdfbb65 100644 --- a/cobbler/serializer.py +++ b/cobbler/serializer.py @@ -22,6 +22,7 @@ import yaml # Howell-Clark version from cexceptions import * import utils import api as cobbler_api +import modules.serializer_yaml as serializer_yaml MODULE_CACHE = {} @@ -40,19 +41,9 @@ def deserialize(obj,topological=False): storage_module = __get_storage_module(obj.collection_type()) return storage_module.deserialize(obj,topological) - def __get_storage_module(collection_type): - if MODULE_CACHE.has_key(collection_type): - return MODULE_CACHE[collection_type] - config = cobbler_api.BootAPI()._config - settings = config.settings() - storage_module_name = settings.storage_modules.get(collection_type, None) - if not storage_module_name: - raise CX(_("Storage module not set for objects of type %s") % collection_type) - storage_module = config.modules.get(storage_module_name, None) - if not storage_module: - raise CX(_("Storage module %s not present") % storage_module_name) - MODULE_CACHE[collection_type] = storage_module - return storage_module + # FIXME: this is always fixed currently, and should not be. + return cobbler_api.BootAPI().modules["serializer_yaml"] + diff --git a/cobbler/settings.py b/cobbler/settings.py index 1c607cc..e8b713f 100644 --- a/cobbler/settings.py +++ b/cobbler/settings.py @@ -41,12 +41,6 @@ DEFAULTS = { "pxe_just_once" : 0, "server" : "127.0.0.1", "snippetsdir" : "/var/lib/cobbler/snippets", - "storage_modules" : { - "distro" : 'serializer_yaml', - "profile" : 'serializer_yaml', - "system" : 'serializer_yaml', - "repo" : 'serializer_yaml', - }, "syslog_port" : 25150, "tftpboot" : "/tftpboot", "tftpd_bin" : "/usr/sbin/in.tftpd", @@ -68,6 +62,9 @@ class Settings(serializable.Serializable): else: return "/var/lib/cobbler/settings" + def collection_type(self): + return "settings" + def __init__(self): """ Constructor. |