From f431b4b08bf2e0b28225bfdf84f62aa2a8aa9bbb Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Mon, 7 Sep 2009 01:54:44 +0000 Subject: POSIX: Add support for unified Path entries This commit adds support for a new Path entry which unifies all the various POSIX entry types. A new plugin is included which will allow you to transform new Path entries back into their old format (for compatibility with old clients). Signed-off-by: Sol Jerome git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5414 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Tools/POSIX.py | 16 +++++++++++----- src/lib/Server/Plugin.py | 3 +++ src/lib/Server/Plugins/Compat.py | 32 ++++++++++++++++++++++++++++++++ src/lib/Server/Plugins/__init__.py | 10 +++++----- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/lib/Server/Plugins/Compat.py (limited to 'src') diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py index bfbe79066..bc9626e88 100644 --- a/src/lib/Client/Tools/POSIX.py +++ b/src/lib/Client/Tools/POSIX.py @@ -79,11 +79,11 @@ def isString(strng): class POSIX(Bcfg2.Client.Tools.Tool): '''POSIX File support code''' name = 'POSIX' - __handles__ = [('ConfigFile', None), ('Directory', None), - ('Path', 'ConfigFile'), ('Path', 'Device'), - ('Path', 'Directory'), ('Path', 'Perms'), - ('Path', 'SymLink'), ('Permissions', None), - ('SymLink', None)] + __handles__ = [('ConfigFile', None), ('ConfigFile', 'Compat'), + ('Directory', None), ('Path', 'ConfigFile'), + ('Path', 'Device'), ('Path', 'Directory'), + ('Path', 'Perms'), ('Path', 'SymLink'), + ('Permissions', None), ('SymLink', None)] __req__ = {'ConfigFile': ['name', 'owner', 'group', 'perms'], 'Directory': ['name', 'owner', 'group', 'perms'], 'Path': ['name', 'type'], @@ -149,6 +149,12 @@ class POSIX(Bcfg2.Client.Tools.Tool): except OSError: return False + def VerifyDevice(self, entry, _): + return False + + def InstallDevice(self, entry): + return False + def VerifyDirectory(self, entry, modlist): '''Verify Directory Entry''' while len(entry.get('perms', '')) < 4: diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 5289dad56..6c6d5aab3 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -708,6 +708,7 @@ class GroupSpool(Plugin, Generator): if self.data[-1] == '/': self.data = self.data[:-1] self.Entries['ConfigFile'] = {} + self.Entries['Path'] = {} self.entries = {} self.handles = {} self.AddDirectoryMonitor('') @@ -735,6 +736,7 @@ class GroupSpool(Plugin, Generator): self.es_child_cls, self.encoding) self.Entries['ConfigFile'][ident] = self.entries[ident].bind_entry + self.Entries['Path'][ident] = self.entries[ident].bind_entry if not posixpath.isdir(epath): # do not pass through directory events self.entries[ident].handle_event(event) @@ -746,6 +748,7 @@ class GroupSpool(Plugin, Generator): # a directory was deleted del self.entries[fbase] del self.Entries['ConfigFile'][fbase] + del self.Entries['Path'][fbase] else: self.entries[ident].handle_event(event) diff --git a/src/lib/Server/Plugins/Compat.py b/src/lib/Server/Plugins/Compat.py new file mode 100644 index 000000000..c68e7181c --- /dev/null +++ b/src/lib/Server/Plugins/Compat.py @@ -0,0 +1,32 @@ +''' + This plugin provides a compatibility layer which turns new-style + POSIX entries into old-style entries. +''' +__revision__ = '$Revision:$' + +import Bcfg2.Server.Plugin + +COMPAT_DICT = {'configfile': 'ConfigFile', + 'device': 'Device', + 'directory': 'Directory', + 'permissions': 'Permissions', + 'symlink': 'SymLink'} + +class Compat(Bcfg2.Server.Plugin.Plugin, + Bcfg2.Server.Plugin.GoalValidator): + name = 'Compat' + __version__ = '$Id:$' + __author__ = 'bcfg-dev@mcs.anl.gov' + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.GoalValidator.__init__(self) + + def validate_goals(self, metadata, goals): + for goal in goals: + for entry in goal.getchildren(): + if entry.tag == 'Path': + oldentry = entry + entry.tag = COMPAT_DICT['%s' % entry.get('type')] + entry.set('type', 'Compat') + goal.replace(oldentry, entry) diff --git a/src/lib/Server/Plugins/__init__.py b/src/lib/Server/Plugins/__init__.py index 0d54fc873..88f84e536 100644 --- a/src/lib/Server/Plugins/__init__.py +++ b/src/lib/Server/Plugins/__init__.py @@ -1,8 +1,8 @@ '''imports for Bcfg2.Server.Plugins''' __revision__ = '$Revision$' -__all__ = ['Account', 'Base', 'Bundler', 'Cfg', 'Decisions', 'GBundler', 'Git', - 'Hostbase', 'Metadata', 'NagiosGen', 'Packages', 'Properties', - 'Probes', 'Pkgmgr', 'Rules', 'SSHbase', 'Snapshots' 'Statistics', - 'Svcmgr', 'Svn', 'TCheetah', 'Trigger', 'SGenshi', 'TGenshi', - 'GroupPatterns', 'Ohai'] +__all__ = ['Account', 'Base', 'Bundler', 'Cfg', 'Compat', 'Decisions', + 'GBundler', 'Git', 'Hostbase', 'Metadata', 'NagiosGen', 'Packages', + 'Properties', 'Probes', 'Pkgmgr', 'Rules', 'SSHbase', 'Snapshots', + 'Statistics', 'Svcmgr', 'Svn', 'TCheetah', 'Trigger', 'SGenshi', + 'TGenshi', 'GroupPatterns', 'Ohai'] -- cgit v1.2.3-1-g7c22